org.jogre.client
Class JogreController

java.lang.Object
  |
  +--org.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.

Version:
Alpha 0.1
Author:
Bob Marks

Field Summary
protected  ClientConnectionThread 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
 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.
 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 setConnection(ClientConnectionThread conn, int tableNum)
          Set up a network connection for this controller.
 
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 ClientConnectionThread 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

setConnection

public void setConnection(ClientConnectionThread conn,
                          int tableNum)
Set up a network connection for this controller.
Parameters:
conn - Link to the ClientConnectionThread.
tableNum -  

getCurrentPlayerSeatNum

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

getTableNum

public int getTableNum()
Return the table number.
Returns:
 

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:
 

isGamePlaying

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

isThisPlayersTurn

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

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 -