net.bluebones.boggle
Class Player

java.lang.Object
  extended by net.bluebones.boggle.Player
Direct Known Subclasses:
AIPlayer, HumanPlayer

public abstract class Player
extends Object

Represents the entire client side of Boggle.

Version:
0.3 $Revision: 1.3 $
Author:
Thomas David Baker

Constructor Summary
Player()
           
 
Method Summary
 boolean connecting()
          Gets whether this machine is in the process of connecting to another machine.
 String connectingTo()
          Gets the address of the machine this Player is currently trying to connect to.
 void createRegistry(int port)
          Creates an RMI Registry on the specified port for this Player.
 void endGame()
          Ends the game and returns words to the host of the game.
 Client getClient()
          Gets the Client being used by this player.
 NamedClient[] getClients()
          Gets the NamedClients attached to this player.
 Game getGame()
          Gets the game this Player is currently playing.
 HostInfo getHostInfo()
          Gets the HostInfo currently being used by this player.
abstract  IServer getLocalServer()
          Gets the local server.
 int getPort()
          Gets the port that the RMI Registry is running on.
 Registry getRegistry()
          Gets the RMI Registry in use by this player.
 IServer getRemoteServer()
          Gets the remote server.
abstract  String[] getWords()
          Get the words this Player has found this round.
 void hostConnectionLost()
          Takes the appropriate action after losing connection to a host.
abstract  void info(String msg)
          Relays the specified message to the user.
abstract  void init(char[][] letters, int timeInSecs)
          Initializes this Player with a board of letters and time for the round.
 void joinGame(GameInfo gameInfo)
          Joins this player into an existing game.
abstract  void problem(String msg)
          Notifies the user of the specified problem.
abstract  void results(Round round)
          Called when results are published.
 void setClient(Client client)
          Removes the old client in use by this Player (if any) and sets a new one.
 void setConnecting(String to)
          Sets the address this Player is currently connecting to.
abstract  void setConnection(ConnectionType type, String address, int clients)
          Sets the current connection details.
abstract  void setConnection(ConnectionType type, String address, int clients, int dots)
          Sets the current connection details with a number of dots to show progress.
 void setGame(Game game)
          Sets the game this Player is currently playing.
 void setHostInfo(HostInfo hostInfo)
          Sets the host details to be used by this Player.
abstract  void setLocalServer(Server server)
          Sets the local server.
 void setNotConnecting()
          Updates this Player so that it knows it is not connecting to any other machine (either because it has connected or because it has given up).
 void setRegistry(Registry registry)
          Sets the RMI Registry to be used by this Player.
 void setRemoteServer(IServer server)
          Sets the remote server.
abstract  void setRubber(Rubber r)
          To be implemented by subclasses to deal with Rubber details as they see fit (display, etc.) Subclasses must deal with the possibilty of a null Rubber being passed in.
abstract  void setTimer(int tenthsOfASecond)
          Sets the timer to the specified amount in tenths of a second
 void startLocalGame(char[][] letters, int timeInSecs)
          Starts a game for this player.
abstract  void stopGame()
          Implemented by the subclassed Player to do anything necessary at the end of a game (cleanup, marshalling of words and so on).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Player

public Player()
Method Detail

info

public abstract void info(String msg)
Relays the specified message to the user.

Parameters:
msg - Message to relay.

problem

public abstract void problem(String msg)
Notifies the user of the specified problem.

Parameters:
msg - Message to relay.

startLocalGame

public void startLocalGame(char[][] letters,
                           int timeInSecs)
Starts a game for this player.

Parameters:
letters - Letters to populate the board with.
timeInSecs - Duration of game.

stopGame

public abstract void stopGame()
Implemented by the subclassed Player to do anything necessary at the end of a game (cleanup, marshalling of words and so on).


getWords

public abstract String[] getWords()
Get the words this Player has found this round.

Returns:
String[] of words found.

endGame

public void endGame()
Ends the game and returns words to the host of the game.


joinGame

public void joinGame(GameInfo gameInfo)
Joins this player into an existing game.

Parameters:
gameInfo - Player-supplied host info to use to connect to the host.

getLocalServer

public abstract IServer getLocalServer()
Gets the local server. null if this Player is not currently hosting a game.

Returns:
Local server or null.

getRemoteServer

public IServer getRemoteServer()
Gets the remote server. null if this Player is not currently the client of another server.

Returns:
Remote server or null.

getClient

public Client getClient()
Gets the Client being used by this player.

Returns:
Client for this player.

getHostInfo

public HostInfo getHostInfo()
Gets the HostInfo currently being used by this player.

Returns:
HostInfo currently being used by this player.

setLocalServer

public abstract void setLocalServer(Server server)
Sets the local server. If the local server is not null this Player is acting as a host.

Parameters:
server - Server to set as local server or null to unset.

setRemoteServer

public void setRemoteServer(IServer server)
Sets the remote server. If the remote server is not null this Player is a client of the remote server.

Parameters:
server - IServer to set as remote server or null to unset.

setClient

public void setClient(Client client)
Removes the old client in use by this Player (if any) and sets a new one.

Parameters:
client - Client to use as client for this Player.

setConnection

public abstract void setConnection(ConnectionType type,
                                   String address,
                                   int clients)
Sets the current connection details.

Parameters:
type - ConnectionType type of connection.
address - String address connected to.
clients - int number of clients attached to this Player.

setConnection

public abstract void setConnection(ConnectionType type,
                                   String address,
                                   int clients,
                                   int dots)
Sets the current connection details with a number of dots to show progress.

Parameters:
type - ConnectionType type of connection.
address - String address connected to.
clients - int number of clients attached to this Player.
dots - int number of dots to be displayed by the client at this time. Maximum of three.

setHostInfo

public void setHostInfo(HostInfo hostInfo)
Sets the host details to be used by this Player.

Parameters:
hostInfo - HostInfo host details to set.

hostConnectionLost

public void hostConnectionLost()
Takes the appropriate action after losing connection to a host.


getPort

public int getPort()
Gets the port that the RMI Registry is running on.

Returns:
Number of the TCP port that the RMI Registry is running on.

getClients

public NamedClient[] getClients()
Gets the NamedClients attached to this player.

Returns:
NamedClient[] of the clients or an empty array if this Player is not hosting a game currently.

setRubber

public abstract void setRubber(Rubber r)
To be implemented by subclasses to deal with Rubber details as they see fit (display, etc.) Subclasses must deal with the possibilty of a null Rubber being passed in.

Parameters:
r - Rubber details to deal with.

setTimer

public abstract void setTimer(int tenthsOfASecond)
Sets the timer to the specified amount in tenths of a second

Parameters:
tenthsOfASecond - Amount to set the display to in tenths of a second.

init

public abstract void init(char[][] letters,
                          int timeInSecs)
Initializes this Player with a board of letters and time for the round.

Parameters:
letters - char[][] of letters on the board.
timeInSecs - int time of the round in seconds.

results

public abstract void results(Round round)
Called when results are published. To be implemented by subclass to display or otherwise deal with results.

Parameters:
round - Round result details.

createRegistry

public void createRegistry(int port)
Creates an RMI Registry on the specified port for this Player.

Parameters:
port - int TCP port to create registry on.

getGame

public Game getGame()
Gets the game this Player is currently playing.

Returns:
Game game being played.

setGame

public void setGame(Game game)
Sets the game this Player is currently playing.

Parameters:
game - Game this player is about to play.

connecting

public boolean connecting()
Gets whether this machine is in the process of connecting to another machine.

Returns:
boolean.

connectingTo

public String connectingTo()
Gets the address of the machine this Player is currently trying to connect to.

Returns:
String address of the machine being connected to.

setNotConnecting

public void setNotConnecting()
Updates this Player so that it knows it is not connecting to any other machine (either because it has connected or because it has given up).


setConnecting

public void setConnecting(String to)
Sets the address this Player is currently connecting to.

Parameters:
to - String address being connected to.

getRegistry

public Registry getRegistry()
Gets the RMI Registry in use by this player.

Returns:
Registry currently in use.

setRegistry

public void setRegistry(Registry registry)
Sets the RMI Registry to be used by this Player.

Parameters:
registry - Registry to use.