org.jogre.client
Class JogreController

java.lang.Object
  extended byorg.jogre.client.JogreController
All Implemented Interfaces:
EventListener, KeyListener, MouseListener, MouseMotionListener

public abstract class JogreController
extends Object
implements MouseListener, MouseMotionListener, KeyListener

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.

Version:
Alpha 0.2.3
Author:
Bob Marks

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

model

protected JogreModel model
Link to the game model.


JogreComponent

protected JogreComponent JogreComponent
Link to the JogreComponent this is controlling .


conn

protected TableConnectionThread conn
Link to the client's connection thread.


tableNum

protected int tableNum
Table number which this controller is controlling.

Constructor Detail

JogreController

public JogreController(JogreModel model,
                       JogreComponent JogreComponent)
Default constructor class which doesn't set up the network connection.

Parameters:
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

start

public abstract void start()
Reset method which is called every time a new game is created. Each sub class of this must have this method. This method is called when the game starts for the first time.


setConnection

public void setConnection(TableConnectionThread conn)
Set up a network connection for this controller.

Parameters:
conn - Link to the TableConnectionThread.

getCurrentPlayer

public String getCurrentPlayer()
Return the current player.

Returns:
Current player's username.

getCurrentPlayerSeatNum

public int getCurrentPlayerSeatNum()
Return the player num (between 0 and the number of players).

Returns:
Seat number of current player.

getTableNum

public int getTableNum()
Return the table number.

Returns:
table number.

getTable

public Table getTable()
Convience method for returning a table.

Returns:
Current table i.e. tableList.getTable (current table).

getSeatNum

public int getSeatNum()
Return the seat number of a user.

Returns:
If -1 user is standing, otherwise seatNum >=0 and < number of seats available.

getPlayer

public String getPlayer(int seatNum)
Return the player name from a seat num.

Parameters:
seatNum - Seat number of the user.
Returns:
If -1 user is standing, otherwise seatNum >=0 and < number of seats available.

getSeatNum

public int getSeatNum(String player)
Return the seat number of a specified player.

Parameters:
player - Name of the player.
Returns:
Number of specified players seat.

isGamePlaying

public boolean isGamePlaying()
Return true/false if the game is started or not.

Returns:
Returns true if a game is underway.

sendProperty

public void sendProperty(String key,
                         String value)
Send a normal String valued property.

Parameters:
key -
value -

sendObject

public void sendObject(ITransmittable object)
Send a more complex object (any object which implements the ITransmittable interface). The recieve (XMLElement element) method must be overwritten to recieve it.

Parameters:
object - A more complex piece of data encoded in XML.

sendObject

public void sendObject(XMLElement message)
Send a more complex object (any object which implements the ITransmittable interface). The recieve (XMLElement element) method must be overwritten to recieve it.

Parameters:
message - A more complex piece of data encoded in XML.

sendProperty

public void sendProperty(String key,
                         int value)
Send a single integer property.

Parameters:
key -
value -

sendProperty

public void sendProperty(String key,
                         int x,
                         int y)
Send a co-ordinate property (x and y integer values).

Parameters:
key -
x -
y -

receiveProperty

public void receiveProperty(String key,
                            String value)
Adapter method for receiving property as a key and value from another client.

Parameters:
key - Key of property to be read from server.
value - String value of property to be read from server.

receiveProperty

public void receiveProperty(String key,
                            int value)
Recieve property as a String key and integer value.

Parameters:
key - Key of property to be read from server.
value - Integer value of property to be read from server.

receiveProperty

public void receiveProperty(String key,
                            int x,
                            int y)
Recieve property from another client as a co-ordinate (x and y integer).

Parameters:
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.

receiveObject

public 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).

Parameters:
message - Receive a more complex XML object from a server.

isThisPlayersTurn

public boolean isThisPlayersTurn()
Return new if it is this players turn.

Returns:
True if this current players turn.

nextPlayer

public void nextPlayer()
Method which tells the server that it is next players turn.


mouseEntered

public void mouseEntered(MouseEvent e)
Invoked when the mouse enters a JogreJogreComponent.

Specified by:
mouseEntered in interface MouseListener
Parameters:
e -

mouseExited

public void mouseExited(MouseEvent e)
Invoked when the mouse exits a JogreComponent.

Specified by:
mouseExited in interface MouseListener
Parameters:
e -

mouseClicked

public void mouseClicked(MouseEvent e)
Invoked when the mouse has been clicked on a JogreComponent.

Specified by:
mouseClicked in interface MouseListener
Parameters:
e -

mouseReleased

public void mouseReleased(MouseEvent e)
Invoked when a mouse button has been released on a JogreComponent.

Specified by:
mouseReleased in interface MouseListener
Parameters:
e -

mousePressed

public void mousePressed(MouseEvent e)
Invoked when a mouse button has been pressed on a JogreComponent.

Specified by:
mousePressed in interface MouseListener
Parameters:
e -

mouseMoved

public void mouseMoved(MouseEvent e)
Invoked when the mouse button has been moved on a JogreComponent (with no buttons no down).

Specified by:
mouseMoved in interface MouseMotionListener
Parameters:
e -

mouseDragged

public void mouseDragged(MouseEvent e)
Invoked when a mouse button is pressed on a JogreComponent and then dragged.

Specified by:
mouseDragged in interface MouseMotionListener
Parameters:
e -

keyPressed

public void keyPressed(KeyEvent e)
Invoked when a key has been pressed.

Specified by:
keyPressed in interface KeyListener
Parameters:
e -

keyReleased

public void keyReleased(KeyEvent e)
Invoked when a key has been released.

Specified by:
keyReleased in interface KeyListener
Parameters:
e -

keyTyped

public void keyTyped(KeyEvent e)
Invoked when a key has been typed.

Specified by:
keyTyped in interface KeyListener
Parameters:
e -