Commit c9f3aa82 authored by CJGutz's avatar CJGutz
Browse files

enhance: battle simulate name refactor and next boolean when selecting attacker

parent 6ee0553d
Pipeline #183926 passed with stages
in 45 seconds
...@@ -96,30 +96,29 @@ public class Battle { ...@@ -96,30 +96,29 @@ public class Battle {
public Army simulate() { public Army simulate() {
if (winner != null) throw new UnsupportedOperationException("Simulation has already been run"); if (winner != null) throw new UnsupportedOperationException("Simulation has already been run");
while (armyOne.hasUnits() && armyTwo.hasUnits()) { while (armyOne.hasUnits() && armyTwo.hasUnits()) {
Army attackingArmy; Army initialAttackingArmy;
Army defendingArmy; Army initialDefendingArmy;
int index = new Random().nextInt(2); if (new Random().nextBoolean()) {
if (index == 0) { initialAttackingArmy = armyOne;
attackingArmy = armyOne; initialDefendingArmy = armyTwo;
defendingArmy = armyTwo;
} else { } else {
attackingArmy = armyTwo; initialAttackingArmy = armyTwo;
defendingArmy = armyOne; initialDefendingArmy = armyOne;
} }
Unit attacker = attackingArmy.getRandom(); Unit initialAttacker = initialAttackingArmy.getRandom();
Unit defender = defendingArmy.getRandom(); Unit initialDefender = initialDefendingArmy.getRandom();
int damageDealt = attacker.attack(defender, terrain); int damageDealt = initialAttacker.attack(initialDefender, terrain);
attackLog.add(attackStringRepresentation(damageDealt, attacker, defender, attackingArmy, defendingArmy)); attackLog.add(attackStringRepresentation(damageDealt, initialAttacker, initialDefender, initialAttackingArmy, initialDefendingArmy));
if (defender.getHealth() <= 0) { if (initialDefender.getHealth() <= 0) {
defendingArmy.remove(defender); initialDefendingArmy.remove(initialDefender);
} else { } else {
damageDealt = defender.attack(attacker, terrain); damageDealt = initialDefender.attack(initialAttacker, terrain);
attackLog.add(attackStringRepresentation(damageDealt, defender, attacker, defendingArmy, attackingArmy)); attackLog.add(attackStringRepresentation(damageDealt, initialDefender, initialAttacker, initialDefendingArmy, initialAttackingArmy));
if (attacker.getHealth() <= 0) if (initialAttacker.getHealth() <= 0)
attackingArmy.remove(attacker); initialAttackingArmy.remove(initialAttacker);
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment