Class GamePool

java.lang.Object
  extended byGamePool

class GamePool
extends java.lang.Object

The GamePool class contains a list (or pool) of Game objects. This pool of games are all of the Game objects that the Liars Dice Server is currently managing. When a new player wants to join a game, the getGame method is called. The getGame method searches through the pool of games for a game that has not been started and has less than 4 players that have joined it. The new player is added to the first game in the list that meets this criteria. If there are no games available for the new player to join, a new Game will be created, the player will be added to it and the new Game will be appended to the game pool. The removeGame method removes a game from the game pool. The removeGame method should be called when all players have left the game or when a game is ruined because a player left the game after it was started.

Version:
1.0, May 2004.
Author:
David Green

Field Summary
private  java.util.ArrayList pool
          A list of all the Game objects being managed by the Liars Dice Server
 
Constructor Summary
(package private) GamePool()
           
 
Method Summary
 Game getGame(int playerID, java.lang.String playerName)
          The getGame method will add the player specified by playerID and playerName to the first available game in the game pool.
 void removeGame(Game game)
          The removeGame method removes the specified game from the game pool.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

pool

private java.util.ArrayList pool
A list of all the Game objects being managed by the Liars Dice Server

Constructor Detail

GamePool

GamePool()
Method Detail

getGame

public Game getGame(int playerID,
                    java.lang.String playerName)
The getGame method will add the player specified by playerID and playerName to the first available game in the game pool. If no games in the game pool are available, a new game will be created, the player will be added to it and the game will be put in the pool. A game is considered available if it has not been started and it has less than four players sitting at the game. The game that the player is added to is returned to the caller of getGame.
 PRE:  playerID and playerName are assigned.
 POST: The specified player is added to the first available game or is added to a new game.
       The game the player is added to is then returned
 

Parameters:
playerID - a unique id that identifies the player to add to a Game.
playerName - the name of the player to add to the game.

removeGame

public void removeGame(Game game)
The removeGame method removes the specified game from the game pool.
 PRE:  game is ruined or game has no players that have joined it.
 POST: The game specified is removed from the pool.
 

Parameters:
game - the Game object to remove from the game pool.