2022-06-08 23:30:15 +02:00
|
|
|
package Text;
|
|
|
|
|
|
|
|
import java.util.Vector;
|
2022-06-14 01:14:54 +02:00
|
|
|
|
|
|
|
import Entity.Enemy;
|
2022-06-16 12:23:33 +02:00
|
|
|
import Entity.Character.Direction;
|
2022-06-14 01:14:54 +02:00
|
|
|
|
2022-06-16 18:59:45 +02:00
|
|
|
import java.text.Normalizer;
|
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 {
|
2022-06-16 12:23:33 +02:00
|
|
|
private static final int CUT = 60;
|
2022-06-08 23:30:15 +02:00
|
|
|
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-16 12:23:33 +02:00
|
|
|
TextEnemy t = new TextEnemy(new Enemy("Mudry", 10, 15, "lumberjack_sheet32", "desert", 25, "informatique", Direction.NULL));
|
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-08 23:30:15 +02:00
|
|
|
|
2022-06-14 01:14:54 +02:00
|
|
|
public TextEnemy(Enemy e){
|
2022-06-08 23:30:15 +02:00
|
|
|
//generate the vector of fight
|
2022-06-14 01:14:54 +02:00
|
|
|
fightData = new FightData(e.getBranch());
|
2022-06-08 23:30:15 +02:00
|
|
|
fightData.readFile();
|
|
|
|
|
|
|
|
//generate the vector of Speechs
|
2022-06-14 01:14:54 +02:00
|
|
|
speechData = new SpeechData(e.getName());
|
2022-06-08 23:30:15 +02:00
|
|
|
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-16 12:23:33 +02:00
|
|
|
String introduction = formatLine(speechData.getSpeechs(0), CUT);
|
|
|
|
lines.add(new Line(introduction, 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
|
|
|
|
|
|
|
//save the order of answer and attack
|
|
|
|
for(int k=1;k<5;k++){
|
|
|
|
currentRandom[k] = orderAnswer[k-1];
|
|
|
|
}
|
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
//Format the line
|
|
|
|
String attack = formatLine(speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ? ("+fightData.getAttack(orderAttack[j]).getXp()+ ") ", CUT);
|
|
|
|
String answer1 = formatLine("1. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]) , CUT);
|
|
|
|
String answer2 = formatLine("2. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]) , CUT);
|
|
|
|
String answer3 = formatLine("3. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]) , CUT);
|
|
|
|
String answer4 = formatLine("4. " + fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]) , CUT);
|
2022-06-15 22:29:34 +02:00
|
|
|
|
2022-06-13 20:53:09 +02:00
|
|
|
//attack and answer (number on vector : 1-4)
|
2022-06-16 12:23:33 +02:00
|
|
|
lines.add(new Line(attack + "\n" +answer1 + "\n" + answer2 + "\n" + answer3 + "\n" + answer4, true));
|
2022-06-13 20:53:09 +02:00
|
|
|
|
|
|
|
|
|
|
|
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-16 12:23:33 +02:00
|
|
|
String dead = formatLine(speechData.getSpeechs(5),CUT);
|
|
|
|
String alive = formatLine(speechData.getSpeechs(6), CUT);
|
|
|
|
lines.add(new Line(dead, false));
|
|
|
|
lines.add(new Line(alive, 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-15 22:29:34 +02:00
|
|
|
public String formatLine(String line, int cut){
|
|
|
|
|
|
|
|
String cutLine = "";
|
|
|
|
String newLine = "";
|
|
|
|
|
|
|
|
int startC = 0;
|
|
|
|
int stoppC = cut;
|
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
if(cut>line.length()-1){
|
|
|
|
newLine =line;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
|
|
|
|
char[] c = new char[line.length()];
|
2022-06-15 22:29:34 +02:00
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
for(int i=0; i<c.length;i++){
|
|
|
|
c[i] = line.charAt(i);
|
|
|
|
}
|
2022-06-15 22:29:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
while(true){
|
|
|
|
for(int i =stoppC; i>=startC; i--){
|
|
|
|
if(c[i] == ' '){
|
|
|
|
stoppC = i;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(stoppC == c.length-1){
|
|
|
|
break;
|
|
|
|
}
|
2022-06-15 22:29:34 +02:00
|
|
|
}
|
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
//découper le mot
|
|
|
|
for(int i=startC;i<=stoppC;i++){
|
|
|
|
cutLine += c[i];
|
|
|
|
}
|
2022-06-15 22:29:34 +02:00
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
newLine += cutLine+"\n";
|
|
|
|
cutLine = "";
|
2022-06-15 22:29:34 +02:00
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
startC = stoppC + 1;
|
2022-06-16 11:57:05 +02:00
|
|
|
|
2022-06-16 12:23:33 +02:00
|
|
|
|
|
|
|
if(c.length-1-stoppC <=0){
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if(c.length-1-stoppC <= cut){
|
|
|
|
stoppC = c.length-1;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
stoppC += cut;
|
|
|
|
}
|
2022-06-15 22:29:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return newLine;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-06-08 23:30:15 +02:00
|
|
|
}
|
2022-06-09 06:58:49 +02:00
|
|
|
|