com.asdf.common
Class GameController

java.lang.Object
  extended by com.asdf.common.GameController
All Implemented Interfaces:
MessageHandler
Direct Known Subclasses:
HelloGame, PokerGameController

public abstract class GameController
extends java.lang.Object
implements MessageHandler

GameController is an abstract class which implements some basic functionality necessary for client side game controllers. It defines few abstract methods which are used as an interface to communicate with our client program and this client side game controller. If you wish to implement a new client side game controller to be used with game implemented at server side, you must use this class (or some other sub-class of this class) as super class of your own implementation.

Author:
asdf

Constructor Summary
GameController()
          Default constructor for GameController which sets a random id for itself.
 
Method Summary
 ConnectionHandler getConnectionHandler()
          Returns ConnectionHandler associated with this GameController.
 long getGameID()
          Gets this games gameID.
 long getID()
          Gets this games sessionID.
abstract  void init(GameResponse joinResponse, java.lang.String accountName, AccountType accountType)
          Since GameControllers are loaded dynamically in lobby it is not possible to use a constructor with parameters, which GameController implementations might need.
 void setConnectionHandler(ConnectionHandler connection)
          Sets this games ConnectionHandler and registers this GameController as a listener for messages received from server for this GameControllers sessionID.
 void setGameID(long id)
          Sets this games gameID.
 void setID(long id)
          Sets this games sessionID.
abstract  void start()
          Start is called from lobby when this GameController is ready to be started.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.asdf.client.MessageHandler
handleRequest, handleResponse, handleStateUpdate
 

Constructor Detail

GameController

public GameController()
Default constructor for GameController which sets a random id for itself.

Method Detail

init

public abstract void init(GameResponse joinResponse,
                          java.lang.String accountName,
                          AccountType accountType)
Since GameControllers are loaded dynamically in lobby it is not possible to use a constructor with parameters, which GameController implementations might need. This is used after the default constructor is called.

Parameters:
joinResponse - Parameters received from server required to initialize this
accountName - Account name of the user who is associated with this GameController.
accountType - Type of the user account. Some users might have more privileges than others. GameController

start

public abstract void start()
Start is called from lobby when this GameController is ready to be started. That means you should implement your game starting procedures using this method.


getID

public final long getID()
Gets this games sessionID.

Specified by:
getID in interface MessageHandler
Returns:
SessionID of this MessageHandler.

setID

public final void setID(long id)
Sets this games sessionID.

Specified by:
setID in interface MessageHandler
Parameters:
id - Semi-Unique sessionID.

setGameID

public final void setGameID(long id)
Sets this games gameID.

Parameters:
id - GameID received from server.

getGameID

public final long getGameID()
Gets this games gameID.

Returns:
gameID

setConnectionHandler

public void setConnectionHandler(ConnectionHandler connection)
Sets this games ConnectionHandler and registers this GameController as a listener for messages received from server for this GameControllers sessionID. ConnectionHandler is also used to send messages and you can get it by calling superclass method "getConnection()".

Specified by:
setConnectionHandler in interface MessageHandler
Parameters:
connection - ConnectionHandler to be used.

getConnectionHandler

public ConnectionHandler getConnectionHandler()
Returns ConnectionHandler associated with this GameController. If you want to send messages to server call this method to get the ConnectionHandler.

Specified by:
getConnectionHandler in interface MessageHandler
Returns:
ConnectionHandler associated with this GameController.