Commit 9f10703a authored by Carl Gützkow's avatar Carl Gützkow
Browse files

Merge branch 'master' of gitlab.stud.idi.ntnu.no:carljgu/Wargames

parents 1afe5e43 c9f3aa82
Pipeline #183931 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);
} }
} }
......
...@@ -253,7 +253,8 @@ public class BattleController implements Initializable { ...@@ -253,7 +253,8 @@ public class BattleController implements Initializable {
editArmyButtons[armyNumber].setDisable(simulation.getOriginalArmyByNumber(armyNumber) == null); editArmyButtons[armyNumber].setDisable(simulation.getOriginalArmyByNumber(armyNumber) == null);
armyUnitListViews[armyNumber].setItems((ObservableList<Unit>) army.getAllUnits()); armyUnitListViews[armyNumber].getItems().clear();
armyUnitListViews[armyNumber].getItems().addAll(army.getAllUnits());
} }
/** /**
......
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