org.jogre.common
Class Player

java.lang.Object
  |
  +--org.jogre.common.Player
All Implemented Interfaces:
ITransmittable

public class Player
extends Object
implements ITransmittable

This class contains information about a player, which is a user who has joined a table and wishes to play a game. Each Table object contains a list of Player objects.

This class contains the username of the player, their seat number (which is set when they sit down) and the state of the player (PlayerState) which uses the state design pattern as state can be quite complex.

This class also implements the ITransmittable interface which means it can be transferred across a network using the flatten() method.

Version:
Alpha 0.1
Author:
Bob Marks

Field Summary
static int NOT_SEATED
          Constant to show that a player hasn't been seated.
static int NUM_OF_TOKENS
          Number of tokens which a Player flattens to.
protected  String playerName
          Username of the user.
protected  PlayerState playerState
          State of the player.
protected  int seatNum
          Seat number of the user e.g.
 
Constructor Summary
Player(String inString)
          Constructor which creates a Player object from the flatten () method of another Player object.
Player(String playerName, PlayerState playerState)
          Constructor requires both a player and a status as parameters and sets the seat number to NOT_SEATED.
 
Method Summary
 boolean canOfferDrawResign()
           
 boolean canSit(PlayerList players)
          Return true if a player can sit or not.
 boolean canStand(PlayerList players)
          Returns true if a player can stand.
 boolean canStart(PlayerList players)
          Returns true if a player can sit.
 String flatten()
          Transmittable String representation of this object.
 String getPlayerName()
          Return the username of this Player object.
 int getSeatNum()
          Return the seat number of this player.
 PlayerState getState()
          Returns the state of this player as a PlayerState object.
 String getStatusStr()
          Returns the status of this player as a String.
 void setSeatNum(int seatNum)
          Set the seat number of this player (set when a player sits down).
 void sit()
          Player sits down at a table.
 void stand()
          Player stands up from a table.
 void start()
          Player decides to start.
 String toString()
          String representation of this player.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NUM_OF_TOKENS

public static final int NUM_OF_TOKENS
Number of tokens which a Player flattens to.

NOT_SEATED

public static final int NOT_SEATED
Constant to show that a player hasn't been seated.

playerName

protected String playerName
Username of the user.

seatNum

protected int seatNum
Seat number of the user e.g. in chess, 0=White, 1=Black. NOT_SEATED (-1) indicates that the Player hasn't sat down yet.

playerState

protected PlayerState playerState
State of the player. The playerState can either be seated, viewing, ready etc. If a Player is in the viewing state for example this variable will be an instance of the PlayerStateViewing class (state design pattern).
Constructor Detail

Player

public Player(String playerName,
              PlayerState playerState)
Constructor requires both a player and a status as parameters and sets the seat number to NOT_SEATED.
Parameters:
playerName -  
playerState -  

Player

public Player(String inString)
       throws TransmissionException,
              NumberFormatException
Constructor which creates a Player object from the flatten () method of another Player object.
Parameters:
inString -  
Throws:
TransmissionException -  
NumberFormatException -  
Method Detail

sit

public void sit()
Player sits down at a table.

stand

public void stand()
Player stands up from a table.

start

public void start()
Player decides to start.

canSit

public boolean canSit(PlayerList players)
Return true if a player can sit or not.
Parameters:
players - List of all the player at a particular table.
Returns:
 

canStand

public boolean canStand(PlayerList players)
Returns true if a player can stand.
Parameters:
players - List of all the player at a particular table.
Returns:
 

canStart

public boolean canStart(PlayerList players)
Returns true if a player can sit.
Parameters:
players - List of all the player at a particular table.
Returns:
 

canOfferDrawResign

public boolean canOfferDrawResign()
Returns:
 

getPlayerName

public String getPlayerName()
Return the username of this Player object.
Returns:
Username.

setSeatNum

public void setSeatNum(int seatNum)
Set the seat number of this player (set when a player sits down).
Parameters:
seatNum - Integer >= 0 and < maximum number of seats.

getSeatNum

public int getSeatNum()
Return the seat number of this player.
Returns:
If greater than zero the player is seated, -1 if standing.

getStatusStr

public String getStatusStr()
Returns the status of this player as a String.
Returns:
 

flatten

public String flatten()
Transmittable String representation of this object.
Specified by:
flatten in interface ITransmittable
See Also:
ITransmittable.flatten()

toString

public String toString()
String representation of this player.
Overrides:
toString in class Object
See Also:
Object.toString()

getState

public PlayerState getState()
Returns the state of this player as a PlayerState object.
Returns: