mirror of
				https://github.com/Klagarge/PokeHES.git
				synced 2025-10-31 03:39:16 +00:00 
			
		
		
		
	| @@ -6,6 +6,8 @@ public class Attack { | ||||
|     String answer2; | ||||
|     String answer3; | ||||
|     String answer4; | ||||
|     String[] s; | ||||
|  | ||||
|     float xp; | ||||
|  | ||||
|     Attack(String attack, String answer1,String answer2,String answer3, String answer4, float xp){ | ||||
| @@ -15,9 +17,19 @@ public class Attack { | ||||
|         this.answer3 = answer3; | ||||
|         this.answer4 = answer4; | ||||
|         this.xp = xp; | ||||
|  | ||||
|         s = new String[4]; | ||||
|         s[0] = answer1; | ||||
|         s[1] = answer2; | ||||
|         s[2] = answer3; | ||||
|         s[3] = answer4; | ||||
|     } | ||||
|  | ||||
|     public String toString(){ | ||||
|         return attack+ "  " + answer1+ "  " + answer2+ "  " + answer3+ "  " + answer4+ "  " + xp; | ||||
|     } | ||||
|  | ||||
|     public String getAnswer(int i){ | ||||
|         return s[i]; | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -27,8 +27,6 @@ public class FightData { | ||||
|             FileReader f = new FileReader(file); | ||||
|             BufferedReader bf = new BufferedReader(f);  | ||||
|  | ||||
|  | ||||
|  | ||||
|             //add the line in the vector attacks of attack | ||||
|             line = bf.readLine();  | ||||
|             while(line != null){ | ||||
| @@ -45,6 +43,7 @@ public class FightData { | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         System.out.println(attacks.size()); | ||||
|     } | ||||
|  | ||||
|     //return the vector with all attaks of one enemi | ||||
|   | ||||
| @@ -1,6 +1,7 @@ | ||||
| package Text; | ||||
|  | ||||
| import java.util.Vector; | ||||
| import java.util.Arrays; | ||||
| import java.util.Random; | ||||
|  | ||||
| public class TextEnemy { | ||||
| @@ -9,7 +10,8 @@ public class TextEnemy { | ||||
|  | ||||
|     public Vector<Line> lines = new Vector<Line>(); | ||||
|  | ||||
|     public int[] orderAnswer; | ||||
|     private int[] orderAttack; | ||||
|     private int[] orderAnswer; | ||||
|  | ||||
|     public static void main(String[] args) { | ||||
|          | ||||
| @@ -35,45 +37,37 @@ public class TextEnemy { | ||||
|  | ||||
|     } | ||||
|  | ||||
|     int[] randomGenerate(int max_val){ | ||||
|         int max = 8-1; | ||||
|         Random r = new Random(); | ||||
|  | ||||
|         int nbre = 4; | ||||
|  | ||||
|         int[] t = new int[nbre]; | ||||
|         int x; | ||||
|         int i=0; | ||||
|         boolean same = false; | ||||
|  | ||||
|         // initialize array at -1 | ||||
|         for(int j=0; j<nbre ; j++){ | ||||
|             t[j] = -1; | ||||
|     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++; | ||||
|         } | ||||
|  | ||||
|         //assign 4 different random value between 0 and max | ||||
|         while(i< nbre){ | ||||
|             x = r.nextInt(max); | ||||
|         //create a new array with the numbers I want | ||||
|         int[] b = new int[nbreRandom]; | ||||
|  | ||||
|             //test if the value is valid | ||||
|             for(int j : t){ | ||||
|                 if(x==j){ | ||||
|                     same = true; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|         // Creating object for Random class | ||||
|         Random rd = new Random(); | ||||
|           | ||||
|             //do again the loop | ||||
|             if(same){ | ||||
|                 same = false; | ||||
|             } | ||||
|             else{ | ||||
|                 t[i] = x; | ||||
|                 i++; | ||||
|             } | ||||
|         // 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; | ||||
|         } | ||||
|          | ||||
|         return t;         | ||||
|         //add the numbers I want | ||||
|         for(int i=0;i<nbreRandom;i++){ | ||||
|             b[i] = a[i]; | ||||
|         } | ||||
|         return b; | ||||
|     } | ||||
|  | ||||
|  | ||||
| @@ -82,19 +76,19 @@ public class TextEnemy { | ||||
|          | ||||
|         //introduction line | ||||
|         lines.add(new Line(speechData.getSpeechs(0), false)); | ||||
|         orderAnswer = randomGenerate(fightData.nbre_line); | ||||
|         orderAttack = randomGenerate(0, fightData.nbre_line-1, 4); | ||||
|         for(int j=0; j<4;j++){ | ||||
|  | ||||
|             //generate the order of the answer | ||||
|              | ||||
|             orderAnswer = randomGenerate(0, 3, 4); | ||||
|             System.out.println("\n" + Arrays.toString(orderAnswer) + "\n"); | ||||
|         //attack and answer (number on vector : 1-4)  | ||||
|             lines.add(new Line( | ||||
|                 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)); | ||||
|             // TODO mélanger les attaques aléatoirement | ||||
|                 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)); | ||||
|         } | ||||
|         //finish (win and death) | ||||
|         lines.add(new Line(speechData.getSpeechs(5), false)); | ||||
|   | ||||
| @@ -1,54 +1,30 @@ | ||||
|  | ||||
| import Text.*; | ||||
| import java.util.Arrays; | ||||
| import java.util.Collections; | ||||
| import java.util.List; | ||||
| import java.util.ListIterator; | ||||
| import java.util.Random; | ||||
| import java.util.RandomAccess; | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| class testYann{ | ||||
|     public static void main(String[] args) { | ||||
|         int max = 8-1; | ||||
|         Random r = new Random(); | ||||
|  | ||||
|         int nbre = 4; | ||||
|  | ||||
|         int[] a = new int[nbre]; | ||||
|         int x; | ||||
|         int i=0; | ||||
|         boolean same = false; | ||||
|  | ||||
|         for(int j=0; j<nbre ; j++){ | ||||
|             a[j] = -1; | ||||
|         } | ||||
|  | ||||
|         while(i< nbre){ | ||||
|             x = r.nextInt(max); | ||||
|             System.out.println(x); | ||||
|             for(int j : a){ | ||||
|                 if(x==j){ | ||||
|                     same = true; | ||||
|                     break; | ||||
|                 } | ||||
|             } | ||||
|             if(same){ | ||||
|                 same = false; | ||||
|             } | ||||
|             else{ | ||||
|                 a[i] = x; | ||||
|                 i++; | ||||
|             } | ||||
|         } | ||||
|         System.out.println("\n"); | ||||
|  | ||||
|  | ||||
|         for(int j : a){ | ||||
|             System.out.println(j); | ||||
|         } | ||||
|          | ||||
|  | ||||
|  | ||||
|         FightData t = new FightData("enemi"); | ||||
|         t.readFile(); | ||||
|  | ||||
|         System.out.println(t.getAttack(1).getAnswer(0).toString()); | ||||
|         | ||||
|     } | ||||
|  | ||||
|     | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
		Reference in New Issue
	
	Block a user