Class BattleSimulationSingleton

java.lang.Object
edu.ntnu.idatt2001.carljgu.client.BattleSimulationSingleton

public class BattleSimulationSingleton extends Object
Singleton class to hold information for the controllers.
Version:
1.1 20.05.2022
Author:
Carl Gützkow
  • Field Details

    • battleSimulationSingleton

      private static final BattleSimulationSingleton battleSimulationSingleton
    • battle

      private Battle battle
    • originalArmies

      private final Army[] originalArmies
    • currentArmies

      private final Army[] currentArmies
    • scores

      private final int[] scores
    • filePaths

      private final String[] filePaths
    • importedLinesSkipped

      private List<String> importedLinesSkipped
    • amountOfArmies

      private final int amountOfArmies
    • currentArmyNumber

      private int currentArmyNumber
  • Constructor Details

    • BattleSimulationSingleton

      private BattleSimulationSingleton()
      Private constructor to uphold singleton design pattern. initializes the arrays.
  • Method Details

    • getBattleSimulation

      public static BattleSimulationSingleton getBattleSimulation()
      Gets the battle simulation instance
      Returns:
      battleSimulationSingleton - BattleSimulationSingleton - the simulation object that holds the models' information
    • getBattle

      public Battle getBattle()
      Gets the current battle.
      Returns:
      battle - Battle - the current battle to simulate.
    • setBattle

      public void setBattle(Battle battle)
      Sets the current battle.
      Parameters:
      battle - Battle - the current battle to simulate.
    • getOriginalArmyByNumber

      public Army getOriginalArmyByNumber(int armyNumber)
      Gets the original army by an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      Returns:
      Army - an army in the original army array.
    • setOriginalArmyByNumber

      public void setOriginalArmyByNumber(int armyNumber, Army army)
      Sets original army at an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      army - Army - an army in the original army array.
    • atLestOneOriginalArmyIsNull

      public boolean atLestOneOriginalArmyIsNull()
      Checks if more than one army is null
      Returns:
      boolean - true if at least one army is a null object.
    • getCurrentArmyByNumber

      public Army getCurrentArmyByNumber(int armyNumber)
      Gets current army by an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      Returns:
      Army - an army in the current army array.
    • setCurrentArmyByNumber

      public void setCurrentArmyByNumber(int armyNumber, Army army)
      Sets current army at an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      army - Army - an army in the current army array.
    • getScoreByNumber

      public int getScoreByNumber(int armyNumber)
      Gets score by an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      Returns:
      int - how many simulations an army has won.
    • setScoreByNumber

      public void setScoreByNumber(int armyNumber, int score)
      Sets score at an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      score - int - how many simulations an army has won.
    • incrementScore

      public void incrementScore(int armyNumber)
      Increment score at an army index number.
      Parameters:
      armyNumber - int - the index of the army.
    • resetScores

      public void resetScores()
      Fills the array with scores with zeroes
    • getFilePathByNumber

      public String getFilePathByNumber(int armyNumber)
      Gets file path by an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      Returns:
      String - file path for an army at the army index number.
    • setFilePathByNumber

      public void setFilePathByNumber(int armyNumber, String filePath)
      Sets file path at an army index number.
      Parameters:
      armyNumber - int - the index of the army.
      filePath - String - file path for an army at the army index number.
    • getImportedLinesSkipped

      public List<String> getImportedLinesSkipped()
      Gets a list of all lines skipped when importing an army.
      Returns:
      importedLinesSkipped - List - which lines were skipped during importing and why.
    • setImportedLinesSkipped

      public void setImportedLinesSkipped(List<String> importedLinesSkipped)
      Sets which lines were skipped during import.
      Parameters:
      importedLinesSkipped - List - which lines were skipped during importing and why.
    • getArmiesAmount

      public int getArmiesAmount()
      Gets the amount of armies.
      Returns:
      int - amount of armies.
    • getCurrentArmyNumber

      public int getCurrentArmyNumber()
      Gets the current army number.
      Returns:
      int - the current army number.
    • setCurrentArmyNumber

      public void setCurrentArmyNumber(int armyNumber)
      Sets current army index number.
      Parameters:
      armyNumber - int - army index number.
    • getCurrentArmyByCurrentNumber

      public Army getCurrentArmyByCurrentNumber()
      Gets current army by current number.
      Returns:
      Army - the current army at the current army index number.