java.lang.Object
edu.ntnu.idatt2001.carljgu.client.controllers.BattleController
All Implemented Interfaces:
javafx.fxml.Initializable

public class BattleController extends Object implements 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 Details

    • terrainChoiceBox

      private javafx.scene.control.ChoiceBox<String> 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

      private javafx.scene.control.ListView<Unit> armyOneUnitsListView
    • armyTwoUnitsListView

      private javafx.scene.control.ListView<Unit> 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

      private javafx.scene.control.ListView<Unit>[] armyUnitListViews
    • editArmyButtons

      private javafx.scene.control.Button[] editArmyButtons
    • attackList

      private javafx.scene.control.ListView<String> 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

      public void deepCopyArmiesAndCreateBattle() throws IllegalArgumentException, NullPointerException
      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

      public void clearAttackListAndDisplayArmies() throws NullPointerException
      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

      public void displayArmy(int armyNumber) throws NullPointerException
      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

      public void initialize(URL url, ResourceBundle resourceBundle)
      Run when the fxml file is first loaded. Fills in the tables of information for the armies
      Specified by:
      initialize in interface javafx.fxml.Initializable
      Parameters:
      url - URL - a Uniform Resource Loader
      resourceBundle - ResourceBundle