public class Lobby extends Object implements Game, GameChangeListener, Serializable
Player's characters. There is a single
Lobby instance for each game app.
While in the lobby all players are on the same channel, which is used for
chatting. Once moved into another game, players are removed from the
lobby channel.
| Modifier and Type | Field and Description |
|---|---|
static String |
IDENTIFIER
The identifier for the lobby
|
NAME_PREFIX| Modifier and Type | Method and Description |
|---|---|
void |
gameAdded(Collection<String> added)
Notifies the listener that some games were added to the app.
|
void |
gameRemoved(Collection<String> removed)
Notifies the listener that some games were removed from the app.
|
static Lobby |
getInstance(GameChangeManager gcm)
Provides access to the single instance of
Lobby. |
String |
getName()
Returns the name of the lobby.
|
MessageHandler |
join(Player player)
Joins a player to the lobby.
|
void |
leave(Player player)
Removes the player from the lobby.
|
void |
membershipChanged(Collection<GameMembershipDetail> details)
Called when it's time to send out membership change messages.
|
int |
numPlayers()
Returns the number of players currently in the lobby.
|
String |
toString() |
public static final String IDENTIFIER
public static Lobby getInstance(GameChangeManager gcm)
Lobby. If the
lobby hasn't already been created, then a new instance is
created and added as a registered ManagedObject. If the
lobby already exists then nothing new is created.
This method implements the pattern described in the programmer's notes document, so that it's safe against multiple simultaneous accesses when the lobby doesn't already exist. In practice, this isn't actually a concern in this app, because this method is never called by more than once party. Still, it's good defensive programming to protect against future models that may change our current access assumptions.
gcm - the manager we'll notify when lobby membership
counts changeLobbypublic MessageHandler join(Player player)
public void leave(Player player)
public String getName()
IDENTIFIER.public int numPlayers()
numPlayers in interface Gamepublic void gameAdded(Collection<String> added)
gameAdded in interface GameChangeListenergames - the games that were addedpublic void gameRemoved(Collection<String> removed)
gameRemoved in interface GameChangeListenergames - the games that were removedpublic void membershipChanged(Collection<GameMembershipDetail> details)
membershipChanged in interface GameChangeListenerdetails - the membership detailsCopyright © 2013. All Rights Reserved.