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 {
public Army simulate() {
if (winner != null) throw new UnsupportedOperationException("Simulation has already been run");
while (armyOne.hasUnits() && armyTwo.hasUnits()) {
Army attackingArmy;
Army defendingArmy;
Army initialAttackingArmy;
Army initialDefendingArmy;
int index = new Random().nextInt(2);
if (index == 0) {
attackingArmy = armyOne;
defendingArmy = armyTwo;
if (new Random().nextBoolean()) {
initialAttackingArmy = armyOne;
initialDefendingArmy = armyTwo;
} else {
attackingArmy = armyTwo;
defendingArmy = armyOne;
initialAttackingArmy = armyTwo;
initialDefendingArmy = armyOne;
}
Unit attacker = attackingArmy.getRandom();
Unit defender = defendingArmy.getRandom();
Unit initialAttacker = initialAttackingArmy.getRandom();
Unit initialDefender = initialDefendingArmy.getRandom();
int damageDealt = attacker.attack(defender, terrain);
attackLog.add(attackStringRepresentation(damageDealt, attacker, defender, attackingArmy, defendingArmy));
if (defender.getHealth() <= 0) {
defendingArmy.remove(defender);
int damageDealt = initialAttacker.attack(initialDefender, terrain);
attackLog.add(attackStringRepresentation(damageDealt, initialAttacker, initialDefender, initialAttackingArmy, initialDefendingArmy));
if (initialDefender.getHealth() <= 0) {
initialDefendingArmy.remove(initialDefender);
} else {
damageDealt = defender.attack(attacker, terrain);
attackLog.add(attackStringRepresentation(damageDealt, defender, attacker, defendingArmy, attackingArmy));
if (attacker.getHealth() <= 0)
attackingArmy.remove(attacker);
damageDealt = initialDefender.attack(initialAttacker, terrain);
attackLog.add(attackStringRepresentation(damageDealt, initialDefender, initialAttacker, initialDefendingArmy, initialAttackingArmy));
if (initialAttacker.getHealth() <= 0)
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