1
0
mirror of https://github.com/Klagarge/PokeHES.git synced 2025-03-14 06:44:33 +00:00
PokeHES/src/Text/TextEnemy.java

107 lines
2.6 KiB
Java
Raw Normal View History

package Text;
import java.util.Vector;
2022-06-12 12:10:57 +02:00
import java.util.Random;
public class TextEnemy {
public FightData fightData;
public SpeechData speechData;
2022-06-10 19:33:24 +02:00
public Vector<Line> lines = new Vector<Line>();
2022-06-12 12:10:57 +02:00
public int[] orderAnswer;
2022-06-10 19:33:24 +02:00
public static void main(String[] args) {
2022-06-12 12:10:57 +02:00
2022-06-10 19:33:24 +02:00
TextEnemy t = new TextEnemy("enemi");
2022-06-12 12:10:57 +02:00
2022-06-10 19:33:24 +02:00
t.generateText();
2022-06-12 12:10:57 +02:00
2022-06-10 19:33:24 +02:00
for(Line l : t.lines) {
System.out.println(l.line);
}
2022-06-12 12:10:57 +02:00
2022-06-10 19:33:24 +02:00
}
public TextEnemy(String name){
//generate the vector of fight
fightData = new FightData(name);
fightData.readFile();
//generate the vector of Speechs
speechData = new SpeechData(name);
speechData.readFile();
}
2022-06-12 14:26:02 +02:00
int[] randomGenerate(int max_val){
int max = 8-1;
Random r = new Random();
int nbre = 4;
2022-06-12 12:10:57 +02:00
2022-06-12 14:26:02 +02:00
int[] t = new int[nbre];
int x;
2022-06-12 12:10:57 +02:00
int i=0;
2022-06-12 14:26:02 +02:00
boolean same = false;
// initialize array at -1
for(int j=0; j<nbre ; j++){
t[j] = -1;
}
2022-06-12 12:10:57 +02:00
2022-06-12 14:26:02 +02:00
//assign 4 different random value between 0 and max
while(i< nbre){
x = r.nextInt(max);
2022-06-12 12:10:57 +02:00
2022-06-12 14:26:02 +02:00
//test if the value is valid
2022-06-12 12:10:57 +02:00
for(int j : t){
2022-06-12 14:26:02 +02:00
if(x==j){
same = true;
break;
2022-06-12 12:10:57 +02:00
}
}
2022-06-12 14:26:02 +02:00
//do again the loop
if(same){
same = false;
}
else{
t[i] = x;
i++;
}
2022-06-12 12:10:57 +02:00
}
return t;
}
public void generateText(){
2022-06-10 19:33:24 +02:00
int i =1;
2022-06-12 12:10:57 +02:00
//introduction line
2022-06-10 19:33:24 +02:00
lines.add(new Line(speechData.getSpeechs(0), false));
2022-06-12 12:10:57 +02:00
orderAnswer = randomGenerate(fightData.nbre_line);
2022-06-10 19:33:24 +02:00
for(int j=0; j<4;j++){
2022-06-12 12:10:57 +02:00
//generate the order of the answer
2022-06-09 06:58:49 +02:00
//attack and answer (number on vector : 1-4)
2022-06-10 19:33:24 +02:00
lines.add(new Line(
2022-06-12 12:10:57 +02:00
speechData.getSpeechs(i++) + fightData.getAttack(orderAnswer[j]).attack + " ? ("+fightData.getAttack(orderAnswer[j]).xp+ ") " + "\n" +
fightData.getAttack(orderAnswer[j]).answer1 + "\n" +
fightData.getAttack(orderAnswer[j]).answer2 + "\n" +
fightData.getAttack(orderAnswer[j]).answer3 + "\n" +
fightData.getAttack(orderAnswer[j]).answer4, true));
2022-06-09 06:58:49 +02:00
// TODO mélanger les attaques aléatoirement
}
//finish (win and death)
2022-06-10 19:33:24 +02:00
lines.add(new Line(speechData.getSpeechs(5), false));
lines.add(new Line(speechData.getSpeechs(6), false));
}
}
2022-06-09 06:58:49 +02:00