Class GameState

java.lang.Object
com.csse3200.game.services.GameState

public class GameState extends Object
Represents the current state of the game whilst ensuring thread safety.
  • Constructor Details

    • GameState

      public GameState()
  • Method Details

    • put

      public void put(String key, Object newValue)
      Add or update the state data and trigger the state change callbacks.
      Parameters:
      key - The key of the state to be set.
      newValue - The new value to be set.
    • get

      public Object get(String key)
      Retrieves the value corresponding to the input key from the current state data.
      Parameters:
      key - The key of the data to be fetched.
      Returns:
      The data corresponding to the provided key.
    • clear

      public void clear()
      Clears the state data.
    • getStateData

      public Map<String,Object> getStateData()
      Returns a copy of the current game state data
      Returns:
      The copy of current state data
    • registerStateChangeListener

      public void registerStateChangeListener(GameState.StateChangeListener listener)
      Registers a state change listener.
      Parameters:
      listener - The listener to be registered.
    • unregisterStateChangeListener

      public void unregisterStateChangeListener(GameState.StateChangeListener listener)
      Unregisters a state change listener.
      Parameters:
      listener - The listener to be unregistered.