Class BattleSimulationSingleton
java.lang.Object
edu.ntnu.idatt2001.carljgu.client.BattleSimulationSingleton
Singleton class to hold information for the controllers.
- Version:
- 1.1 20.05.2022
- Author:
- Carl Gützkow
-
Field Summary
Modifier and TypeFieldDescriptionprivate final int
private Battle
private static final BattleSimulationSingleton
private final Army[]
private int
private final String[]
private final Army[]
private final int[]
-
Constructor Summary
ModifierConstructorDescriptionprivate
Private constructor to uphold singleton design pattern. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Checks if more than one army is nullint
Gets the amount of armies.Gets the current battle.static BattleSimulationSingleton
Gets the battle simulation instanceGets current army by current number.getCurrentArmyByNumber
(int armyNumber) Gets current army by an army index number.int
Gets the current army number.getFilePathByNumber
(int armyNumber) Gets file path by an army index number.Gets a list of all lines skipped when importing an army.getOriginalArmyByNumber
(int armyNumber) Gets the original army by an army index number.int
getScoreByNumber
(int armyNumber) Gets score by an army index number.void
incrementScore
(int armyNumber) Increment score at an army index number.void
Fills the array with scores with zeroesvoid
Sets the current battle.void
setCurrentArmyByNumber
(int armyNumber, Army army) Sets current army at an army index number.void
setCurrentArmyNumber
(int armyNumber) Sets current army index number.void
setFilePathByNumber
(int armyNumber, String filePath) Sets file path at an army index number.void
setImportedLinesSkipped
(List<String> importedLinesSkipped) Sets which lines were skipped during import.void
setOriginalArmyByNumber
(int armyNumber, Army army) Sets original army at an army index number.void
setScoreByNumber
(int armyNumber, int score) Sets score at an army index number.
-
Field Details
-
battleSimulationSingleton
-
battle
-
originalArmies
-
currentArmies
-
scores
private final int[] scores -
filePaths
-
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
Gets the battle simulation instance- Returns:
- battleSimulationSingleton - BattleSimulationSingleton - the simulation object that holds the models' information
-
getBattle
Gets the current battle.- Returns:
- battle - Battle - the current battle to simulate.
-
setBattle
Sets the current battle.- Parameters:
battle
- Battle - the current battle to simulate.
-
getOriginalArmyByNumber
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
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
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
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
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
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
Gets a list of all lines skipped when importing an army.- Returns:
- importedLinesSkipped - List - which lines were skipped during importing and why.
-
setImportedLinesSkipped
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
Gets current army by current number.- Returns:
- Army - the current army at the current army index number.
-