java.lang.Object
edu.ntnu.idatt2001.carljgu.battle.Battle

public class Battle extends Object
Class Battle that simulates a battle between two armies.
Version:
1.4 01.05.2022
Author:
Carl Gützkow
  • Field Details

    • armyOne

      private final Army armyOne
    • armyTwo

      private final Army armyTwo
    • winner

      private Army winner
    • terrain

      private final Terrain terrain
    • attackLog

      private final List<String> attackLog
  • Constructor Details

  • Method Details

    • getWinner

      public Army getWinner()
      Gets the winner of the army or a null object.
      Returns:
      winner - Army - winner of the simulated battle
    • getAttackLog

      public List<String> getAttackLog()
      Returns the log of attacks to easily hold the information about each attack.
      Returns:
      attackLog - List - a list of all the attacks performed in the simulation.
    • getTerrain

      public Terrain getTerrain()
      Gets the terrain where the battle occurs.
      Returns:
      terrain - Terrain - on what terrain the battle is fought on.
    • simulate

      public Army simulate()
      Simulate a battle. The attacking army is chosen at random. One random unit from the attacking army attacks a random unit from the defending army. Then, if the defender survives, it attacks the first attacker. If the defender has no health left, it is removed. The simulations run until one army has no units left.
      Returns:
      winner - Army - the army that won.
    • attackStringRepresentation

      public String attackStringRepresentation(int damageDealt, Unit attacker, Unit defender, Army attackingArmy, Army defendingArmy)
      Information displayed is the name of the attacking and defending army, unit information like name and class as well as how much damage was outputted from the attack. In addition, the defender's health after the attack is shown Example of an attack's representation: "InfantryUnit knight from Human army did 10 damage to RangedUnit crossbow orc from Orc army Current health of defender is now at 0"
      Parameters:
      damageDealt - int - how much health the defending unit lost
      attacker - Unit - the attacking unit
      defender - Unit - the defending unit
      attackingArmy - Army - the attacking army
      defendingArmy - Army - the defending army
      Returns:
      String - string representation of an attack
    • toString

      public String toString()
      Overrides toString() method from Object. Returns different strings depending on who won the battle or if the battle is not simulated yet. Example: Winner: Army Human army ------------------------ Infantry: 10 Ranged: 23 Cavalry: 4 Commander: 0 ------------------------ Loser: Army Orc army ------------------------ Infantry: 3 Ranged: 10 Cavalry: 4 Commander: 3 ------------------------
      Overrides:
      toString in class Object
      Returns:
      String - string representation of the battle.