heurgame
Class HuClient

java.lang.Object
  extended byheurgame.HuClient
All Implemented Interfaces:
java.lang.Runnable

public abstract class HuClient
extends java.lang.Object
implements java.lang.Runnable

Author:
David Kaplin HuClients are short for "HumanClients" each of these act on the request of a physical user who is occupying the same computer as the game server. Instead of giving the protocol to the user directly, the status information appears in some form of user interface. When the player is instructed it it their move they should interact with a component that is a HuReceptor that can properly translate the users actions into the text that needs to be translated over the network.

Field Summary
protected  LogBox debugging
           
protected  java.io.BufferedReader fromServer
          fromPlayer The part we read from the player.
protected  HuReceptor guiReceptor
          guiReceptor is the component that the user interacts with to play the game.
protected  java.lang.String move
          move is a protocol specific string that corresponds to a players move.
protected  java.io.PrintWriter toServer
          toPlayer The part we write to the player.
 
Constructor Summary
HuClient()
           
 
Method Summary
 void connect(java.net.Socket s, java.lang.String name)
          This method should be called before loading the HeuClient into a thread.
 void fromOutside(java.lang.String ans)
          Another portion of the input contract Notifies the component of some new external data
abstract  void handleDisqualification(java.lang.String reason)
          Informs us that we have been rejected from the game
abstract  void handleFinalStatus(java.lang.String status)
          Ususally the final outcome of the game.
abstract  void handleIncrementalStatus(java.lang.String status)
          Gets the latest change in status
abstract  void handleInitialStatus(java.lang.String status)
          Initial Status usually does not involve the actions of other players.
abstract  java.lang.String handleInvalidMove(java.lang.String reason)
          Now knowing the reason for an invalid move, the player should respond with a hopefully valid move.
abstract  java.lang.String handleMove(java.lang.String query)
          Invoked when it is our turn to move.
abstract  void handleStatus(java.lang.String status)
          Usuallly the state of other players during the game.
 void setReceptor(HuReceptor h)
          The Initial portion of the outside input contract that allows the HuClient access to user input.
abstract  java.lang.String waitForMessage()
          This should be called as the thread polls
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface java.lang.Runnable
run
 

Field Detail

debugging

protected LogBox debugging

fromServer

protected java.io.BufferedReader fromServer
fromPlayer The part we read from the player.


toServer

protected java.io.PrintWriter toServer
toPlayer The part we write to the player.


move

protected volatile java.lang.String move
move is a protocol specific string that corresponds to a players move.


guiReceptor

protected HuReceptor guiReceptor
guiReceptor is the component that the user interacts with to play the game.

Constructor Detail

HuClient

public HuClient()
Method Detail

setReceptor

public void setReceptor(HuReceptor h)
The Initial portion of the outside input contract that allows the HuClient access to user input.

Parameters:
h - some component that will notify us when we desire information.

fromOutside

public void fromOutside(java.lang.String ans)
Another portion of the input contract Notifies the component of some new external data

Parameters:
ans - Specific to implementation.

connect

public final void connect(java.net.Socket s,
                          java.lang.String name)
                   throws java.io.IOException
This method should be called before loading the HeuClient into a thread. The player should report their name to the server.

Parameters:
s - An open bound constructed sockect
name - Represents this player
Throws:
java.io.IOException

waitForMessage

public abstract java.lang.String waitForMessage()
This should be called as the thread polls

Returns:
Our next message from the Server

handleMove

public abstract java.lang.String handleMove(java.lang.String query)
Invoked when it is our turn to move. It is suggested that the player save its move information in case it sent an invalid move.

Parameters:
query - The state of the game as defined by the server.
Returns:
our response to the server.

handleInvalidMove

public abstract java.lang.String handleInvalidMove(java.lang.String reason)
Now knowing the reason for an invalid move, the player should respond with a hopefully valid move.

Parameters:
reason - why the move was invalid
Returns:
another move from the player.

handleInitialStatus

public abstract void handleInitialStatus(java.lang.String status)
Initial Status usually does not involve the actions of other players. It might be something like the size of the board.

Parameters:
status - specific to game

handleStatus

public abstract void handleStatus(java.lang.String status)
Usuallly the state of other players during the game.

Parameters:
status - game specific

handleIncrementalStatus

public abstract void handleIncrementalStatus(java.lang.String status)
Gets the latest change in status

Parameters:
status - game specific

handleFinalStatus

public abstract void handleFinalStatus(java.lang.String status)
Ususally the final outcome of the game.

Parameters:
status - exepected to be something of the lines of WIN, LOSE, or TIE

handleDisqualification

public abstract void handleDisqualification(java.lang.String reason)
Informs us that we have been rejected from the game

Parameters:
reason - for the rejection