org.jogre.common
Class PlayerList

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

public class PlayerList
extends Observable
implements ITransmittable

This class contains a list of Player object.s

Version:
Alpha 0.2.3
Author:
Bob Marks

Field Summary
static String NO_PLAYER
           
protected static int NUM_OF_HEADER_TOKENS
          Number of header tokens.
protected static int NUM_OF_TOKENS
          Number of tokens which a PlayerList flattens to.
 
Constructor Summary
PlayerList(String owner)
          Default constructor.
PlayerList(XMLElement message)
          Constructor which creates a Player object from the flatten () method of another Player object.
 
Method Summary
 void addPlayer(String playerName)
          Add a player to the table.
 boolean containsUser(String player)
          Return true if the list contains the player.
 XMLElement flatten()
          Flatten the String so that it can be transmitted.
 Player getCurrentPlayer()
          Return the currrent layer at a turned based table.
 String getCurrentPlayerName()
          Return the currrent layer at a turned based table.
 String[] getInGamePlayers()
          Convience method to return in-game players sorted by seat and in the form of Strings (just the players usernames)
 String getOwner()
          Return the owner of this table.
 Player getPlayer(int seatNum)
          Return a player from a seat number.
 Player getPlayer(String playerName)
          Return a player.
 Vector getPlayers()
          Return a vector of players which arn't sorted.
 Vector getPlayersSortedBySeat()
          Return a vector of all the players in this list which are sorted by seat number (used for the game logic).
 Vector getPlayersSortedBySeat(String state)
          Return a vector of all the players in this list which are currently actually playing a game.
 int getPlayerStateCount(String state)
          Returns the number of players in a particular state.
 boolean isSeatFree(int seatNum)
          Return true if a seat at a table is free.
 void nextPlayer()
          Makes the current player equal to the next player.
 void nextPlayer(Player player)
          Sets the next player
 void nextPlayer(String playerName)
          Sets the next player
 void refreshObservers()
          Notify observers.
 void removePlayer(String player)
          Remove a player.
 void resetCurrentPlayer()
          Sets the current player to the person with the smallest seat number.
 void setCurrentPlayer(String username)
          Set current player.
 int size()
          Return the number of users playing at a particular table.
 String toString()
           
 
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

NUM_OF_HEADER_TOKENS

protected static final int NUM_OF_HEADER_TOKENS
Number of header tokens.

See Also:
Constant Field Values

NUM_OF_TOKENS

protected static final int NUM_OF_TOKENS
Number of tokens which a PlayerList flattens to.

See Also:
Constant Field Values

NO_PLAYER

public static final String NO_PLAYER
See Also:
Constant Field Values
Constructor Detail

PlayerList

public PlayerList(String owner)
Default constructor.


PlayerList

public PlayerList(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

addPlayer

public void addPlayer(String playerName)
Add a player to the table.

Parameters:
playerName - Name of the player to add to table.

removePlayer

public void removePlayer(String player)
Remove a player.

Parameters:
player - Name of player to remove.

size

public int size()
Return the number of users playing at a particular table.

Returns:
Number of players.

containsUser

public boolean containsUser(String player)
Return true if the list contains the player.

Parameters:
player - Username of player
Returns:
True if player is on this list.

getOwner

public String getOwner()
Return the owner of this table.

Returns:
Username of owner of table.

getPlayer

public Player getPlayer(String playerName)
Return a player.

Parameters:
playerName - Username of player.
Returns:
Player object.

getPlayer

public Player getPlayer(int seatNum)
Return a player from a seat number. Returns null if a player isn't found.

Parameters:
seatNum - Seat number of a user.
Returns:
Player object.

getPlayers

public Vector getPlayers()
Return a vector of players which arn't sorted.

Returns:
Unsorted list of players.

nextPlayer

public void nextPlayer(String playerName)
Sets the next player

Parameters:
playerName - Next player

nextPlayer

public void nextPlayer(Player player)
Sets the next player

Parameters:
player - Next player

nextPlayer

public void nextPlayer()
Makes the current player equal to the next player.


setCurrentPlayer

public void setCurrentPlayer(String username)
Set current player.

Parameters:
username - Username of current player.

resetCurrentPlayer

public void resetCurrentPlayer()
Sets the current player to the person with the smallest seat number.


getCurrentPlayerName

public String getCurrentPlayerName()
Return the currrent layer at a turned based table.

Returns:
Current player in String form.

getCurrentPlayer

public Player getCurrentPlayer()
Return the currrent layer at a turned based table.

Returns:
Current player as a Player object.

getPlayersSortedBySeat

public Vector getPlayersSortedBySeat(String state)
Return a vector of all the players in this list which are currently actually playing a game.

Parameters:
state - State of the player e.g. game in state.
Returns:
List of players sorted by seat.

getInGamePlayers

public String[] getInGamePlayers()
Convience method to return in-game players sorted by seat and in the form of Strings (just the players usernames)

Returns:

getPlayersSortedBySeat

public Vector getPlayersSortedBySeat()
Return a vector of all the players in this list which are sorted by seat number (used for the game logic).

Returns:
List of players sorted by seat.

getPlayerStateCount

public int getPlayerStateCount(String state)
Returns the number of players in a particular state.

Parameters:
state -
Returns:
Count of the specified state.

isSeatFree

public boolean isSeatFree(int seatNum)
Return true if a seat at a table is free.

Parameters:
seatNum - Seat number to check.
Returns:
If seat is free, return true.

flatten

public XMLElement flatten()
Flatten the String so that it can be transmitted.

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()
See Also:
Object.toString()

refreshObservers

public void refreshObservers()
Notify observers.

See Also:
Observable.notifyObservers()