Package rea.gaming
Class GameEventSource
java.lang.Object
rea.gaming.GameEventSource
- Direct Known Subclasses:
GameInstance
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 Summary
FieldsModifier and TypeFieldDescription(package private) final EventBroadcast
<GameChangedEvent> The listeners registered to receive game changed events.(package private) final EventMulticast
<InventoryUpdateEvent> The listeners registered to receive inventory update events.(package private) final EventMulticast
<MessageUpdateEvent> The listeners registered to receive message update events.The set of players in this game.(package private) final EventMulticast
<SceneUpdateEvent> The listeners registered to receive scene update events. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addGameChangedListener
(UpdateListener<GameChangedEvent> listener) Add a listener forGameChangedEvent
.void
addInventoryUpdateListener
(Player player, UpdateListener<InventoryUpdateEvent> listener) Add a listener forInventoryUpdateEvent
.void
addMessageUpdateListener
(Player player, UpdateListener<MessageUpdateEvent> listener) Add a listener forMessageUpdateEvent
.void
addSceneUpdateListener
(Player player, UpdateListener<SceneUpdateEvent> listener) Add a listener forSceneUpdateEvent
.(package private) void
broadcastGameChanged
(GameInstance gameInstance) Broadcast major game changes to all registered listeners.(package private) void
multicastMessageUpdate
(Place place, Character character, String message) Multicasts players in the given place with a message.(package private) void
multicastSceneUpdate
(Place place) Multicast players in the given scene with the current state of that scene.(package private) void
unicastInventoryUpdate
(Character character) Sends aInventoryUpdateEvent
to the character given as argument.(package private) void
unicastMessageUpdate
(Character character, String message) Sends aMessageUpdateEvent
to the character
-
Field Details
-
gameChanged
The listeners registered to receive game changed events. -
inventoryUpdate
The listeners registered to receive inventory update events. -
messageUpdate
The listeners registered to receive message update events. -
sceneUpdate
The listeners registered to receive scene update events. -
players
The set of players in this game.
-
-
Constructor Details
-
GameEventSource
protected GameEventSource()Create an instance of this class. No particular initializations are performed.
-
-
Method Details
-
addGameChangedListener
Add a listener forGameChangedEvent
. 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 forInventoryUpdateEvent
. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.- Parameters:
player
- adding the listenerlistener
- 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 forMessageUpdateEvent
. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.- Parameters:
player
- adding the listenerlistener
- 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 forSceneUpdateEvent
. Only identified players can add these listeners. The player will be used as key to this listener in multicasting.- Parameters:
player
- adding the listenerlistener
- of scene update events- Throws:
ReaException
- if player not in this game
-
broadcastGameChanged
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
Multicast players in the given scene with the current state of that scene.- Parameters:
place
- to notify
-
multicastMessageUpdate
Multicasts players in the given place with a message.- Parameters:
place
- with players to multicastcharacter
- that sends the messagemessage
- to multicast
-
unicastMessageUpdate
Sends aMessageUpdateEvent
to the character- Parameters:
character
- that receive the messagemessage
- to be sent
-
unicastInventoryUpdate
Sends aInventoryUpdateEvent
to the character given as argument.- Parameters:
character
- to be updated
-