org.jogre.common
Class Player

java.lang.Object
  extended byjava.util.Observable
      extended byorg.jogre.common.Player
All Implemented Interfaces:
ITransmittable

public class Player
extends Observable
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.2.1
Author:
Bob Marks

Field Summary
static int NOT_SEATED
          Constant to show that a player hasn't been seated.
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 playerName, PlayerState playerState)
          Constructor requires both a player and a status as parameters and sets the seat number to NOT_SEATED.
Player(XMLElement message)
          Constructor which creates a Player object from the flatten () method of another Player object.
 
Method Summary
 boolean canOfferDrawResign()
          REturn if it a player can offer a draw or resign a game.
 boolean canSit(Table table)
          Return true if a player can sit or not.
 boolean canStand(Table table)
          Returns true if a player can stand.
 boolean canStart(Table table)
          Returns true if a player can sit.
 XMLElement flatten()
          Transmittable String representation of this object (XML).
 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.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

NOT_SEATED

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

See Also:
Constant Field Values

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 - Name of player
playerState - State of the player

Player

public Player(XMLElement message)
Constructor which creates a Player object from the flatten () method of another Player object.

Parameters:
message - XML element version of object.
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(Table table)
Return true if a player can sit or not.

Parameters:
table - Link to table
Returns:
True if player can sit down.

canStand

public boolean canStand(Table table)
Returns true if a player can stand.

Parameters:
table - Link to table
Returns:
True if player can stand up.

canStart

public boolean canStart(Table table)
Returns true if a player can sit.

Parameters:
table - Link to table
Returns:
True if player can start.

canOfferDrawResign

public boolean canOfferDrawResign()
REturn if it a player can offer a draw or resign a game.

Returns:
True if player can offer draw / resign.

getPlayerName

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

Returns:
Username of player.

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:
Get the status of the player as a String.

flatten

public XMLElement flatten()
Transmittable String representation of this object (XML).

Specified by:
flatten in interface ITransmittable
Returns:
XML version of the state of an object which can be constructed again.
See Also:
ITransmittable.flatten()

toString

public String toString()
String representation of this player.

See Also:
Object.toString()

getState

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

Returns:
Return the state of the player.