org.jogre.common
Class Table

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

public class Table
extends Observable
implements ITransmittableWithProps

Server side data object which holds information on various tables and their current users etc.

This class implements the ITransmittable and be transmitabled to a client. It also extends the Observable interface so that other class can listen to changes on the data.

Version:
Alpha 0.2.3
Author:
Bob Marks

Field Summary
static String NUM_OF_PLAYERS
           
 
Fields inherited from interface org.jogre.common.comm.ITransmittableWithProps
XML_ATT_PROPERTIES
 
Constructor Summary
Table(int tableNumber, String username, boolean isPublic, JogrePropertyHash properties)
          Create a table and 1 user (owner)
Table(XMLElement message)
          Create Table object from a String.
 
Method Summary
 void addPlayer(String playerName)
          Add a user to the table i.e.
 void addProperty(String key, String value)
          Add a property to the hash map.
 boolean containsPlayer(String user)
          Returns true if a specified user is at a table.
 XMLElement flatten()
          Flatten the table object.
 void gameOver()
          Game over.
 JogreModel getModel()
          Retrieve the model from the server (if its being used).
 int getNumOfPlayers()
          Return the number of players as specified by a client through a property.
 String getOwner()
          Get the owner of this table.
 PlayerList getPlayerList()
          Return a player list.
 JogrePropertyHash getProperties()
          Return the properties hash.
 String getProperty(String key)
          Return a property from a key.
 String getProperty(String key, String defaultValue)
          Return a property from a key.
 Date getStartTime()
          Return the time this table was created.
 int getTableNum()
          Get the number of this table.
 String getTimeFormatted()
          Return the time started as a String.
 boolean isGamePlaying()
          Return true if a game is in progress.
 boolean isPublic()
          Returns true if this is a public table.
 void nextPlayer()
          Sets the next player username.
 void nextPlayer(Player player)
          Sets the next player.
 void nextPlayer(String playerName)
          Sets the next player.
 void refreshObservers()
          Refresh observers - calls the setChanged() and notifyObservers () methods in the Observable class.
 void setModel(JogreModel model)
          Set the game data.
 void setPlayerList(PlayerList playerList)
           
 String toString()
          Return the String version of this table.
 
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_PLAYERS

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

Table

public Table(int tableNumber,
             String username,
             boolean isPublic,
             JogrePropertyHash properties)
Create a table and 1 user (owner)

Parameters:
tableNumber - The table number of the new table.
username - Username (owner).
isPublic - boolean to show if a table is public or private.

Table

public Table(XMLElement message)
      throws TransmissionException
Create Table object from a String.

Parameters:
message - XMLElement communication object.
Throws:
TransmissionException - Thrown if there is a problem in transmission.
NumberFormatException - Problem parsing an int.
Method Detail

addProperty

public void addProperty(String key,
                        String value)
Add a property to the hash map.

Specified by:
addProperty in interface ITransmittableWithProps
Parameters:
key - Key of the value to add.
value - Value of the property

getProperty

public String getProperty(String key,
                          String defaultValue)
Return a property from a key. If key does not exist, then return default value;

Parameters:
key -
Returns:

getProperty

public String getProperty(String key)
Return a property from a key.

Parameters:
key -
Returns:

addPlayer

public void addPlayer(String playerName)
Add a user to the table i.e. a user joins a table

Parameters:
playerName - Username of the player.

gameOver

public void gameOver()
Game over. Update all players that are already seated to be ready for press start again.


getTableNum

public int getTableNum()
Get the number of this table.

Returns:
table number as an integer.

getStartTime

public Date getStartTime()
Return the time this table was created.

Returns:
Time table was created.

getNumOfPlayers

public int getNumOfPlayers()
Return the number of players as specified by a client through a property.

Returns:
Minimum number of players

getPlayerList

public PlayerList getPlayerList()
Return a player list.

Returns:
PlayerList at this table.

setPlayerList

public void setPlayerList(PlayerList playerList)

containsPlayer

public boolean containsPlayer(String user)
Returns true if a specified user is at a table.

Parameters:
user - Username to check.
Returns:
True if specified is at table.

getOwner

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

Returns:
Username of owner.

isPublic

public boolean isPublic()
Returns true if this is a public table.

Returns:
True if table is public.

getModel

public JogreModel getModel()
Retrieve the model from the server (if its being used).

Returns:
Model (will be null if doesn't exist).

setModel

public void setModel(JogreModel model)
Set the game data.

Parameters:
model -

nextPlayer

public void nextPlayer(String playerName)
Sets the next player.


nextPlayer

public void nextPlayer(Player player)
Sets the next player.


nextPlayer

public void nextPlayer()
Sets the next player username.


flatten

public XMLElement flatten()
Flatten the table object. Also include the model of the current game if the modelStateIsAttached variable is set.

Specified by:
flatten in interface ITransmittable
Returns:
XML element version of object.

getTimeFormatted

public String getTimeFormatted()
Return the time started as a String.

Returns:

toString

public String toString()
Return the String version of this table.

See Also:
Object.toString()

isGamePlaying

public boolean isGamePlaying()
Return true if a game is in progress. This method loops through the various Player object in the PlayerList to see if any of them are in the PlayerStateGameStarted state.

Returns:
True if game is playing.

getProperties

public JogrePropertyHash getProperties()
Return the properties hash.

Specified by:
getProperties in interface ITransmittableWithProps
Returns:
See Also:
ITransmittableWithProps.getProperties()

refreshObservers

public void refreshObservers()
Refresh observers - calls the setChanged() and notifyObservers () methods in the Observable class.