Skip to content
Snippets Groups Projects
Commit 6310a9a7 authored by Kellian Mirey's avatar Kellian Mirey
Browse files

Patch Timer Bug in Main

parent 4545dada
No related branches found
No related tags found
No related merge requests found
......@@ -40,6 +40,9 @@ public enum Attack implements Action {
}
public static boolean attackInTime(LocalDateTime timeBeforeAttack, int attackTime) {
System.out.println(timeBeforeAttack);
System.out.println(LocalDateTime.now());
System.out.println(Duration.between(timeBeforeAttack, LocalDateTime.now()).toSeconds());
return (Duration.between(timeBeforeAttack, LocalDateTime.now()).toSeconds() > attackTime);
}
......
......@@ -58,7 +58,7 @@ public class Character implements Serializable {
}
public boolean isDead(){
return this.currentHealth <= 0;
return (int) this.currentHealth <= 0;
}
public void revive(){
......
......@@ -124,9 +124,9 @@ public class Level{
}
// annonce la mort du joueur
/*public void playerDying() {
public void playerDying() {
System.out.println(this.player.getName() + " is dead!");
}*/
}
// action quand le joueur n'est pas épuisé
public void playerHasEnergy(Attack attack) {
......@@ -159,7 +159,6 @@ public class Level{
// méthodes de combats
// liste des attaques et défenses possibles pour le joueur
public void possibleActions() throws IOException {
this.displayLevelInfos();
Display.clearDialogBox();
System.out.println("Possible " + Terminal.RED + "attacks" + Terminal.RESET + " are : \n \t punch, kick, double kick, supermanpunch. \"");
System.out.println("Possible " + Terminal.BLUE + "defenses" + Terminal.RESET + " are : \n \t lowblock, highblock\"");
......
......@@ -26,6 +26,7 @@ class Main {
if (gamedata != null) {
player = gamedata.getPlayer();
level = gamedata.getLevelReached();
enemy = level.getEnnemy();
}
menu.display();
......@@ -64,27 +65,18 @@ class Main {
while (!input.getInput().equals("q") && !enemy.isDead() && !player.isDead()) {
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());
int attackTime = 5;//- (int)(5 * rand.nextDouble());
level.possibleActions();
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")) {
while (!actionNames.contains(input.getInput()) && !input.getInput().equals("q") && !player.isDead()) {
//Si le joueur est trop lent, l'ennemi fait une attaque aléatoire
if(!Attack.attackInTime(timeBeforeAttack, attackTime)){
Display.clearDialogBox();
Attack randomEnemyAttack = Attack.values()[(int) rand.nextDouble()*Attack.values().length];
level.ennemyFaster(randomEnemyAttack);
Display.displayNewHealthBar();
timeBeforeAttack = LocalDateTime.now();
input.newInput(in);
}
if (!actionNames.contains(input.getInput())){
Display.clearDialogBox();
......@@ -93,6 +85,15 @@ class Main {
}
}
//Si le joueur est trop lent, l'ennemi fait une attaque aléatoire
if(Attack.attackInTime(timeBeforeAttack, attackTime)){
Display.clearDialogBox();
Attack randomEnemyAttack = Attack.values()[(int) rand.nextDouble()*Attack.values().length];
level.ennemyFaster(randomEnemyAttack);
Display.displayNewHealthBar();
timeBeforeAttack = LocalDateTime.now();
input.newInput(in);
}
if(!player.isExhausted() && !input.getInput().equals("q") ){
ActionType type = null;
......@@ -130,6 +131,7 @@ class Main {
Display.clearScreen();
level.gameOver();
level.defeat();
break;
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment