diff --git a/src/main/java/bitFight/Input.java b/src/main/java/bitFight/Input.java index 1c6ebd97096bfab244afbcd735eaef8652290b09..1b19f6f427d0cd68b5f529b97278c0b4779e9a0d 100644 --- a/src/main/java/bitFight/Input.java +++ b/src/main/java/bitFight/Input.java @@ -27,10 +27,17 @@ public class Input { } - public void newInput(String input) { + public void newInput() { + BufferedReader in= new BufferedReader( new InputStreamReader(System.in)); + do { try { - setInput(input); + try { + setInput(in.readLine()); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } catch (InvalidInputException e) { try { Display.newPrintln(e.getMessage()); diff --git a/src/main/java/bitFight/Main.java b/src/main/java/bitFight/Main.java index 4d06cedb0645b4431f4453f15f5a0a1e4f19742a..74a651dd045f8d7011025139451bc5c768a63352 100644 --- a/src/main/java/bitFight/Main.java +++ b/src/main/java/bitFight/Main.java @@ -63,20 +63,22 @@ class Main { Input input = new Input(); - input.newInput(in.readLine()); + input.newInput(); Display.goToDialogBox(); - while (!input.getInput().equals("q") && !enemy.isDead() && !player.isDead()) { - - //A garder au début de la boucle, mesure le temps que le joueur à pris d'écrire - LocalDateTime timeBeforeAttack = LocalDateTime.now(); - int attackTime = 5 - (int)(5 * rand.nextDouble()); - - // arrivée de l'ennemi - level.ennemyShowing(); + if (input.getInput().equals("a")) { + while (!input.getInput().equals("q") && !enemy.isDead() && !player.isDead()) { + + //A garder au début de la boucle, mesure le temps que le joueur à pris d'écrire + LocalDateTime timeBeforeAttack = LocalDateTime.now(); + int attackTime = 5 - (int)(5 * rand.nextDouble()); + + // arrivée de l'ennemi + level.ennemyShowing(); + level.possibleActions(); - input.newInput(in.readLine()); + input.newInput(); // Boucle tant que le joueur n'a pas taper de nom d'une attaque valide ou tape trop tard ou tape q while ((!actionNames.contains(input.getInput()) || !Attack.attackInTime(timeBeforeAttack, attackTime)) && !input.getInput().equals("q")) { @@ -86,13 +88,13 @@ class Main { Attack randomEnemyAttack = Attack.values()[(int) rand.nextDouble()*Attack.values().length]; level.ennemyFaster(randomEnemyAttack); timeBeforeAttack = LocalDateTime.now(); - input.newInput(in.readLine()); + input.newInput(); } - + if (!actionNames.contains(input.getInput())){ Display.clearDialogBox(); level.invalidActionChoice(); - input.newInput(in.readLine()); + input.newInput(); System.out.println(actionNames.toString()); System.out.println(input.getInput()); } @@ -104,13 +106,13 @@ class Main { level.playerHasEnergy(attack); } else {} //TODO ajouter display trop fatigué - + //Display.clearDialogBox(); - + Display.newPrintln(enemy.toString()); - + //Display.clearDialogBox(); - + if (enemy.isDead()){ level.ennemyDying(); player.revive(); @@ -118,17 +120,19 @@ class Main { enemy.levelUp(); level.levelGoingUp(); Display.clearDialogBox(); - System.out.println('\n'); - System.out.println(" Congrats! "+'\n'); - System.out.println(" you won your first fight! + \n \t let's see what you can do with your second ennemy... Good luck! \n\t your currrent enemy level is "+level.getEnnemy().getLevel()); - + System.out.println('\n'); + System.out.println(" Congrats! "+'\n'); + System.out.println(" you won your first fight! + \n \t let's see what you can do with your second ennemy... Good luck! \n\t your currrent enemy level is "+level.getEnnemy().getLevel()); + System.out.println(" \n this time your enemy health is "+ (int) level.getEnnemy().getCurrentHealth()+ "\n ... "); - + } + } + + } + in.close(); + Save.saveObject("res/gamedata", gamedata); } - - in.close(); - Save.saveObject("res/gamedata", gamedata); - } -} + } + \ No newline at end of file