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.1
Author:
Bob Marks

Field Summary
static String NUM_OF_PLAYERS
           
static String XML_NAME
          Header in XMLElement.
 
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 containsUser(String user)
          Returns true if a specified user is at a table.
 XMLElement flatten()
          Flatten this object without the model state attached (this is the default way of doing things).
 XMLElement flatten(boolean modelStateAttached)
          Flatten the table object.
 void gameOver()
          Game over.
 int getMaxNumOfPlayers()
          Return the maximum number of players as specified by a client through a property.
 int getMinNumOfPlayers()
          Return the minimum number of players as specified by a client through a property.
 JogreModel getModel()
          Retrieve the model from the server (if its being used).
 String getOwner()
          Get the owner of this table.
 PlayerList getPlayerList()
          Return a player list.
 JogrePropertyHash getProperties()
          Return the properties hash.
 int getRequiredNumOfPlayers()
          Return the maximum number of players as specified by a client through a property.
 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 isModelStateAttached()
          Return if the model state is attached or not.
 boolean isPublic()
          Returns true if this is a public table.
 void nextPlayer()
          Sets the next player username.
 void removePlayer(String player)
          Remove a player from the list.
 void setModel(JogreModel model)
          Set the game data.
 void setModelStateAttached(boolean value)
          Set true if the model state is to be attached or not.
 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

XML_NAME

public static final String XML_NAME
Header in XMLElement.

See Also:
Constant Field Values

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

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.

removePlayer

public void removePlayer(String player)
Remove a player from the list.

Parameters:
player - Username of the player.

gameOver

public void gameOver()
Game over.


getTableNum

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

Returns:
table number as an integer.

getMinNumOfPlayers

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

Returns:
Minimum number of players

getMaxNumOfPlayers

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

Returns:
Maximum number of players

getRequiredNumOfPlayers

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

Returns:
Required number of players

getPlayerList

public PlayerList getPlayerList()
Return a player list.

Returns:
PlayerList at this table.

containsUser

public boolean containsUser(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()
Sets the next player username.


setModelStateAttached

public void setModelStateAttached(boolean value)
Set true if the model state is to be attached or not.

Parameters:
value -

isModelStateAttached

public boolean isModelStateAttached()
Return if the model state is attached or not.

Returns:
True if the model state is attached.

flatten

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

Parameters:
modelStateAttached - Boolean to specify to include the model or not.
Returns:
XML element version of object.

getTimeFormatted

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

Returns:

flatten

public XMLElement flatten()
Flatten this object without the model state attached (this is the default way of doing things).

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()
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()