2022-06-08 23:30:15 +02:00
|
|
|
package Text;
|
|
|
|
|
|
|
|
import java.util.Vector;
|
2022-06-13 11:41:24 +02:00
|
|
|
import java.util.Arrays;
|
2022-06-12 12:10:57 +02:00
|
|
|
import java.util.Random;
|
2022-06-08 23:30:15 +02:00
|
|
|
|
|
|
|
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-13 11:41:24 +02:00
|
|
|
private int[] orderAttack;
|
|
|
|
private int[] orderAnswer;
|
2022-06-12 12:10:57 +02:00
|
|
|
|
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
|
|
|
|
|
|
|
}
|
2022-06-08 23:30:15 +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-13 11:41:24 +02:00
|
|
|
public static int[] randomGenerate( int min, int max, int nbreRandom){
|
|
|
|
//create an array with all the number I need
|
|
|
|
int[] a = new int[max-min+1];
|
|
|
|
int k = min;
|
|
|
|
for(int i=0;k<=max;i++){
|
|
|
|
a[i] = k;
|
|
|
|
k++;
|
2022-06-12 14:26:02 +02:00
|
|
|
}
|
2022-06-12 12:10:57 +02:00
|
|
|
|
2022-06-13 11:41:24 +02:00
|
|
|
//create a new array with the numbers I want
|
|
|
|
int[] b = new int[nbreRandom];
|
|
|
|
|
|
|
|
// Creating object for Random class
|
|
|
|
Random rd = new Random();
|
|
|
|
|
|
|
|
// Starting from the last element and swapping one by one.
|
|
|
|
for (int i = a.length-1; i > 0; i--) {
|
|
|
|
|
|
|
|
// Pick a random index from 0 to i
|
|
|
|
int j = rd.nextInt(i+1);
|
|
|
|
|
|
|
|
// Swap array[i] with the element at random index
|
|
|
|
int temp = a[i];
|
|
|
|
a[i] = a[j];
|
|
|
|
a[j] = temp;
|
2022-06-12 12:10:57 +02:00
|
|
|
}
|
2022-06-13 11:41:24 +02:00
|
|
|
//add the numbers I want
|
|
|
|
for(int i=0;i<nbreRandom;i++){
|
|
|
|
b[i] = a[i];
|
|
|
|
}
|
|
|
|
return b;
|
2022-06-12 12:10:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
public void generateText(){
|
2022-06-10 19:33:24 +02:00
|
|
|
int i =1;
|
2022-06-12 12:10:57 +02:00
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
//introduction line
|
2022-06-10 19:33:24 +02:00
|
|
|
lines.add(new Line(speechData.getSpeechs(0), false));
|
2022-06-13 11:41:24 +02:00
|
|
|
orderAttack = randomGenerate(0, fightData.nbre_line-1, 4);
|
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-13 11:41:24 +02:00
|
|
|
orderAnswer = randomGenerate(0, 3, 4);
|
|
|
|
System.out.println("\n" + Arrays.toString(orderAnswer) + "\n");
|
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-13 11:41:24 +02:00
|
|
|
speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ? ("+fightData.getAttack(orderAttack[j]).xp+ ") " + "\n" +
|
|
|
|
fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]) + "\n" +
|
|
|
|
fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]) + "\n" +
|
|
|
|
fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]) + "\n" +
|
|
|
|
fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]), true));
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
//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-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
2022-06-09 06:58:49 +02:00
|
|
|
|