heurgame
Class PlayerProxy

java.lang.Object
  extended byheurgame.PlayerProxy

public abstract class PlayerProxy
extends java.lang.Object

Author:
David Kaplin PlayerProxies allow for Protocol Independance. Whether or not the player is a network player is immaterial. This class and all of its children translate the protocol to an interface understood by the entire framework. I sincerely hope it is general enough to be used for any sort of game.

Field Summary
protected  LogBox debugging
           
protected  java.io.BufferedReader fromPlayer
          fromPlayer The part we read from the player.
protected  PlayerToken token
          Each Individual Player has posesson of a single token that identifies them to the system.
protected  java.io.PrintWriter toPlayer
          toPlayer The part we write to the player.
 
Constructor Summary
PlayerProxy()
           
 
Method Summary
abstract  java.lang.String getMove(java.lang.String query)
          Informs the player that it is their turn.
 PlayerToken getToken()
          Allows other components to have a partial handle on the player state without giving them too much information.
abstract  void sendDisqualify(java.lang.String reason)
          Informs the player that they have been disqualified from the game.
abstract  void sendFinalStatus(java.lang.String status)
          Informs the player of its final status in the game.
abstract  void sendIncrementalStatus(java.lang.String status)
          Sends the latest change in status
abstract  void sendInitialStatus(java.lang.String status)
          Informs the player of the initial status of the game.
abstract  java.lang.String sendInvalidMove(java.lang.String information)
          Uses the protocol to inform the player they have made an invalid move
abstract  void sendStatus(java.lang.String status)
          Sends intermediate game status
 void setup(PlayerProxy parent, java.lang.String origin, java.net.Socket s)
          This should be useed in liew of a constructor.
abstract  void setupLogging(LogBox debugger)
          Taylors the debugging method to an implementation specific one
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

debugging

protected LogBox debugging

token

protected PlayerToken token
Each Individual Player has posesson of a single token that identifies them to the system. This token is used throughout the framework.


fromPlayer

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


toPlayer

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

Constructor Detail

PlayerProxy

public PlayerProxy()
Method Detail

setup

public final void setup(PlayerProxy parent,
                        java.lang.String origin,
                        java.net.Socket s)
                 throws java.io.IOException
This should be useed in liew of a constructor. If the socket is open. The server will expect to read the players name in the first line of the output. Inside only creation of a PlayerToken takes place.

Parameters:
parent - The originating PlayerProxy
origin - The source of the Proxy, should be a hostname and port
s - Actual socket connected to the player
Throws:
java.io.IOException - Will be thrown in case of socket problems.

getToken

public PlayerToken getToken()
Allows other components to have a partial handle on the player state without giving them too much information.

Returns:
Token that contains the player name and a unique id in the case of rare naming conflicts. It is recommented to test based on the == equality to remove any possibility of duplication.

getMove

public abstract java.lang.String getMove(java.lang.String query)
Informs the player that it is their turn. Returns the player's response

Parameters:
query - game specific information for the player
Returns:
The move sent by the player

sendDisqualify

public abstract void sendDisqualify(java.lang.String reason)
Informs the player that they have been disqualified from the game.

Parameters:
reason - why the person was disqualified

sendInitialStatus

public abstract void sendInitialStatus(java.lang.String status)
Informs the player of the initial status of the game.

Parameters:
status - specific to the individual game.

sendFinalStatus

public abstract void sendFinalStatus(java.lang.String status)
Informs the player of its final status in the game. If this message is sent the player was not disqualified during the game.

Parameters:
status - specific to the inidividual game

sendStatus

public abstract void sendStatus(java.lang.String status)
Sends intermediate game status

Parameters:
status - specific information

sendIncrementalStatus

public abstract void sendIncrementalStatus(java.lang.String status)
Sends the latest change in status

Parameters:
status - game specific

sendInvalidMove

public abstract java.lang.String sendInvalidMove(java.lang.String information)
Uses the protocol to inform the player they have made an invalid move

Parameters:
information - why the move was invalid
Returns:
A better move from the player

setupLogging

public abstract void setupLogging(LogBox debugger)
Taylors the debugging method to an implementation specific one

Parameters:
debugger - A prepackaged system that allows easy logging capability.