mirror of
				https://github.com/Klagarge/PokeHES.git
				synced 2025-10-31 03:39:16 +00:00 
			
		
		
		
	| @@ -14,10 +14,10 @@ public class Player extends Character{ | ||||
|  | ||||
|     private int xp; | ||||
| 	public Enemy lastEnemy = null; | ||||
| 	public boolean onEnemy = false; | ||||
| 	public boolean frontOfEnemy = false; | ||||
|  | ||||
|     public Player(int x, int y, String map) { | ||||
|         super("Player", x, y, "character", map); | ||||
|         super("Player", x, y, "Character", map); | ||||
|     } | ||||
|  | ||||
|     public void addXp(int xp){ | ||||
| @@ -32,7 +32,7 @@ public class Player extends Character{ | ||||
| 			// Compute direction and next cell | ||||
| 			Vector<TiledMapTile> nextCell = new Vector<>(); | ||||
| 			Player.Direction goalDirection = Player.Direction.NULL; | ||||
| 			Vector2 nextPos = new Vector2(position); | ||||
| 			Vector2 nextPos = position; | ||||
|  | ||||
| 			if (c.keyStatus.get(Input.Keys.RIGHT)) { | ||||
| 				goalDirection = Player.Direction.RIGHT; | ||||
| @@ -76,13 +76,12 @@ public class Player extends Character{ | ||||
| 					nMap = ScreenMap.Door.nextMap; | ||||
| 					x = ScreenMap.Door.nextX; | ||||
| 					y = ScreenMap.Door.nextY; | ||||
| 					goalDirection = ScreenMap.Door.direction; | ||||
| 				} catch (Exception e) { } | ||||
| 				ScreenMap.Door.reset(); | ||||
| 				if (nMap == null || x == null || y == null) return; | ||||
| 				map = nMap; | ||||
| 				setPosition(x*sm.tileWidth, y*sm.tileHeight); | ||||
| 				System.out.println("Go to: " + map + " in " + x + " x " + y); | ||||
| 				System.out.println("Go to: " + sm.map + " in " + x + " x " + y); | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| @@ -98,7 +97,7 @@ public class Player extends Character{ | ||||
| 			 | ||||
| 			if(bMap && pX==eX && pY==eY) { | ||||
| 				lastEnemy = enemy; | ||||
| 				onEnemy = true; | ||||
| 				frontOfEnemy = true; | ||||
| 				return true; | ||||
| 			} | ||||
| 		} | ||||
|   | ||||
| @@ -1,5 +1,7 @@ | ||||
| package Game; | ||||
|  | ||||
| import java.util.Arrays; | ||||
|  | ||||
| import Entity.Enemy; | ||||
| import Text.TextEnemy; | ||||
|  | ||||
| @@ -12,6 +14,8 @@ public class Battle { | ||||
| 	 | ||||
| 	public int answer; | ||||
|  | ||||
|     private int winPoint; | ||||
|     | ||||
|  | ||||
|     public Battle(Enemy enemy){ | ||||
|         this.enemy = enemy; | ||||
| @@ -19,9 +23,8 @@ public class Battle { | ||||
| 		textEnemy.generateText(); | ||||
|  | ||||
|         lineSpeech = 0; | ||||
|         answer = 0; | ||||
|         winPoint = 0; | ||||
|  | ||||
|         //initialize the first line | ||||
|         System.out.println("lll : "+ getLine()); | ||||
|          | ||||
|     } | ||||
| @@ -32,6 +35,37 @@ public class Battle { | ||||
|  | ||||
| 	} | ||||
|  | ||||
|     //check the choice answer | ||||
|     public void checkAnswer(int answer){ | ||||
|         int attack = lineSpeech-1; | ||||
|         //get number current attack random | ||||
|         int currentAttack = textEnemy.getCurrentData().get(attack)[0]; | ||||
|         System.out.println(Arrays.toString(textEnemy.getCurrentData().get(attack))); | ||||
|  | ||||
|         //get number current answer random | ||||
|         int currentAnswer = textEnemy.getCurrentData().get(attack)[answer]; | ||||
|         System.out.println("current answer  : " + currentAnswer); | ||||
|  | ||||
|         //get the answer of the player | ||||
|         String answerPlayer = textEnemy.fightData.getAttack(currentAttack).getAnswer(currentAnswer); | ||||
|         System.out.println("answer player  : " + answerPlayer); | ||||
|  | ||||
|         //get true answer | ||||
|         String trueAsnwer = textEnemy.fightData.getAttack(currentAttack).getTrueAnswer(); | ||||
|         System.out.println("true answer : " + trueAsnwer); | ||||
|  | ||||
|         //check the choice of the player | ||||
|         if(answerPlayer == trueAsnwer){ | ||||
|             System.out.println("it's true !!!!"); | ||||
|         } | ||||
|         else{ | ||||
|             System.out.println("it's false !!!!"); | ||||
|         } | ||||
|  | ||||
|         readNextLine(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public boolean getAttackOn(){ | ||||
|         return textEnemy.lines.get(lineSpeech).attackOn; | ||||
|     } | ||||
| @@ -40,6 +74,7 @@ public class Battle { | ||||
|         return textEnemy.lines.get(lineSpeech).line; | ||||
|     } | ||||
|  | ||||
|      | ||||
|     public int getLineSpeech() { | ||||
|         return lineSpeech; | ||||
|     } | ||||
|   | ||||
| @@ -62,7 +62,7 @@ public class PokeMudry extends PortableApplication { | ||||
|         if(onMapScreen) sp.p.manageEntity(sp.sm, controller); | ||||
|          | ||||
|         // Switch screen | ||||
|         if (sp.p.onEnemy && onMapScreen){ | ||||
|         if (sp.p.frontOfEnemy && onMapScreen){ | ||||
|             sp.e = sp.p.lastEnemy; | ||||
|             sp.sb = sp.screenManager.getScreenBattle(); | ||||
|             sp.b = new Battle(sp.e); | ||||
|   | ||||
| @@ -98,7 +98,6 @@ public class ScreenBattle extends RenderingScreen{ | ||||
| 		if(PokeMudry.front_montant){ | ||||
|  	     	System.out.println("manage: " + battle.getLineSpeech()); | ||||
|  | ||||
|  | ||||
| 			if( battle.getAttackOn() == false){ | ||||
| 				if (c.keyStatus.get(Input.Keys.SPACE)){ | ||||
| 					System.out.println("in"); | ||||
| @@ -106,24 +105,22 @@ public class ScreenBattle extends RenderingScreen{ | ||||
| 				} | ||||
| 			} | ||||
|  | ||||
|  | ||||
| 			if(battle.getAttackOn() == true){ | ||||
| 				if (c.keyStatus.get(Input.Keys.NUM_1)){ | ||||
| 					System.out.println("je sui dansakjshfljkahflkasjhfdlkajshflkajshfdlkasjdhfalsdkjfh123412341234"); | ||||
| 					battle.readNextLine(); | ||||
| 					battle.answer = 1; | ||||
| 					 | ||||
| 					battle.checkAnswer(1); | ||||
| 				} | ||||
| 				else if (c.keyStatus.get(Input.Keys.NUM_2)){ | ||||
| 					battle.readNextLine(); | ||||
| 					battle.answer = 2; | ||||
|  | ||||
| 					battle.checkAnswer(2); | ||||
| 				} | ||||
| 				else if (c.keyStatus.get(Input.Keys.NUM_3)){ | ||||
| 					battle.readNextLine(); | ||||
| 					battle.answer = 3; | ||||
| 	 | ||||
| 					battle.checkAnswer(3); | ||||
| 				} | ||||
| 				else if (c.keyStatus.get(Input.Keys.NUM_4)){ | ||||
| 					battle.readNextLine(); | ||||
| 					battle.answer = 4; | ||||
|  | ||||
| 					battle.checkAnswer(4); | ||||
| 					 | ||||
| 				} | ||||
| 			} | ||||
| @@ -135,5 +132,6 @@ public class ScreenBattle extends RenderingScreen{ | ||||
|  | ||||
|  | ||||
| 	 | ||||
|  | ||||
| 	} | ||||
| } | ||||
|   | ||||
| @@ -59,24 +59,18 @@ public class ScreenMap extends RenderingScreen{ | ||||
|          | ||||
|         tiledLayer.clear(); | ||||
|          | ||||
|         // Get actual map of the player | ||||
|         try { map = player.getMap(); } catch (Exception e) { System.out.println("error for get map");} | ||||
|         try { map = player.getMap(); } catch (Exception e) {} | ||||
|  | ||||
| 		// Get all layers on the current map | ||||
| 		for (int i = 0; i < 50; i++) { | ||||
|             try { tiledLayer.add((TiledMapTileLayer) tMap.get(map).getLayers().get(i)); } catch (Exception e) { } | ||||
|         } | ||||
|  | ||||
|         // Get heigh and width of tiles and the size of the tiles | ||||
|         TiledMapTileLayer tl = tiledLayer.get(0); | ||||
|         width = tl.getWidth(); | ||||
|         tileWidth = (int) tl.getTileWidth(); | ||||
|         height = tl.getHeight(); | ||||
|         tileHeight = (int) tl.getTileHeight(); | ||||
|          | ||||
|         // System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); | ||||
|  | ||||
|         // Get all doors on the current map | ||||
|         //System.out.println(width + " x " + height + " - " + tileWidth + " x " + tileHeight); | ||||
| 		try { | ||||
|             doors = tMap.get(map).getLayers().get("door").getObjects(); | ||||
| 		} catch (Exception e) {	doors = null; } | ||||
| @@ -84,7 +78,8 @@ public class ScreenMap extends RenderingScreen{ | ||||
| 		 | ||||
| 		// Render the tileMap | ||||
|         g.zoom(zoom); | ||||
|         g.moveCamera((int)player.getPosition().x, (int)player.getPosition().y, width * tileWidth, height * tileHeight); | ||||
|         try {g.moveCamera(player.getPosition().x, player.getPosition().y, width * tileWidth, height * tileHeight);} | ||||
|         catch (Exception e) {System.out.println("Fail to move camera");} | ||||
|  | ||||
| 		tMapRenderer.get(map).setView(g.getCamera()); | ||||
| 		tMapRenderer.get(map).render(); | ||||
| @@ -111,11 +106,10 @@ public class ScreenMap extends RenderingScreen{ | ||||
|  | ||||
|     public boolean isWalkable(Vector<TiledMapTile> tile) { | ||||
| 		if (tile == null) return false; | ||||
| 		if (tile.size() == 0) return false; | ||||
|         boolean walkable = true; | ||||
|         boolean walkable = false; | ||||
|         for (TiledMapTile tiledMapTile : tile) { | ||||
|             Object test = tiledMapTile.getProperties().get("walkable"); | ||||
|             walkable = Boolean.parseBoolean(test.toString()) ? walkable:false; | ||||
|             walkable = Boolean.parseBoolean(test.toString()) ? true:walkable; | ||||
|         } | ||||
|         return walkable; | ||||
| 	} | ||||
| @@ -156,7 +150,6 @@ public class ScreenMap extends RenderingScreen{ | ||||
| 				try { Door.nextMap = mapProperties.get("nextMap").toString(); } catch (Exception e) { } | ||||
| 				try { Door.nextX = Integer.parseInt(mapProperties.get("nextX").toString()); } catch (Exception e) { } | ||||
| 				try { Door.nextY = Integer.parseInt(mapProperties.get("nextY").toString()); } catch (Exception e) { } | ||||
| 				try { Door.direction = Player.Direction.valueOf(mapProperties.get("nextDirection").toString()); } catch (Exception e) { } | ||||
| 			} | ||||
|         } | ||||
|          | ||||
| @@ -167,13 +160,11 @@ public class ScreenMap extends RenderingScreen{ | ||||
| 		public static String nextMap; | ||||
| 		public static Integer nextX; | ||||
| 		public static Integer nextY; | ||||
|         public static Player.Direction direction; | ||||
|  | ||||
| 		public static void reset(){ | ||||
| 			nextMap = null; | ||||
| 			nextX = null; | ||||
| 			nextY = null; | ||||
| 			direction = null; | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
|   | ||||
| @@ -2,11 +2,12 @@ package Text; | ||||
|  | ||||
| public class Attack { | ||||
|     String attack; | ||||
|     int currentAttack; | ||||
|     String answer1; | ||||
|     String answer2; | ||||
|     String answer3; | ||||
|     String answer4; | ||||
|     String[] s; | ||||
|     public String[] s; | ||||
|  | ||||
|     float xp; | ||||
|  | ||||
| @@ -32,4 +33,9 @@ public class Attack { | ||||
|     public String getAnswer(int i){ | ||||
|         return s[i]; | ||||
|     } | ||||
|  | ||||
|     public String getTrueAnswer(){ | ||||
|         return answer1; | ||||
|     } | ||||
|  | ||||
| } | ||||
|   | ||||
| @@ -11,14 +11,15 @@ public class FightData { | ||||
|     private  File file; | ||||
|     private static final String REGEX = ","; | ||||
|  | ||||
|      | ||||
|  | ||||
|     public int nbre_line =0; | ||||
|  | ||||
|     public FightData(String name) { | ||||
|         file = new File("./resources/Battle/Fight/" + name + ".csv"); | ||||
|          | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|     public void readFile() { | ||||
|         Attack attack; | ||||
|         String line = ""; | ||||
| @@ -43,7 +44,8 @@ public class FightData { | ||||
|         } catch (Exception e) { | ||||
|             e.printStackTrace(); | ||||
|         } | ||||
|         System.out.println(attacks.size()); | ||||
|  | ||||
|          | ||||
|     } | ||||
|  | ||||
|     //return the vector with all attaks of one enemi | ||||
| @@ -56,6 +58,10 @@ public class FightData { | ||||
|         return attacks.get(a); | ||||
|     } | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| } | ||||
|  | ||||
|      | ||||
|   | ||||
| @@ -13,6 +13,8 @@ public class TextEnemy { | ||||
|     private int[] orderAttack; | ||||
|     private int[] orderAnswer; | ||||
|  | ||||
|     private Vector<int[]> currentData; | ||||
|  | ||||
|     public static void main(String[] args) { | ||||
|          | ||||
|         TextEnemy t  = new TextEnemy("enemi"); | ||||
| @@ -35,6 +37,9 @@ public class TextEnemy { | ||||
|         speechData = new SpeechData(name); | ||||
|         speechData.readFile(); | ||||
|  | ||||
|         //save random data (attack and ansver) : attack, answer 1, answer 2 answer 3, answer 4 | ||||
|         currentData = new Vector<int[]>(); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     public static int[] randomGenerate( int min, int max, int nbreRandom){ | ||||
| @@ -74,27 +79,48 @@ public class TextEnemy { | ||||
|     public void generateText(){ | ||||
|         int i =1; | ||||
|          | ||||
|  | ||||
|         //introduction line | ||||
|         lines.add(new Line(speechData.getSpeechs(0), false)); | ||||
|         orderAttack = randomGenerate(0, fightData.nbre_line-1, 4); | ||||
|         for(int j=0; j<4;j++){ | ||||
|             int[] currentRandom = new int[5]; | ||||
|             currentRandom[0] = orderAttack[j]; | ||||
|  | ||||
|             //generate the order of the answer | ||||
|             orderAnswer = randomGenerate(0, 3, 4); | ||||
|             System.out.println("\n" + Arrays.toString(orderAnswer) + "\n"); | ||||
|             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)  | ||||
|             lines.add(new Line( | ||||
|                 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)); | ||||
|                 "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); | ||||
|         } | ||||
|          | ||||
|         for(int[] a : currentData){ | ||||
|             System.out.println(Arrays.toString(a)); | ||||
|         } | ||||
|  | ||||
|         //finish (win and death) | ||||
|         lines.add(new Line(speechData.getSpeechs(5), false)); | ||||
|         lines.add(new Line(speechData.getSpeechs(6), false)); | ||||
|     } | ||||
|  | ||||
|     public Vector<int[]> getCurrentData() { | ||||
|         return currentData; | ||||
|     } | ||||
|  | ||||
|      | ||||
| } | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user