common
Class Table

java.lang.Object
  extended by common.Table
Direct Known Subclasses:
BlackjackTable, HeartsTable, SpadesTable

public abstract class Table
extends java.lang.Object


Field Summary
protected  Deck deck
           
static java.lang.String DRAW
          Indicates that the player drew.
static int FULL
          Returned by getNextAvailableSlot() when the table is full or the game has already started.
protected  java.util.Vector<Hand> hands
           
static java.lang.String LOSS
          Indicates that the player lost.
static int NUMBER_OF_GAMES
          The number of games the framework currently supports.
protected  int numPlayers
           
protected  java.util.Vector<ServerThread> players
           
protected  boolean started
           
protected  java.lang.String type
           
static java.lang.String WIN
          Indicates that the player won.
 
Constructor Summary
Table()
          Default constructor.
Table(int numPlayers, java.lang.String type)
          Creates a new table with the number of players that are needed at the table to start the game and the type of Table this is.
 
Method Summary
 void addPlayer(ServerThread s)
          Adds an additional player to the table.
abstract  void beginGame()
          Called when the table is FULL.
 int getNextAvailableSlot()
          Returns FULL if the Table is full, otherwise returns the next available slot.
 java.lang.String getType()
          Returns a String representation of the type of game being played at this table.
abstract  void handleMessage(java.lang.Object o, int fromClientNum)
          Receive messages from ServerThread (from a Client), checks to see if a move causes a win, loss, or draw, then if not, passes that move to the other players.
 void initialize(int numPlayers, java.lang.String type)
          Initializes a new table with the number of players that are needed at the table to start the game and the type of Table this is.
 void removePlayer(int playerNum)
          Removes the specified player from the table.
 void removePlayer(ServerThread player)
          Removes the specified player from the table.
 void sendResults(java.lang.String[] results)
          Sends the given results to the players and updates player records.
 void sendTo(java.lang.Object msg, int clientToSendTo)
          Sends a NetworkObject to the specified client in the ServerThread array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NUMBER_OF_GAMES

public static final int NUMBER_OF_GAMES
The number of games the framework currently supports. Computed dynamically by checking how many public constants there are in common.Game.java.


WIN

public static final java.lang.String WIN
Indicates that the player won. Used with updateRecords(String, int).

See Also:
Constant Field Values

DRAW

public static final java.lang.String DRAW
Indicates that the player drew. Used with updateRecords(String, int).

See Also:
Constant Field Values

LOSS

public static final java.lang.String LOSS
Indicates that the player lost. Used with updateRecords(String, int).

See Also:
Constant Field Values

FULL

public static final int FULL
Returned by getNextAvailableSlot() when the table is full or the game has already started.

See Also:
Constant Field Values

players

protected java.util.Vector<ServerThread> players

hands

protected java.util.Vector<Hand> hands

numPlayers

protected int numPlayers

type

protected java.lang.String type

deck

protected Deck deck

started

protected boolean started
Constructor Detail

Table

public Table()
Default constructor. Used in conjunction with initialize(int, String).


Table

public Table(int numPlayers,
             java.lang.String type)
Creates a new table with the number of players that are needed at the table to start the game and the type of Table this is.

Parameters:
numPlayers - int number of players that are needed at the table to start the game.
type - String of Table this is.
Method Detail

initialize

public void initialize(int numPlayers,
                       java.lang.String type)
Initializes a new table with the number of players that are needed at the table to start the game and the type of Table this is.

Parameters:
numPlayers - int number of players that are needed at the table to start the game.
type - String of Table this is.

handleMessage

public abstract void handleMessage(java.lang.Object o,
                                   int fromClientNum)
Receive messages from ServerThread (from a Client), checks to see if a move causes a win, loss, or draw, then if not, passes that move to the other players. If it is a win, loss, or draw, MUST call sendResults(String[]) where String[] contains the results of the players as defined in Player.

Parameters:
o - Object received from the player.
fromClientNum - int the player number that sent this message.

beginGame

public abstract void beginGame()
Called when the table is FULL. Creates a Deck, deals a Hand to each player at the Table, and storesvthe remains of the Deck (if any) as a global variable. When each hand is dealt, it stores each Hand in an array.


sendResults

public void sendResults(java.lang.String[] results)
Sends the given results to the players and updates player records. Must be called at the end of each game.

Parameters:
results - String[] that need to be sent to each player.

getNextAvailableSlot

public int getNextAvailableSlot()
Returns FULL if the Table is full, otherwise returns the next available slot. Also returns FULL if the game has already started. at the table.

Returns:
int

addPlayer

public void addPlayer(ServerThread s)
Adds an additional player to the table. Once the amount of players is equal to the amount of players needed at that table to start the game, this method will call beginGame().

Parameters:
s - ServerThread Associated with the player that just joined the Table.

sendTo

public void sendTo(java.lang.Object msg,
                   int clientToSendTo)
Sends a NetworkObject to the specified client in the ServerThread array.

Parameters:
msg - Object to send to the player.
clientToSendTo - int the player number that this message is being sent to.

removePlayer

public void removePlayer(ServerThread player)
Removes the specified player from the table. Used when player disconnects or leaves this Table. If the game has already started, updates that player's records to reflect a forfeit. If there is only one player left at the table, they win by default. Also lets the client know who's sitting at the table.

Parameters:
player - ServerThread the player that left the table.

removePlayer

public void removePlayer(int playerNum)
Removes the specified player from the table. Used when player disconnects or leaves this Table. If the game has already started, updates that player's records to reflect a forfeit.

Parameters:
playerNum - int of the player that left the table.

getType

public java.lang.String getType()
Returns a String representation of the type of game being played at this table. These values can be found in the Game class.

Returns:
String