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 answer2; | ||||||
|     String answer3; |     String answer3; | ||||||
|     String answer4; |     String answer4; | ||||||
|  |     String[] s; | ||||||
|  |  | ||||||
|     float xp; |     float xp; | ||||||
|  |  | ||||||
|     Attack(String attack, String answer1,String answer2,String answer3, String answer4, 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.answer3 = answer3; | ||||||
|         this.answer4 = answer4; |         this.answer4 = answer4; | ||||||
|         this.xp = xp; |         this.xp = xp; | ||||||
|  |  | ||||||
|  |         s = new String[4]; | ||||||
|  |         s[0] = answer1; | ||||||
|  |         s[1] = answer2; | ||||||
|  |         s[2] = answer3; | ||||||
|  |         s[3] = answer4; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public String toString(){ |     public String toString(){ | ||||||
|         return attack+ "  " + answer1+ "  " + answer2+ "  " + answer3+ "  " + answer4+ "  " + xp; |         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); |             FileReader f = new FileReader(file); | ||||||
|             BufferedReader bf = new BufferedReader(f);  |             BufferedReader bf = new BufferedReader(f);  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|             //add the line in the vector attacks of attack |             //add the line in the vector attacks of attack | ||||||
|             line = bf.readLine();  |             line = bf.readLine();  | ||||||
|             while(line != null){ |             while(line != null){ | ||||||
| @@ -45,6 +43,7 @@ public class FightData { | |||||||
|         } catch (Exception e) { |         } catch (Exception e) { | ||||||
|             e.printStackTrace(); |             e.printStackTrace(); | ||||||
|         } |         } | ||||||
|  |         System.out.println(attacks.size()); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     //return the vector with all attaks of one enemi |     //return the vector with all attaks of one enemi | ||||||
|   | |||||||
| @@ -1,6 +1,7 @@ | |||||||
| package Text; | package Text; | ||||||
|  |  | ||||||
| import java.util.Vector; | import java.util.Vector; | ||||||
|  | import java.util.Arrays; | ||||||
| import java.util.Random; | import java.util.Random; | ||||||
|  |  | ||||||
| public class TextEnemy { | public class TextEnemy { | ||||||
| @@ -9,7 +10,8 @@ public class TextEnemy { | |||||||
|  |  | ||||||
|     public Vector<Line> lines = new Vector<Line>(); |     public Vector<Line> lines = new Vector<Line>(); | ||||||
|  |  | ||||||
|     public int[] orderAnswer; |     private int[] orderAttack; | ||||||
|  |     private int[] orderAnswer; | ||||||
|  |  | ||||||
|     public static void main(String[] args) { |     public static void main(String[] args) { | ||||||
|          |          | ||||||
| @@ -35,45 +37,37 @@ public class TextEnemy { | |||||||
|  |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     int[] randomGenerate(int max_val){ |     public static int[] randomGenerate( int min, int max, int nbreRandom){ | ||||||
|         int max = 8-1; |         //create an array with all the number I need | ||||||
|         Random r = new Random(); |         int[] a = new int[max-min+1]; | ||||||
|  |         int k = min; | ||||||
|         int nbre = 4; |         for(int i=0;k<=max;i++){ | ||||||
|  |             a[i] = k; | ||||||
|         int[] t = new int[nbre]; |             k++; | ||||||
|         int x; |  | ||||||
|         int i=0; |  | ||||||
|         boolean same = false; |  | ||||||
|  |  | ||||||
|         // initialize array at -1 |  | ||||||
|         for(int j=0; j<nbre ; j++){ |  | ||||||
|             t[j] = -1; |  | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         //assign 4 different random value between 0 and max |         //create a new array with the numbers I want | ||||||
|         while(i< nbre){ |         int[] b = new int[nbreRandom]; | ||||||
|             x = r.nextInt(max); |  | ||||||
|  |  | ||||||
|             //test if the value is valid |         // Creating object for Random class | ||||||
|             for(int j : t){ |         Random rd = new Random(); | ||||||
|                 if(x==j){ |  | ||||||
|                     same = true; |  | ||||||
|                     break; |  | ||||||
|                 } |  | ||||||
|             } |  | ||||||
|           |           | ||||||
|             //do again the loop |         // Starting from the last element and swapping one by one. | ||||||
|             if(same){ |         for (int i = a.length-1; i > 0; i--) { | ||||||
|                 same = false; |               | ||||||
|             } |             // Pick a random index from 0 to i | ||||||
|             else{ |             int j = rd.nextInt(i+1); | ||||||
|                 t[i] = x; |               | ||||||
|                 i++; |             // 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 | ||||||
|         return t;         |         for(int i=0;i<nbreRandom;i++){ | ||||||
|  |             b[i] = a[i]; | ||||||
|  |         } | ||||||
|  |         return b; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |  | ||||||
| @@ -82,19 +76,19 @@ public class TextEnemy { | |||||||
|          |          | ||||||
|         //introduction line |         //introduction line | ||||||
|         lines.add(new Line(speechData.getSpeechs(0), false)); |         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++){ |         for(int j=0; j<4;j++){ | ||||||
|  |  | ||||||
|             //generate the order of the answer |             //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)  |         //attack and answer (number on vector : 1-4)  | ||||||
|             lines.add(new Line( |             lines.add(new Line( | ||||||
|                 speechData.getSpeechs(i++) + fightData.getAttack(orderAnswer[j]).attack + " ?  ("+fightData.getAttack(orderAnswer[j]).xp+ ") " + "\n" + |                 speechData.getSpeechs(i++) + fightData.getAttack(orderAttack[j]).attack + " ?  ("+fightData.getAttack(orderAttack[j]).xp+ ") " + "\n" + | ||||||
|                 fightData.getAttack(orderAnswer[j]).answer1 + "\n" + |                 fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[0]) + "\n" + | ||||||
|                 fightData.getAttack(orderAnswer[j]).answer2 + "\n" +  |                 fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[1]) + "\n" +  | ||||||
|                 fightData.getAttack(orderAnswer[j]).answer3 + "\n" +  |                 fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[2]) + "\n" +  | ||||||
|                 fightData.getAttack(orderAnswer[j]).answer4, true)); |                 fightData.getAttack(orderAttack[j]).getAnswer(orderAnswer[3]), true)); | ||||||
|             // TODO mélanger les attaques aléatoirement |  | ||||||
|         } |         } | ||||||
|         //finish (win and death) |         //finish (win and death) | ||||||
|         lines.add(new Line(speechData.getSpeechs(5), false)); |         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.Random; | ||||||
|  | import java.util.RandomAccess; | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
|  |  | ||||||
| class testYann{ | class testYann{ | ||||||
|     public static void main(String[] args) { |     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