diff --git a/assets/DialogBox.text b/assets/DialogBox.text index 3824c2cfa6d57ed073ec9ad88effe88f20d33bf0..2882879bc05263cc3ac838d5c349e4c50e053252 100644 --- a/assets/DialogBox.text +++ b/assets/DialogBox.text @@ -1,4 +1,4 @@ -________________________________________________________________________________________________________________________ + @@ -13,7 +13,7 @@ ________________________________________________________________________________ Commandes : - a - Attaquer - q - Quitter + a - Action + q - Quitter ________________________________________________________________________________________________________________________ \ No newline at end of file diff --git a/src/main/java/bitFight/Display.java b/src/main/java/bitFight/Display.java index 77173399f160548dac6e55a4e453e390d134e0ff..5d47f5c96155f82bd4434c39f6a31042d05225ce 100644 --- a/src/main/java/bitFight/Display.java +++ b/src/main/java/bitFight/Display.java @@ -31,20 +31,27 @@ public class Display { } public static void goToDialogBox(){ - setCursorPos(row+7,0); + setCursorPos(1,0); + //System.out.flush(); } - public static void clearDialogBox() throws IOException{ + public static void clearDialogBox(){ clearScreen(); setCursorPos(row, 0); printDialogBox(); goToDialogBox(); } - public static void printDialogBox() throws IOException{ - setCursorPos(50, 0); - String dialogBox = loadTextFile("assets/DialogBox.text"); + public static void printDialogBox(){ + setCursorPos(100, 0); + String dialogBox = ""; + try { + dialogBox = loadTextFile("assets/DialogBox.text"); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } System.out.println(dialogBox); } @@ -52,7 +59,7 @@ public class Display { setCursorPos(50, 0); } - public static void newPrintln(String text) throws IOException{ + public static void newPrintln(String text){ clearDialogBox(); System.out.println(text); goToUserInput(); diff --git a/src/main/java/bitFight/Enemy.java b/src/main/java/bitFight/Enemy.java index a2ec9113a2c5f2083e9b33573fe3f6eefdc340c4..948ce6f6515077b53acff449dff38749c5ee60f0 100644 --- a/src/main/java/bitFight/Enemy.java +++ b/src/main/java/bitFight/Enemy.java @@ -32,7 +32,7 @@ public class Enemy extends Character{ public String toString() { - return name + " LE " + characteristic.name() + " : level " + this.level + " - Current life level : " + (int)this.currentHealth; + return name + " LE " + characteristic.name() + " : level " + this.level; } public Characteristics getCharacteristic() { diff --git a/src/main/java/bitFight/Input.java b/src/main/java/bitFight/Input.java index 1b19f6f427d0cd68b5f529b97278c0b4779e9a0d..62d37f08a893c0e84a83d90db6d64c1a51e669c4 100644 --- a/src/main/java/bitFight/Input.java +++ b/src/main/java/bitFight/Input.java @@ -1,9 +1,7 @@ package bitFight; -import java.io.BufferedReader; import java.io.IOException; -import java.io.InputStreamReader; import java.util.ArrayList; public class Input { @@ -39,11 +37,7 @@ public class Input { e.printStackTrace(); } } catch (InvalidInputException e) { - try { - Display.newPrintln(e.getMessage()); - } catch (IOException e1) { - e1.printStackTrace(); - } + Display.newPrintln(e.getMessage()); } } while (!validInput()); diff --git a/src/main/java/bitFight/Level.java b/src/main/java/bitFight/Level.java index b129a2f8e8afb9a8950df81469a090e47fa68877..7c792aa03633c85e96e1ef7fe95be126ddd1f9c2 100644 --- a/src/main/java/bitFight/Level.java +++ b/src/main/java/bitFight/Level.java @@ -59,38 +59,42 @@ public class Level{ // annonce un nouvel ennemi public void ennemyShowing() { System.out.println("An ennemy just appeared : " + this.ennemy.toString()); + System.out.println(); } public void ennemyFaster(Attack attack) { + Display.clearDialogBox(); System.out.println("The ennemy attacks before you can !"); player.setCurrentHealth(player.getCurrentHealth() - attack.getDamage() * this.ennemy.getAttackMultiplier()); //Récupère une attaque aléatoire dans l'enum System.out.println(attack.getName() + "!! You're getting " + (int) attack.getDamage() * this.ennemy.getAttackMultiplier() + " of damage!"); System.out.println(this.player.getName() + "'s life' : " + this.displayPlayerHealth()); + Display.goToUserInput(); } + // affiche la jauge de vie public void displayLifePoints (){ System.err.println(); System.out.println("\t \t " +this.player.getName()); - System.out.print(Terminal.GREEN+" \t current health "+Terminal.GREEN); + System.out.print(Terminal.GREEN+" \t current health "+Terminal.RESET); for (int indice = 0; indice < ((this.player.getCurrentHealth()/this.player.getMaxHealth())*100)/2; indice ++){ - System.out.print(Terminal.GREEN+ "▬"+ Terminal.GREEN); + System.out.print(Terminal.GREEN+ "▬"+ Terminal.RESET); } System.out.print(" "); System.err.println( (int) this.player.getCurrentHealth() + "/" + (int) this.player.getMaxHealth()); - System.out.print(Terminal.YELLOW+"\t current energy "+Terminal.YELLOW); + System.out.print(Terminal.YELLOW+"\t current energy "+Terminal.RESET); for (int indice = 0; indice < (this.player.getCurrentEnergy())/2; indice ++){ - System.out.print(Terminal.YELLOW +"▬"+ Terminal.YELLOW); + System.out.print(Terminal.YELLOW +"▬"+ Terminal.RESET); } System.out.print(" "); System.err.println(this.player.getCurrentEnergy() + "/" + this.player.getMaxEnergy()); } - // affiche la jauge de vie du joueur - public String displayPlayerHealth() { - return (int)this.player.getCurrentHealth() +"/" + (int)this.player.getMaxHealth(); + public String displayPlayerHealth(){ + return (int )this.ennemy.getCurrentHealth() +" / " + (int) this.ennemy.getMaxHealth(); } + // annonce la mort de l'ennemi public void ennemyDying() { System.out.println("The ennemy is dead!"); @@ -122,14 +126,18 @@ public class Level{ // méthodes de combats // liste des attaques et défenses possibles pour le joueur public void possibleActions() { + Display.clearDialogBox(); System.out.println("Possible attacks are : \n \t punch, kick, double kick, supermanpunch. \""); System.out.println("Possible defenses are : \n \t lowblock, highblock\""); + Display.goToUserInput(); } // quand l'utilisateur choisit une action qui n'existe pas public void invalidActionChoice() { + Display.clearDialogBox(); System.out.println("This action is not available."); possibleActions(); + Display.goToUserInput(); } // méthodes de paramètrages @@ -201,5 +209,5 @@ public class Level{ } - + diff --git a/src/main/java/bitFight/Main.java b/src/main/java/bitFight/Main.java index 74a651dd045f8d7011025139451bc5c768a63352..0de1a18f98fa6244ca379ab2415272a7eaa1096b 100644 --- a/src/main/java/bitFight/Main.java +++ b/src/main/java/bitFight/Main.java @@ -46,9 +46,11 @@ class Main { Display.goToDialogBox(); - Display.newPrintln(Terminal.RED_BACKGROUND + "ATTAQUEZ" + Terminal.RESET + " ou " + Terminal.PURPLE_BACKGROUND + "QUITTEZ" + Terminal.RESET); + // arrivée de l'ennemi + level.ennemyShowing(); - level.displayGameRules(); + Display.newPrintln(enemy.toString()); + Display.newPrintln(Terminal.RED_BACKGROUND + "ATTAQUEZ" + Terminal.RESET + " ou " + Terminal.PURPLE_BACKGROUND + "QUITTEZ" + Terminal.RESET); Display.goToUserInput(); @@ -68,15 +70,13 @@ class Main { 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(); - + 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()); + + if (input.getInput().equals("a")) { level.possibleActions(); input.newInput(); @@ -95,8 +95,6 @@ class Main { Display.clearDialogBox(); level.invalidActionChoice(); input.newInput(); - System.out.println(actionNames.toString()); - System.out.println(input.getInput()); } } @@ -112,7 +110,9 @@ class Main { Display.newPrintln(enemy.toString()); //Display.clearDialogBox(); - + + input.newInput(); + if (enemy.isDead()){ level.ennemyDying(); player.revive(); @@ -135,4 +135,5 @@ class Main { Save.saveObject("res/gamedata", gamedata); } } +} \ No newline at end of file