Package model

Class GameState

java.lang.Object
model.GameState
All Implemented Interfaces:
Serializable

public class GameState extends Object implements Serializable
GameState class implementation for Double Trouble Kingdom game, contains the Players, playerNumbers, the roundState, and other fields and methods for managing the state of the Game.
See Also:
  • Field Details

    • deltaTime

      public static double deltaTime
      The deltaTime for animation drawing.
  • Constructor Details

    • GameState

      public GameState()
      Constructs a gamesState.
    • GameState

      public GameState(GameState gameState)
      Constructs a copy of the GameState.
      Parameters:
      gameState - the GameState to copy
    • GameState

      public GameState(String p1Name, String p2Name, Database database)
      Constructs a class containing the Players, roundState, and elapsedTimer.
      Parameters:
      p1Name - name of Player1
      p2Name - name of Player2
      database - DB reference
  • Method Details

    • getAnimBuffer

      public static ArrayList<Animator> getAnimBuffer()
      Returns the animation buffer.
      Returns:
      the animation buffer
    • loadBuildings

      public void loadBuildings(Map map)
      Loads the buildings from a map file after load.
      Parameters:
      map - the map file
    • getPlayers

      public ArrayList<Player> getPlayers()
      Returns the Players in an ArrayList.
      Returns:
      the Players in an ArrayList
    • getRoundState

      public RoundState getRoundState()
      Returns the roundState.
      Returns:
      the roundState
    • nextRoundState

      public void nextRoundState()
      Switches the current roundState to the next one. Switches Player after Training roundState phase.
    • isEnded

      public boolean isEnded()
      Checks if the game is ended.
      Returns:
      true if the game is ended
    • checkAlive

      public boolean checkAlive()
      Returns if the Game is ended.
      Returns:
      if the Game is ended
    • getWinner

      public Player getWinner()
      Returns the winner of the game.
      Returns:
      the winner of the game
    • decideStarter

      public void decideStarter()
      Determines the starting Player.
    • getCurrentPlayer

      public Player getCurrentPlayer()
      Returns the current Player.
      Returns:
      the current Player
    • setCurrentPlayer

      public void setCurrentPlayer(Player currentPlayer)
      Sets the current Player.
      Parameters:
      currentPlayer - the Player to set
    • startElapsedTimer

      public void startElapsedTimer()
      Starts the elapsedTimer.
    • stopElapsedTimer

      public void stopElapsedTimer()
      Stops the elapsedTimer.
    • restartElapsedTimer

      public void restartElapsedTimer()
      Restarts the elapsedTimer.
    • getEnemyCastle

      public Building getEnemyCastle(int playerNumber)
      Returns the enemy's Castle.
      Parameters:
      playerNumber - the Player's number
      Returns:
      the enemy's Castle
    • getEnemySoldiers

      public ArrayList<Soldier> getEnemySoldiers(int playerNumber)
      Returns the enemy's Soldiers.
      Parameters:
      playerNumber - the Player's number
      Returns:
      the enemy's Soldiers
    • setTargets

      public void setTargets()
      Sets the soldier's target.
    • getEnemyTowers

      public ArrayList<Tower> getEnemyTowers(int playerNumber)
      Returns the enemy's Towers.
      Parameters:
      playerNumber - the Player's number
      Returns:
      the enemy's Towers
    • getElapsedTime

      public int getElapsedTime()
      Returns elapsed time.
      Returns:
      elapsed time
    • setElapsedTime

      public void setElapsedTime(int elapsedTime)
      Sets the elapsed time.
      Parameters:
      elapsedTime - the elapsed time
    • calculatePaths

      public void calculatePaths()
      Calculates the soldier' path.
    • togglePathVisualization

      public void togglePathVisualization()
      Toggles if path visualization is enabled.
    • isPathVisualization

      public boolean isPathVisualization()
      Returns if path visualization is enabled.
      Returns:
      if path visualization is enabled