Record Class GameEvent.GameStateChanged
java.lang.Object
java.lang.Record
edu.uw.tcss.model.GameEvent.GameStateChanged
- Record Components:
oldState- the previous game statenewState- the new game statetimestamp- when the event was created (milliseconds since epoch)
- All Implemented Interfaces:
GameEvent
- Enclosing interface:
GameEvent
public static record GameEvent.GameStateChanged(GameControls.GameState oldState, GameControls.GameState newState, long timestamp)
extends Record
implements GameEvent
Event fired when the game state changes.
This occurs when the game transitions between NEW, RUNNING, PAUSED, and OVER states.
This event provides type-safe access to both the old and new game states. When fired, this event is associated with property name "GameStateChanged".
Usage Example:
game.addPropertyChangeListener(evt -> {
if (evt.getNewValue() instanceof GameEvent.GameStateChanged e) {
System.out.println("Game state: " + e.oldState() + " -> " + e.newState());
if (e.newState() == GameControls.GameState.OVER) {
showGameOverDialog();
}
}
});
- Version:
- Winter 2025
- Author:
- Charles Bryan
-
Nested Class Summary
Nested classes/interfaces inherited from interface GameEvent
GameEvent.CurrentPieceChanged, GameEvent.FrozenBlocksChanged, GameEvent.GameStateChanged, GameEvent.NextPieceChanged, GameEvent.RowsCleared -
Constructor Summary
ConstructorsConstructorDescriptionGameStateChanged(GameControls.GameState oldState, GameControls.GameState newState, long timestamp) Creates an instance of aGameStateChangedrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.newState()Returns the value of thenewStaterecord component.oldState()Returns the value of theoldStaterecord component.longReturns the value of thetimestamprecord component.final StringtoString()Returns a string representation of this record class.Methods inherited from interface GameEvent
getPropertyName
-
Constructor Details
-
GameStateChanged
public GameStateChanged(GameControls.GameState oldState, GameControls.GameState newState, long timestamp) Creates an instance of aGameStateChangedrecord class.
-
-
Method Details
-
toString
-
hashCode
-
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with thecomparemethod from their corresponding wrapper classes. -
oldState
-
newState
-
timestamp
-