package Text; import Entity.Enemy; import java.util.Vector; import java.util.Arrays; import java.util.Random; public class TextEnemy { private static final int CUT = 55; public FightData fightData; public SpeechData speechData; public Vector lines = new Vector(); private int[] orderAttack; private int[] orderAnswer; private Vector currentData; public TextEnemy(Enemy e){ //generate the vector of fight fightData = new FightData(e.getBranch()); fightData.readFile(); //generate the vector of Speechs speechData = new SpeechData(e.getName()); speechData.readFile(); //save random data (attack and answer) : attack, answer 1, answer 2 answer 3, answer 4 currentData = new Vector(); } public static int[] randomGenerate( int min, int max, int nbrRandom){ //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++; } //create a new array with the numbers I want int[] b = new int[nbrRandom]; // 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; } //add the numbers I want for(int i=0;i getCurrentData() { return currentData; } //format a String with a specific length of char public String formatLine(String line, int cut){ String cutLine = ""; String newLine = ""; int startC = 0; int stopC = cut; //check if the line is shorter than the character limit if(cut>line.length()-1){ newLine =line; } else{ //create a array with the line char[] c = new char[line.length()]; for(int i=0; i=startC; i--){ if(c[i] == ' '){ stopC = i; break; } else if(stopC == c.length-1){ break; } } //découper le mot for(int i=startC;i<=stopC;i++){ cutLine += c[i]; } //rebuild the line with the line breaks newLine += cutLine+"\n"; cutLine = ""; startC = stopC + 1; if(c.length-1-stopC <=0){ break; } else if(c.length-1-stopC <= cut){ stopC = c.length-1; } else{ stopC += cut; } } } return newLine; } }