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 {
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);
}
}
......
......@@ -253,7 +253,8 @@ public class BattleController implements Initializable {
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