Package rea.gaming

Class GameEventSource

java.lang.Object
rea.gaming.GameEventSource
Direct Known Subclasses:
GameInstance

public class GameEventSource extends Object
Source of game related events. This class will be extended by GameInstance, to which it provides methods for adding listeners and methods for broadcasting, multicasting or unicasting events. This class delegates on methods of EventBroadcast and EventMulticast instances.
Author:
José Paulo Leal jpleal@fc.up.pt
See Also:
  • Field Details

  • Constructor Details

    • GameEventSource

      protected GameEventSource()
      Create an instance of this class. No particular initializations are performed.
  • Method Details

    • addGameChangedListener

      public void addGameChangedListener(UpdateListener<GameChangedEvent> listener)
      Add a listener for GameChangedEvent. These events will be broadcast to all registered listeners.
      Parameters:
      listener - of game changed events.
    • addInventoryUpdateListener

      public void addInventoryUpdateListener(Player player, UpdateListener<InventoryUpdateEvent> listener) throws ReaException
      Add a listener for InventoryUpdateEvent. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.
      Parameters:
      player - adding the listener
      listener - of inventory update events
      Throws:
      ReaException - if player not in this game
    • addMessageUpdateListener

      public void addMessageUpdateListener(Player player, UpdateListener<MessageUpdateEvent> listener) throws ReaException
      Add a listener for MessageUpdateEvent. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.
      Parameters:
      player - adding the listener
      listener - of message update events
      Throws:
      ReaException - if player not in this game
    • addSceneUpdateListener

      public void addSceneUpdateListener(Player player, UpdateListener<SceneUpdateEvent> listener) throws ReaException
      Add a listener for SceneUpdateEvent. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.
      Parameters:
      player - adding the listener
      listener - of scene update events
      Throws:
      ReaException - if player not in this game
    • broadcastGameChanged

      void broadcastGameChanged(GameInstance gameInstance)
      Broadcast major game changes to all registered listeners. It is typically called when players are added to a game, or when the game starts or ends. The argument is the changed game instance itself, passed as argument by the calling method from a class extension (e.g. broadcastGameChanged(this)).
      Parameters:
      gameInstance - changed
    • multicastSceneUpdate

      void multicastSceneUpdate(Place place)
      Multicast players in the given scene with the current state of that scene.
      Parameters:
      place - to notify
    • multicastMessageUpdate

      void multicastMessageUpdate(Place place, Character character, String message)
      Multicasts players in the given place with a message.
      Parameters:
      place - with players to multicast
      character - that sends the message
      message - to multicast
    • unicastMessageUpdate

      void unicastMessageUpdate(Character character, String message)
      Sends a MessageUpdateEvent to the character
      Parameters:
      character - that receive the message
      message - to be sent
    • unicastInventoryUpdate

      void unicastInventoryUpdate(Character character)
      Sends a InventoryUpdateEvent to the character given as argument.
      Parameters:
      character - to be updated