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-13 20:53:09 +02:00
|
|
|
private Vector<int[]> currentData;
|
|
|
|
|
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 20:53:09 +02:00
|
|
|
//save random data (attack and ansver) : attack, answer 1, answer 2 answer 3, answer 4
|
|
|
|
currentData = new Vector<int[]>();
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
|
|
|
|
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-13 20:53:09 +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-13 20:53:09 +02:00
|
|
|
int[] currentRandom = new int[5];
|
|
|
|
currentRandom[0] = orderAttack[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);
|
2022-06-13 20:53:09 +02:00
|
|
|
System.out.println("\n attaque " + j + " : " + Arrays.toString(orderAnswer) + "\n");
|
|
|
|
|
|
|
|
//save the order of answer and attack
|
|
|
|
for(int k=1;k<5;k++){
|
|
|
|
currentRandom[k] = orderAnswer[k-1];
|
|
|
|
}
|
|
|
|
|
|
|
|
//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" +
|
2022-06-13 20:53:09 +02:00
|
|
|
"1. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]) + "\n" +
|
|
|
|
"2. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]) + "\n" +
|
|
|
|
"3. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]) + "\n" +
|
|
|
|
"4. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]), true));
|
|
|
|
|
|
|
|
|
|
|
|
currentData.add(currentRandom);
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
for(int[] a : currentData){
|
|
|
|
System.out.println(Arrays.toString(a));
|
|
|
|
}
|
|
|
|
|
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-13 20:53:09 +02:00
|
|
|
public Vector<int[]> getCurrentData() {
|
|
|
|
return currentData;
|
|
|
|
}
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
|
|
|
|
}
|
2022-06-09 06:58:49 +02:00
|
|
|
|