Class BattleController
java.lang.Object
edu.ntnu.idatt2001.carljgu.client.controllers.BattleController
- All Implemented Interfaces:
javafx.fxml.Initializable
A controller class which
handles events in the fxml file battle-armies.fxml.
This includes requesting to import
armies and simulate the battle
- Version:
- 2.0 14.05.2022
- Author:
- Carl Gützkow
-
Field Summary
Modifier and TypeFieldDescriptionprivate javafx.scene.control.Label[]
private javafx.scene.control.Label[]
private javafx.scene.control.Label
private javafx.scene.control.Label
private javafx.scene.control.Label
private javafx.scene.control.ListView<Unit>
private javafx.scene.control.Label[]
private javafx.scene.control.Label
private javafx.scene.control.Label
private javafx.scene.control.Label
private javafx.scene.control.ListView<Unit>
private javafx.scene.control.ListView<Unit>[]
private javafx.scene.control.ListView<String>
private javafx.scene.control.Button[]
private javafx.scene.control.Button
private javafx.scene.control.Button
private javafx.scene.control.Label
private javafx.scene.control.Button
private javafx.scene.control.Button
private javafx.scene.control.Label
private javafx.scene.control.ChoiceBox<String>
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the simulation attack log and displays to the armies.void
Creates a dialog box with custom buttons where the user can change which side to create an army to.void
Creates deep copies of the original armies and selects them as the current armies.void
displayArmy
(int armyNumber) Updates the information about an army in the chosen elements.void
editArmy
(int armyNumber) Goes to the edit page of an imported army.void
Edits the left army.void
Edits the right army.private void
importArmy
(int armyNumber) Helper method to import an army and display its information in the given label elements.void
Imports an army for the first army.void
Imports an army for the second army.void
initialize
(URL url, ResourceBundle resourceBundle) Run when the fxml file is first loaded.void
Run when clicking on reset armies.void
Run when clicking on the button reset and run.
-
Field Details
-
terrainChoiceBox
-
resetArmiesButton
private javafx.scene.control.Button resetArmiesButton -
resetAndBattleButton
private javafx.scene.control.Button resetAndBattleButton -
editArmyOneButton
private javafx.scene.control.Button editArmyOneButton -
editArmyTwoButton
private javafx.scene.control.Button editArmyTwoButton -
armyOneImportPath
private javafx.scene.control.Label armyOneImportPath -
armyOneName
private javafx.scene.control.Label armyOneName -
armyOneToString
private javafx.scene.control.Label armyOneToString -
armyOneUnitsListView
-
armyTwoUnitsListView
-
armyTwoImportPath
private javafx.scene.control.Label armyTwoImportPath -
armyTwoName
private javafx.scene.control.Label armyTwoName -
armyTwoToString
private javafx.scene.control.Label armyTwoToString -
armyImportPathLabels
private javafx.scene.control.Label[] armyImportPathLabels -
armyNameLabels
private javafx.scene.control.Label[] armyNameLabels -
armySummaryLabels
private javafx.scene.control.Label[] armySummaryLabels -
armyUnitListViews
-
editArmyButtons
private javafx.scene.control.Button[] editArmyButtons -
attackList
-
lastSimulation
private javafx.scene.control.Label lastSimulation -
score
private javafx.scene.control.Label score
-
-
Constructor Details
-
BattleController
public BattleController()
-
-
Method Details
-
importArmyOne
public void importArmyOne()Imports an army for the first army. Uses the system's file explorer to find the file. 0 selects the first army. -
importArmyTwo
public void importArmyTwo()Imports an army for the second army. Uses the system's file explorer to find the file. 1 selects the second army. -
importArmy
private void importArmy(int armyNumber) Helper method to import an army and display its information in the given label elements.- Parameters:
armyNumber
- int - the selected army to import. 0 for army one and 1 for army two
-
deepCopyArmiesAndCreateBattle
Creates deep copies of the original armies and selects them as the current armies. Creates a battle with those armies.- Throws:
IllegalArgumentException
- thrown if an army or battle is invalid.NullPointerException
- thrown if an army is a null object.
-
clearAttackListAndDisplayArmies
Clear the simulation attack log and displays to the armies.- Throws:
NullPointerException
- thrown if an army is a null object.
-
resetArmies
public void resetArmies()Run when clicking on reset armies. Deep copies the armies and creates a new battle. Also resets the labels. -
runSimulation
public void runSimulation()Run when clicking on the button reset and run. Creates deep copies of the armies and runs the simulation. Then it calls the methods in View to display that information. -
displayArmy
Updates the information about an army in the chosen elements. Uses both armyNumber and army to be able to display armies that have changed. For example after a battle.- Parameters:
armyNumber
- int - 0 or 1 depending on which elements to use to display an army.- Throws:
NullPointerException
- thrown if the army is null
-
editArmy
public void editArmy(int armyNumber) Goes to the edit page of an imported army.- Parameters:
armyNumber
- int - the specified army's number to edit
-
editArmyOne
public void editArmyOne()Edits the left army. Army one -
editArmyTwo
public void editArmyTwo()Edits the right army. Army two -
createArmy
public void createArmy()Creates a dialog box with custom buttons where the user can change which side to create an army to. From there it changes scene to edit a new army. -
initialize
Run when the fxml file is first loaded. Fills in the tables of information for the armies- Specified by:
initialize
in interfacejavafx.fxml.Initializable
- Parameters:
url
- URL - a Uniform Resource LoaderresourceBundle
- ResourceBundle
-