Skip to content
Snippets Groups Projects
Commit 6d5c4735 authored by Camille Okubo's avatar Camille Okubo
Browse files
parents 2c158de0 c2b1330e
No related branches found
No related tags found
No related merge requests found
......@@ -70,4 +70,10 @@ public class Display {
System.out.println(text);
goToUserInput();
}
public static void displayNewHealthBar(){
setCursorPos(row,0);
level.displayLifePoints();
goToUserInput();
}
}
......@@ -5,10 +5,13 @@ import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;
public class Input {
private String input = "";
private ArrayList<String> inputRange;
private static BufferedReader in= new BufferedReader( new InputStreamReader(System.in));
public String getInput() {
return input;
......@@ -27,23 +30,15 @@ public class Input {
}
public void newInput() throws IOException {
public void newInput(Scanner in) throws IOException {
do {
BufferedReader in= new BufferedReader( new InputStreamReader(System.in));
try {
try {
setInput(in.readLine());
} catch (IOException e) {
// TODO Auto-generated catch block
System.err.println(e.getMessage() + ": Contact support");
}
setInput(in.nextLine());
} catch (InvalidInputException e) {
Display.newPrintln(e.getMessage());
} catch (Exception e) {
System.err.println(e.getMessage()+": Contact support");
} finally {
// in.close();
}
}
while (!validInput());
......
......@@ -89,7 +89,7 @@ public class Level{
}
}
System.out.print(" ");
System.err.println( (int) this.player.getCurrentHealth() + "/" + (int) this.player.getMaxHealth());
System.err.println( (int) this.player.getCurrentHealth() + "/" + (int) this.player.getMaxHealth() + " ");
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.RESET);
......@@ -100,7 +100,7 @@ public class Level{
public String displayPlayerHealth(){
return (int )this.ennemy.getCurrentHealth() +" / " + (int) this.ennemy.getMaxHealth();
return (int )this.player.getCurrentHealth() +" / " + (int) this.player.getMaxHealth();
}
......
......@@ -7,6 +7,7 @@ import java.io.InputStreamReader;
import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;
class Main {
......@@ -27,15 +28,7 @@ class Main {
level = gamedata.getLevelReached();
}
try {
menu.display();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
menu.display();
menu.validate();
Display.clearScreen();
......@@ -62,7 +55,7 @@ class Main {
ArrayList<String> actionNames = new ArrayList<>();
for (Action a : actionList) actionNames.add(a.getName());
BufferedReader in= new BufferedReader( new InputStreamReader(System.in));
Scanner in= new Scanner(System.in);
Random rand = new Random();
......@@ -70,7 +63,7 @@ class Main {
level.ennemyShowing();
Input input = new Input();
input.newInput();
input.newInput(in);
Display.goToDialogBox();
......@@ -82,9 +75,8 @@ class Main {
LocalDateTime timeBeforeAttack = LocalDateTime.now();
int attackTime = 5 - (int)(5 * rand.nextDouble());
if (input.getInput().equals("a")) {
level.possibleActions();
input.newInput();
input.newInput(in);
// 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")) {
......@@ -94,14 +86,15 @@ class Main {
Display.clearDialogBox();
Attack randomEnemyAttack = Attack.values()[(int) rand.nextDouble()*Attack.values().length];
level.ennemyFaster(randomEnemyAttack);
Display.displayNewHealthBar();
timeBeforeAttack = LocalDateTime.now();
input.newInput();
input.newInput(in);
}
if (!actionNames.contains(input.getInput())){
Display.clearDialogBox();
level.invalidActionChoice();
input.newInput();
input.newInput(in);
}
}
......@@ -130,8 +123,6 @@ class Main {
//Display.clearDialogBox();
input.newInput();
if (enemy.isDead()){
level.ennemyDying();
player.revive();
......@@ -139,6 +130,10 @@ class Main {
enemy.levelUp();
level.levelGoingUp();
level.displayEndOfLevel();
}
if (player.isDead()){
Display.clearScreen();
level.defeat();
}
if (player.isDead()) {
......@@ -152,6 +147,5 @@ class Main {
in.close();
Save.saveObject("res/gamedata", gamedata);
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment