vooga.engine.networking.server.games
Class TicTacToeHandler

java.lang.Object
  extended by java.lang.Thread
      extended by vooga.engine.networking.server.Handler
          extended by vooga.engine.networking.server.ClientHandler
              extended by vooga.engine.networking.server.games.TicTacToeHandler
All Implemented Interfaces:
java.lang.Runnable

public class TicTacToeHandler
extends ClientHandler

Extends ClientHandler to add TicTacToe specific logic to receiving and sending messages through the sockets. Every game will have a class like this that extends ClientHandler.


Nested Class Summary
 
Nested classes/interfaces inherited from class java.lang.Thread
java.lang.Thread.State, java.lang.Thread.UncaughtExceptionHandler
 
Field Summary
 
Fields inherited from class vooga.engine.networking.server.ClientHandler
handlers, numberOfPlayers
 
Fields inherited from class vooga.engine.networking.server.Handler
sessionID, socket
 
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY
 
Constructor Summary
TicTacToeHandler(VoogaDaemon daemon, GameSocket socket, int numberOfPlayers, int gameNumber)
          Calls ClientHandler's constructor.
 
Method Summary
 void firstRun()
          Right after the correct number of players is found, tell the first player that it is their turn and tell the other player that it is their opponent's turn.
 void run()
          Calls super.run() first to wait for the two players and call the firstRun method.
 
Methods inherited from class vooga.engine.networking.server.ClientHandler
broadcastToAll, broadcastToOthers, getFirstPlayer, getPlayers
 
Methods inherited from class vooga.engine.networking.server.Handler
getSessionID, getSocket
 
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, destroy, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, stop, suspend, toString, yield
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TicTacToeHandler

public TicTacToeHandler(VoogaDaemon daemon,
                        GameSocket socket,
                        int numberOfPlayers,
                        int gameNumber)
Calls ClientHandler's constructor.

Method Detail

run

public void run()
Calls super.run() first to wait for the two players and call the firstRun method. Then tries to receive the message from the server. If there is no message then that means they have quit so tell the other players that this player has quit. Otherwise send the message through to the opponent, tell the opponent that it is their turn, and then let the sender know that it is now their opponent's turn.

Specified by:
run in interface java.lang.Runnable
Overrides:
run in class ClientHandler

firstRun

public void firstRun()
Right after the correct number of players is found, tell the first player that it is their turn and tell the other player that it is their opponent's turn.

Specified by:
firstRun in class ClientHandler