Class TTTccpListener

java.lang.Object
  extended by TTTccpListener
All Implemented Interfaces:
java.lang.Runnable

public class TTTccpListener
extends java.lang.Object
implements java.lang.Runnable

TTT project file that listens for CCP messages and reacts in an appropriate fashion

Author:
James Barr

Field Summary
private  boolean done
          status of the CCP Message Listener
private  TTTengine tttEngine
          reference to the main engine class
 
Constructor Summary
TTTccpListener(TTTengine tttEngine)
          Copy the engine reference and set status to false
 
Method Summary
private  void commandKill()
          Sends exit message and tells GUI to close everything
private  void endGame(java.lang.String from)
          If currently playing a game, end it.
private  void getState()
          If the state is there, return it and success.
private  void makeMove(java.lang.String player, java.lang.String flags)
          If playing a game, set appropriate letter on GUI and if using auto mode, tell the robix interface to draw the letter on the real board.
 void run()
          Main execution loop starts when thread is started.
private  void setAutoModeReady(java.lang.String flags)
          Marks Vision System and Robix Interface as ready when their modules are online
private  void setOpponent(java.lang.String name, java.lang.String from)
          New opponent can only be set while not playing a game.
private  void setOpponentAlert(java.lang.String from)
          Marks LA Opponents as alert when correct message is received from their modules
private  void startNewAutoGame(java.lang.String from, java.lang.String type, java.lang.String flags)
          If already playing a game, sends error message.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tttEngine

private TTTengine tttEngine
reference to the main engine class


done

private boolean done
status of the CCP Message Listener

Constructor Detail

TTTccpListener

public TTTccpListener(TTTengine tttEngine)
Copy the engine reference and set status to false

Parameters:
tttEngine - - reference to main engine class
Method Detail

run

public void run()
Main execution loop starts when thread is started. While not done, keep listening for messages.

Specified by:
run in interface java.lang.Runnable

makeMove

private void makeMove(java.lang.String player,
                      java.lang.String flags)
               throws javaClient.exceptions.MsgFieldLenException
If playing a game, set appropriate letter on GUI and if using auto mode, tell the robix interface to draw the letter on the real board. Send move to the LA if the player is HUMAN and check for a win or tie

Parameters:
player - - string that is either HUMAN or ROBOT
flags - - string version of a number of a cell 1 - 9
Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop

setOpponentAlert

private void setOpponentAlert(java.lang.String from)
Marks LA Opponents as alert when correct message is received from their modules


setAutoModeReady

private void setAutoModeReady(java.lang.String flags)
Marks Vision System and Robix Interface as ready when their modules are online


commandKill

private void commandKill()
                  throws javaClient.exceptions.MsgFieldLenException
Sends exit message and tells GUI to close everything

Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop

startNewAutoGame

private void startNewAutoGame(java.lang.String from,
                              java.lang.String type,
                              java.lang.String flags)
                       throws javaClient.exceptions.MsgFieldLenException
If already playing a game, sends error message. Otherwise, tells GUI and LA to start a new game. Uses ROY TTT LEARNER as default if no LA chosen.

Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop

endGame

private void endGame(java.lang.String from)
              throws javaClient.exceptions.MsgFieldLenException
If currently playing a game, end it. Otherwise send error message.

Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop

setOpponent

private void setOpponent(java.lang.String name,
                         java.lang.String from)
                  throws javaClient.exceptions.MsgFieldLenException
New opponent can only be set while not playing a game.

Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop

getState

private void getState()
               throws javaClient.exceptions.MsgFieldLenException
If the state is there, return it and success. Otherwise return failure message.

Throws:
javaClient.exceptions.MsgFieldLenException - - Dealth with by try/catch in main loop