public class ObservableGame
extends java.lang.Object
Observer management and event propagation in a game instance.
This class provides methods to register observers and propagate 3 types of
events
SendCardsEvent, RoundUpdateEvent,
RoundConclusionEvent and GameEndEvent -,
using 2 different communication forms. The former is sent to a single user
and the latter two are broadcast to all observers. No enable this 2 forms
observers are associated with a nick that is used as an identifier
(i.e. is assumed to be unique in a game).
This class is a participant in the Observable design pattern.
jpleal@fc.up.pt| Constructor and Description |
|---|
ObservableGame() |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addObserver(java.lang.String nick,
GameObserver observer)
Add a
GameObserver that will receive a
notification when an event is broadcast. |
protected void |
broadcast(GameEndEvent event)
Broadcast given
GameEndEvent to all registered observers. |
protected void |
broadcast(RoundConclusionEvent event)
Broadcast given
RoundConclusionEvent to all registered observers. |
protected void |
broadcast(RoundUpdateEvent event)
Broadcast given
RoundUpdateEvent to all registered observers. |
protected void |
notify(java.lang.String nick,
SendCardsEvent event)
Notify a single observer with a send
SendCardsEvent. |
protected void addObserver(java.lang.String nick,
GameObserver observer)
GameObserver that will receive a
notification when an event is broadcast.nick - identifying observerobserver - that will receive the eventprotected void notify(java.lang.String nick,
SendCardsEvent event)
SendCardsEvent.
Only previously registered observers will receive these notifications.
Events to non-registered observers will be silently ignored.nick - identifying observerevent - to sendprotected void broadcast(RoundUpdateEvent event)
RoundUpdateEvent to all registered observers.event - to broadcastprotected void broadcast(RoundConclusionEvent event)
RoundConclusionEvent to all registered observers.event - to broadcastprotected void broadcast(GameEndEvent event)
GameEndEvent to all registered observers.event - to broadcast