|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.util.Observable | +--org.jogre.common.JogreModel
Abstract class which holds the state/model of a particular game when extended. This class extends the Observable class so that JogreComponent classes can update themselfs depending on changes made in this classes.
For a very simple example, to create the model for a game of tic-tac-toe a class TicTacToeModel should extend this class and add a 3x3 two dimensional int array i.e.
int [][] = {{0, 0, 0}, {0, 0, 0}, {0, 0, 0}}.
A model can also store itself on a JogreServer. This is because this class implements the IJogreModel interface so if state is to be stored this method must be overewritten. The length () method must also be overwritten as the state is transferred along with a Table. To set the state of a JogreModel the setState (String inString) method must be overwritten. The constructor wasn't used (like the constructor of Comm objects) as this reference must be kept.
Field Summary | |
protected int |
gameType
Game type from IJogreModel e.g. |
static String |
JOGRE_MODEL
Header token used in ITransmittable.flatten() method. |
Fields inherited from interface org.jogre.client.IJogreModel |
GAME_TYPE_REAL_TIME, GAME_TYPE_TURN_BASED |
Constructor Summary | |
protected |
JogreModel()
Blank constructor which can be called by a sub class. |
|
JogreModel(int gameType)
Create a new jogre model which sets the game type, client connection thread and the table number. |
Method Summary | |
String |
flatten()
Returns the state/snapshot of a particular game. |
int |
length()
Return the number of tokens that this class creates when flattened. |
void |
refreshObservers()
Refresh observers - calls the setChanged() and notifyObservers () methods. |
void |
setState(String inString)
Set the state of the model (set values of the model equal to the values of this model by copying its values. |
abstract void |
start()
Reset method which is called every time a new game is created. |
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, toString, wait, wait, wait |
Field Detail |
public static final String JOGRE_MODEL
protected int gameType
Constructor Detail |
protected JogreModel()
public JogreModel(int gameType)
gameType
- Method Detail |
public abstract void start()
public void refreshObservers()
public void setState(String inString) throws TransmissionException
Set the state of the model (set values of the model equal to the values of this model by copying its values. The inString is created from the flatten () method of JogreModel. The implementation of this method in the subclass should call the refreshObservers() method so that the screen gets updated correctly.
Note: This is a marker method (not abstract) and only needs to be implemented if a games stores its state on the server Table object.
inString
- String created from flatten () method of this object.TransmissionException
- public int length()
Return the number of tokens that this class creates when flattened. If a game doesn't hold state then this method simply returns -1.
Note: This is a marker method (not abstract) and only needs to be implemented if a games stores its state on the server Table object.
public String flatten()
Returns the state/snapshot of a particular game.
Note: This is a marker method (not abstract) and only needs to be implemented if a games stores its state on the server Table object.
flatten
in interface ITransmittable
ITransmittable.flatten()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |