From 983d314d1dc76656b7e8778ffc77aa98ccf92520 Mon Sep 17 00:00:00 2001
From: Kellian Mirey <kellian.mirey.etu@univ-lille.fr>
Date: Thu, 5 Sep 2024 10:08:10 +0200
Subject: [PATCH] First patch for display main

---
 assets/DialogBox.text               |  6 +++---
 src/main/java/bitFight/Display.java | 19 ++++++++++++------
 src/main/java/bitFight/Input.java   |  6 +-----
 src/main/java/bitFight/Level.java   |  7 +++++++
 src/main/java/bitFight/Main.java    | 30 ++++++++++++++---------------
 5 files changed, 39 insertions(+), 29 deletions(-)

diff --git a/assets/DialogBox.text b/assets/DialogBox.text
index 3824c2c..2882879 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 7717339..5d47f5c 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/Input.java b/src/main/java/bitFight/Input.java
index 3cef902..62d37f0 100644
--- a/src/main/java/bitFight/Input.java
+++ b/src/main/java/bitFight/Input.java
@@ -37,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 b7b150e..5cf0541 100644
--- a/src/main/java/bitFight/Level.java
+++ b/src/main/java/bitFight/Level.java
@@ -59,13 +59,16 @@ 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 de l'ennemi
@@ -109,14 +112,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
diff --git a/src/main/java/bitFight/Main.java b/src/main/java/bitFight/Main.java
index 74a651d..f324907 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();
                 
@@ -94,9 +94,7 @@ class Main {
                     if (!actionNames.contains(input.getInput())){
                         Display.clearDialogBox();
                         level.invalidActionChoice();                        
-                        input.newInput();
-                        System.out.println(actionNames.toString());
-                        System.out.println(input.getInput());
+                        input.newInput(in.readLine());
                     }
                 }
                 
@@ -112,7 +110,9 @@ class Main {
                 Display.newPrintln(enemy.toString());
                 
                 //Display.clearDialogBox();
-                
+
+                input.newInput(in.readLine());
+
                 if (enemy.isDead()){
                     level.ennemyDying();
                     player.revive();
-- 
GitLab