Record Class GameEvent.GameStateChanged

java.lang.Object
java.lang.Record
edu.uw.tcss.model.GameEvent.GameStateChanged
Record Components:
oldState - the previous game state
newState - the new game state
timestamp - 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
  • Constructor Details

    • GameStateChanged

      public GameStateChanged(GameControls.GameState oldState, GameControls.GameState newState, long timestamp)
      Creates an instance of a GameStateChanged record class.
      Parameters:
      oldState - the value for the oldState record component
      newState - the value for the newState record component
      timestamp - the value for the timestamp record component
  • Method Details

    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object); primitive components are compared with the compare method from their corresponding wrapper classes.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • oldState

      public GameControls.GameState oldState()
      Returns the value of the oldState record component.
      Returns:
      the value of the oldState record component
    • newState

      public GameControls.GameState newState()
      Returns the value of the newState record component.
      Returns:
      the value of the newState record component
    • timestamp

      public long timestamp()
      Returns the value of the timestamp record component.
      Specified by:
      timestamp in interface GameEvent
      Returns:
      the value of the timestamp record component