Package com.csse3200.game.services
Class GameState
java.lang.Object
com.csse3200.game.services.GameState
Represents the current state of the game whilst ensuring thread safety.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCallback interface to be implemented by classes interested in receiving notifications about state changes. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the state data.Retrieves the value corresponding to the input key from the current state data.Returns a copy of the current game state datavoidAdd or update the state data and trigger the state change callbacks.voidRegisters a state change listener.voidUnregisters a state change listener.
-
Constructor Details
-
GameState
public GameState()
-
-
Method Details
-
put
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
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
Returns a copy of the current game state data- Returns:
- The copy of current state data
-
registerStateChangeListener
Registers a state change listener.- Parameters:
listener- The listener to be registered.
-
unregisterStateChangeListener
Unregisters a state change listener.- Parameters:
listener- The listener to be unregistered.
-