diff --git a/src/Entity/Player.java b/src/Entity/Player.java index 57d3b3f..d4aa5ac 100644 --- a/src/Entity/Player.java +++ b/src/Entity/Player.java @@ -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 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; } } diff --git a/src/Game/Battle.java b/src/Game/Battle.java index 8dbfc6b..9de1486 100644 --- a/src/Game/Battle.java +++ b/src/Game/Battle.java @@ -1,5 +1,7 @@ package Game; +import java.util.Arrays; + import Entity.Enemy; import Text.TextEnemy; @@ -11,6 +13,8 @@ public class Battle { private int lineSpeech; public int answer; + + private int winPoint; public Battle(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; } diff --git a/src/Main/PokeMudry.java b/src/Main/PokeMudry.java index 372370d..4ff97e1 100644 --- a/src/Main/PokeMudry.java +++ b/src/Main/PokeMudry.java @@ -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); diff --git a/src/Screen/ScreenBattle.java b/src/Screen/ScreenBattle.java index 4a7e812..86b11ee 100644 --- a/src/Screen/ScreenBattle.java +++ b/src/Screen/ScreenBattle.java @@ -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); } } @@ -131,6 +128,7 @@ public class ScreenBattle extends RenderingScreen{ //mettre le front à false jusqu'à ce que le bouton soit relâché PokeMudry.front_montant = false; } + diff --git a/src/Screen/ScreenMap.java b/src/Screen/ScreenMap.java index e6cc804..09c2a9f 100644 --- a/src/Screen/ScreenMap.java +++ b/src/Screen/ScreenMap.java @@ -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++) { + 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 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; } } diff --git a/src/Text/Attack.java b/src/Text/Attack.java index 48da327..c915827 100644 --- a/src/Text/Attack.java +++ b/src/Text/Attack.java @@ -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; + } + } diff --git a/src/Text/FightData.java b/src/Text/FightData.java index 1ca671d..99914e5 100644 --- a/src/Text/FightData.java +++ b/src/Text/FightData.java @@ -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); } + + + + } diff --git a/src/Text/TextEnemy.java b/src/Text/TextEnemy.java index 9b3f9bb..a783fa1 100644 --- a/src/Text/TextEnemy.java +++ b/src/Text/TextEnemy.java @@ -13,6 +13,8 @@ public class TextEnemy { private int[] orderAttack; private int[] orderAnswer; + private Vector 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(); + } 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"); - //attack and answer (number on vector : 1-4) + 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 getCurrentData() { + return currentData; + } + }