fix engines bugs
This commit is contained in:
@@ -7,6 +7,10 @@ public abstract class BattleEngine {
|
||||
public Entity Player2;
|
||||
|
||||
public BattleEngine(Entity player1, Entity player2) {
|
||||
player1.ResetStamina();
|
||||
player1.RestoreHealth();
|
||||
player2.RestoreHealth();
|
||||
player2.ResetStamina();
|
||||
Player1 = player1;
|
||||
Player2 = player2;
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
super(player1, player2);
|
||||
this.player1 = (Player) Player1;
|
||||
this.player2 = (Player) Player2;
|
||||
player1Past = null;
|
||||
player2Past = null;
|
||||
player1Past = player1.copy();
|
||||
player2Past = player2.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,14 +37,16 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
player1.SetState(EntityState.ALIVE);
|
||||
}
|
||||
|
||||
player1Past = player1;
|
||||
player2Past = player2;
|
||||
|
||||
EntityDiff playerDiff = getPlayerDiff(player1Past, player1);
|
||||
EntityDiff enemyDiff = getPlayerDiff(player2Past, player2);
|
||||
|
||||
System.out.println();
|
||||
showFighter(playerDiff, player1);
|
||||
showFighter(enemyDiff, player2);
|
||||
System.out.println();
|
||||
|
||||
player1Past = player1.copy();
|
||||
player2Past = player2.copy();
|
||||
|
||||
FightMoves player2Move = PlayerMovesMenu(player2, player1);
|
||||
showMoveExplanation(player2Move, player2, player1);
|
||||
@@ -53,14 +55,16 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
player2.SetState(EntityState.ALIVE);
|
||||
}
|
||||
|
||||
player1Past = player1;
|
||||
player2Past = player2;
|
||||
|
||||
playerDiff = getPlayerDiff(player1Past, player1);
|
||||
enemyDiff = getPlayerDiff(player2Past, player2);
|
||||
|
||||
System.out.println();
|
||||
showFighter(playerDiff, player1);
|
||||
showFighter(enemyDiff, player2);
|
||||
System.out.println();
|
||||
|
||||
player1Past = player1.copy();
|
||||
player2Past = player2.copy();
|
||||
|
||||
if (player2.GetState() == EntityState.DEAD) {
|
||||
System.out.println(TextColor.Green + player1.Name + " WON!" + TextColor.Reset);
|
||||
@@ -88,10 +92,12 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
System.out.println(entity.Name + ":");
|
||||
|
||||
String color = diff.health() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Health: " + entity.Health + " " + color + diff.health() + TextColor.Reset);
|
||||
String sign = diff.health() > 0 ? "+" : "-";
|
||||
System.out.println(" Health: " + entity.Health + " " + color + sign + Math.abs(diff.health()) + TextColor.Reset);
|
||||
|
||||
color = diff.stamina() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + diff.stamina() + TextColor.Reset);
|
||||
sign = diff.stamina() > 0 ? "+" : "-";
|
||||
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + sign + Math.abs(diff.stamina()) + TextColor.Reset);
|
||||
|
||||
if (diff.lostShield()) {
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||
@@ -103,12 +109,14 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
|
||||
if (entity.Shield != null) {
|
||||
color = diff.shieldHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||
sign = diff.shieldHealth() > 0 ? "+" : "-";
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + sign + Math.abs(diff.shieldHealth()) + TextColor.Reset);
|
||||
}
|
||||
|
||||
if (entity.Costume != null) {
|
||||
color = diff.costumeHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||
sign = diff.costumeHealth() > 0 ? "+" : "-";
|
||||
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + sign + Math.abs(diff.shieldHealth()) + TextColor.Reset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,6 +164,7 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
}
|
||||
|
||||
private void showMoveExplanation(FightMoves move, Entity performer, Entity receiver) {
|
||||
System.out.print(TextColor.Cyan);
|
||||
switch (move) {
|
||||
case FightMoves.LIGHT_ATTACK -> System.out.println(performer.Name + " performs a light attack");
|
||||
case FightMoves.HEAVY_ATTACK -> System.out.println(performer.Name + " performs a heavy attack");
|
||||
@@ -163,5 +172,6 @@ public class MultiPlayerBattleEngine extends BattleEngine {
|
||||
case FightMoves.HEAL -> System.out.println(performer.Name + " heals");
|
||||
case FightMoves.DEFEND -> System.out.println(performer.Name + " get their guard up!");
|
||||
}
|
||||
System.out.print(TextColor.Reset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,8 +22,8 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
super(player, enemy);
|
||||
this.player = (Player) Player1;
|
||||
this.enemy = (Enemy) Player2;
|
||||
playerPast = null;
|
||||
enemyPast = null;
|
||||
playerPast = player.copy();
|
||||
enemyPast = enemy.copy();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -37,14 +37,16 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
player.SetState(EntityState.ALIVE);
|
||||
}
|
||||
|
||||
playerPast = player;
|
||||
enemyPast = enemy;
|
||||
playerPast = player.copy();
|
||||
enemyPast = enemy.copy();
|
||||
|
||||
EntityDiff playerDiff = getPlayerDiff(playerPast, player);
|
||||
EntityDiff enemyDiff = getPlayerDiff(enemyPast, enemy);
|
||||
|
||||
System.out.println();
|
||||
showFighter(playerDiff, player);
|
||||
showFighter(enemyDiff, enemy);
|
||||
System.out.println();
|
||||
|
||||
FightMoves botMove = enemy.PlayRound(player);
|
||||
showMoveExplanation(botMove, enemy, player);
|
||||
@@ -53,14 +55,16 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
enemy.SetState(EntityState.ALIVE);
|
||||
}
|
||||
|
||||
playerPast = player;
|
||||
enemyPast = enemy;
|
||||
playerPast = player.copy();
|
||||
enemyPast = enemy.copy();
|
||||
|
||||
playerDiff = getPlayerDiff(playerPast, player);
|
||||
enemyDiff = getPlayerDiff(enemyPast, enemy);
|
||||
|
||||
System.out.println();
|
||||
showFighter(playerDiff, player);
|
||||
showFighter(enemyDiff, enemy);
|
||||
System.out.println();
|
||||
|
||||
if (enemy.GetState() == EntityState.DEAD) {
|
||||
enemy.DropLoot(player);
|
||||
@@ -89,10 +93,12 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
System.out.println(entity.Name + ":");
|
||||
|
||||
String color = diff.health() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Health: " + entity.Health + " " + color + diff.health() + TextColor.Reset);
|
||||
String sign = diff.health() > 0 ? "+" : "-";
|
||||
System.out.println(" Health: " + entity.Health + " " + color + sign + Math.abs(diff.health()) + TextColor.Reset);
|
||||
|
||||
color = diff.stamina() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + diff.stamina() + TextColor.Reset);
|
||||
sign = diff.stamina() > 0 ? "+" : "-";
|
||||
System.out.println(" Stamina: " + entity.GetStamina() + " " + color + sign + Math.abs(diff.stamina()) + TextColor.Reset);
|
||||
|
||||
if (diff.lostShield()) {
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + TextColor.Red + "LOST" + TextColor.Reset);
|
||||
@@ -104,12 +110,14 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
|
||||
if (entity.Shield != null) {
|
||||
color = diff.shieldHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||
sign = diff.shieldHealth() > 0 ? "+" : "-";
|
||||
System.out.println(" Shield: " + entity.Shield.getName() + " " + color + sign + Math.abs(diff.shieldHealth()) + TextColor.Reset);
|
||||
}
|
||||
|
||||
if (entity.Costume != null) {
|
||||
color = diff.costumeHealth() > 0 ? TextColor.Green : TextColor.Red;
|
||||
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + diff.shieldHealth() + TextColor.Reset);
|
||||
sign = diff.costumeHealth() > 0 ? "+" : "-";
|
||||
System.out.println(" Costume: " + entity.Costume.getName() + " " + color + sign + Math.abs(diff.shieldHealth()) + TextColor.Reset);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,6 +165,7 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
}
|
||||
|
||||
private void showMoveExplanation(FightMoves move, Entity performer, Entity receiver) {
|
||||
System.out.print(TextColor.Cyan);
|
||||
switch (move) {
|
||||
case FightMoves.LIGHT_ATTACK -> System.out.println(performer.Name + " performs a light attack");
|
||||
case FightMoves.HEAVY_ATTACK -> System.out.println(performer.Name + " performs a heavy attack");
|
||||
@@ -164,5 +173,6 @@ public class SinglePlayerBattleEngine extends BattleEngine {
|
||||
case FightMoves.HEAL -> System.out.println(performer.Name + " heals");
|
||||
case FightMoves.DEFEND -> System.out.println(performer.Name + " get their guard up!");
|
||||
}
|
||||
System.out.print(TextColor.Reset);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user