|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.jogre.client.JogreController
Adapter game controller class which creates empty methods for the MouseListener, MouseMotionListener and KeyListener event interfaces. This class also contains a link to the JogreModel, a connection thread to the server and also a JogreComponent where the mouse movements/key presses are taking place on.
To use this controller a class must extend it e.g. ChessController and
then override one of its event methods, update the correct model and send
communication to other users. To use the controller on a JogreComponent
a JogreComponent calls its public void setController (JogreController
controller)
method.
Any of the following methods can be overwritten to do something:
This class also contains a link to the ClientConnectionThread. This allows access to the UserList and TableList object which allow access to what is happening on the server. This class also provides various useful methods such as returning the table number, current player, current player's seat number, this players seat number, etc.
Since Alpha 0.2, the controller contains convience methods for sending and receving properties and XML objects easily and quickly to other players at a game using the following send methods:
All of these methods send something to the server. If a send method is used then its corresponding adapter receive method must also be fillin. e.g. if a method calls:
sendProperty ("move", 5, 5");
then the following recieve method must be filled in to do as the controllers for the other players will receive this property.
recieveProperty (String key, int x, int y) { ...
Note: Each sub class of JogreController most implement the abstract start() method. This is used for things like resetting the model / controller timers etc.
Field Summary | |
protected TableConnectionThread |
conn
Link to the client's connection thread. |
protected JogreComponent |
JogreComponent
Link to the JogreComponent this is controlling . |
protected JogreModel |
model
Link to the game model. |
protected int |
tableNum
Table number which this controller is controlling. |
Constructor Summary | |
JogreController(JogreModel model,
JogreComponent JogreComponent)
Default constructor class which doesn't set up the network connection. |
Method Summary | |
String |
getCurrentPlayer()
Return the current player. |
int |
getCurrentPlayerSeatNum()
Return the player num (between 0 and the number of players). |
String |
getPlayer(int seatNum)
Return the player name from a seat num. |
int |
getSeatNum()
Return the seat number of a user. |
int |
getSeatNum(String player)
Return the seat number of a specified player. |
Table |
getTable()
Convience method for returning a table. |
int |
getTableNum()
Return the table number. |
boolean |
isGamePlaying()
Return true/false if the game is started or not. |
boolean |
isThisPlayersTurn()
Return new if it is this players turn. |
void |
keyPressed(KeyEvent e)
Invoked when a key has been pressed. |
void |
keyReleased(KeyEvent e)
Invoked when a key has been released. |
void |
keyTyped(KeyEvent e)
Invoked when a key has been typed. |
void |
mouseClicked(MouseEvent e)
Invoked when the mouse has been clicked on a JogreComponent. |
void |
mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a JogreComponent and then dragged. |
void |
mouseEntered(MouseEvent e)
Invoked when the mouse enters a JogreJogreComponent. |
void |
mouseExited(MouseEvent e)
Invoked when the mouse exits a JogreComponent. |
void |
mouseMoved(MouseEvent e)
Invoked when the mouse button has been moved on a JogreComponent (with no buttons no down). |
void |
mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a JogreComponent. |
void |
mouseReleased(MouseEvent e)
Invoked when a mouse button has been released on a JogreComponent. |
void |
nextPlayer()
Method which tells the server that it is next players turn. |
void |
receiveObject(XMLElement message)
Recieve object as XML from a client or server (use this when more advanced data is required from the server or a client). |
void |
receiveProperty(String key,
int value)
Recieve property as a String key and integer value. |
void |
receiveProperty(String key,
int x,
int y)
Recieve property from another client as a co-ordinate (x and y integer). |
void |
receiveProperty(String key,
String value)
Adapter method for receiving property as a key and value from another client. |
void |
sendObject(ITransmittable object)
Send a more complex object (any object which implements the ITransmittable interface). |
void |
sendObject(XMLElement message)
Send a more complex object (any object which implements the ITransmittable interface). |
void |
sendProperty(String key,
int value)
Send a single integer property. |
void |
sendProperty(String key,
int x,
int y)
Send a co-ordinate property (x and y integer values). |
void |
sendProperty(String key,
String value)
Send a normal String valued property. |
void |
setConnection(TableConnectionThread conn)
Set up a network connection for this controller. |
abstract void |
start()
Reset method which is called every time a new game is created. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected JogreModel model
protected JogreComponent JogreComponent
protected TableConnectionThread conn
protected int tableNum
Constructor Detail |
public JogreController(JogreModel model, JogreComponent JogreComponent)
model
- Model which the controller can update depending on
what the user input is.JogreComponent
- The JogreComponent which the controller is
listening on.Method Detail |
public abstract void start()
public void setConnection(TableConnectionThread conn)
conn
- Link to the TableConnectionThread.public String getCurrentPlayer()
public int getCurrentPlayerSeatNum()
public int getTableNum()
public Table getTable()
public int getSeatNum()
public String getPlayer(int seatNum)
seatNum
- Seat number of the user.
public int getSeatNum(String player)
player
- Name of the player.
public boolean isGamePlaying()
public void sendProperty(String key, String value)
key
- value
- public void sendObject(ITransmittable object)
object
- A more complex piece of data encoded in XML.public void sendObject(XMLElement message)
message
- A more complex piece of data encoded in XML.public void sendProperty(String key, int value)
key
- value
- public void sendProperty(String key, int x, int y)
key
- x
- y
- public void receiveProperty(String key, String value)
key
- Key of property to be read from server.value
- String value of property to be read from server.public void receiveProperty(String key, int value)
key
- Key of property to be read from server.value
- Integer value of property to be read from server.public void receiveProperty(String key, int x, int y)
key
- Key of property to be read from server.x
- Integer x co-ordinate value property to be read from server.y
- Integer y co-ordinate value property to be read from server.public void receiveObject(XMLElement message)
message
- Receive a more complex XML object from a server.public boolean isThisPlayersTurn()
public void nextPlayer()
public void mouseEntered(MouseEvent e)
mouseEntered
in interface MouseListener
e
- public void mouseExited(MouseEvent e)
mouseExited
in interface MouseListener
e
- public void mouseClicked(MouseEvent e)
mouseClicked
in interface MouseListener
e
- public void mouseReleased(MouseEvent e)
mouseReleased
in interface MouseListener
e
- public void mousePressed(MouseEvent e)
mousePressed
in interface MouseListener
e
- public void mouseMoved(MouseEvent e)
mouseMoved
in interface MouseMotionListener
e
- public void mouseDragged(MouseEvent e)
mouseDragged
in interface MouseMotionListener
e
- public void keyPressed(KeyEvent e)
keyPressed
in interface KeyListener
e
- public void keyReleased(KeyEvent e)
keyReleased
in interface KeyListener
e
- public void keyTyped(KeyEvent e)
keyTyped
in interface KeyListener
e
-
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |