|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--au.com.solidsoftware.multimahjong.mms.GamesList
GamesList stores and manages the list of games currently being played on the MultiMahjongServer. GamesList has two arrays for representing games:
RemoteReferee.
MiniGame.
Registrar when the list of
games is required. It is a much smaller representation than the main array,
and so it is quicker to transfer over TCP/IP.
GamesList creates a new RemoteReferee and stores it in the main
array every time a new game is requested by the Registrar.
GamesList must also keep track of the MMCs that require updated information
whenever a new game or player is added to the list. It keeps a list of
GamesObservers in a HashSet and notifies them
whenever a change is made. GamesObservers are added whenever an
initial request is made for the entire list of games (when a user on an MMC
wishes to join a game).
MiniGame,
Registrar,
RemoteReferee,
GamesObserver,
HashSet| Field Summary | |
private RemoteReferee[] |
mainList
The main array of games on the MMS. |
private MiniGame[] |
miniList
The mini array of games on the MMS. |
private int |
numberOfGames
The number of games in both the mainList and
miniList |
private java.util.HashSet |
observerList
The list of GamesObservers waiting for updates |
| Constructor Summary | |
GamesList()
|
|
| Method Summary | |
int |
addPlayer(java.lang.String name,
int iconID,
int gameID,
ObserverIntf gamesObserver)
Adds a new player to the specified RemoteReferee. |
int |
createNewGame(java.lang.String name,
int limit,
int iconID,
ObserverIntf playersObserver)
Creates a new RemoteReferee and adds it to the
mainList. |
MiniGame[] |
getGamesList(ObserverIntf gamesObserver)
Returns the miniList of games and in the process, adds a new
GamesObserver to the observerList. |
int |
getNumberOfGames()
Just gets the number of games. |
void |
removeGame(int gameID)
Removes the specified game from mainList and
miniList. |
Referee |
startGame(int gameID)
Calls the startGame method in the specified
RemoteReferee. |
Referee |
waitForStart(int gameID)
Calls the waitForStart method in the specified
RemoteReferee. |
| Methods inherited from class java.lang.Object |
|
| Field Detail |
private RemoteReferee[] mainList
private MiniGame[] miniList
mainList used for transferring over TCP/IP.private java.util.HashSet observerList
GamesObservers waiting for updatesprivate int numberOfGames
mainList and
miniList| Constructor Detail |
public GamesList()
| Method Detail |
public int getNumberOfGames()
public int createNewGame(java.lang.String name,
int limit,
int iconID,
ObserverIntf playersObserver)
throws java.rmi.RemoteException
RemoteReferee and adds it to the
mainList. Firstly, this method checks to see whether the
mainList is full. If it's not, then the method proceeds to
create a new RemoteReferee and a corresponding
MiniGame and adds them to their respective lists. Finally,
the method notifies all GamesObservers that a new game has
been created.name - the name of the player creating the gamelimit - the score limit of the new gameiconID - the chosen icon of the player creating the gameplayersObserver - the observer to notify when players are addedLIST_FULL if no more games can be
createdmainList,
miniList,
RemoteReferee,
MiniGame,
GamesObserver,
PlayersObserver
public int addPlayer(java.lang.String name,
int iconID,
int gameID,
ObserverIntf gamesObserver)
throws java.rmi.RemoteException
RemoteReferee. Firstly,
this method checks to see whether the game has started. If it hasn't,
then the method calls the addPlayer method in the
ServerGame. It also removes the GamesObserver
that this user had from the list, because the user does not need to know
about game updates anymore. Finally, the method notifies all remaining
GamesObservers that a new player has been added to this
game.name - the name of the player being addediconID - the chosen icon of the player being addedgameID - the game that the player is being added togamesObserver - the observer that this user was using to get
updates throughLIST_FULL if no more players can be
addedmainList,
RemoteReferee,
RemoteReferee#addPlayer(Observer, String, int),
GamesObserverpublic MiniGame[] getGamesList(ObserverIntf gamesObserver)
miniList of games and in the process, adds a new
GamesObserver to the observerList. This method
is called thorugh the Registrar when a user wishing to join
a game wants to get the list of games currently needing players.gamesObserver - the observer that the user will receive updates
throughminiList of gamesminiList,
observerList,
GamesObserver,
Registrar
public Referee startGame(int gameID)
throws java.rmi.RemoteException
startGame method in the specified
RemoteReferee. Firstly, this
method notifies all GamesObservers that there are no more
spaces needed to be filled in this game. Then it just calls and returns
whatever value the startGame method returns in the
RemoteReferee.gameID - the game that is being startedRemoteReferee.startGame returnsRemoteReferee,
RemoteReferee.startGame(),
GamesObserver
public Referee waitForStart(int gameID)
throws java.rmi.RemoteException
waitForStart method in the specified
RemoteReferee.gameID - the game that is waiting to be startedRemoteReferee.waitForStart
returnsRemoteReferee,
RemoteReferee.waitForStart()
public void removeGame(int gameID)
throws java.rmi.RemoteException
mainList and
miniList.gameID - the game to be removedmainList,
miniList
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||