fix engines bugs

This commit is contained in:
2026-07-15 17:24:38 +03:30
parent 71f1f272f2
commit d66dab9fce
3 changed files with 46 additions and 22 deletions
@@ -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);
}
}