uk.org.redfelineninja.risk.client
Class RiskServerHandler

java.lang.Object
  |
  +--uk.org.redfelineninja.risk.client.RiskServerHandler
All Implemented Interfaces:
RiskServerInterface, java.lang.Runnable

public class RiskServerHandler
extends java.lang.Object
implements RiskServerInterface, java.lang.Runnable

This class provides all the tools for a client to get data to and from the Server.


Constructor Summary
RiskServerHandler(RiskClientInterface inter)
          Create a new RiskServerHandler.
 
Method Summary
 void cards(Card[] cards)
          Turn the the supplied cards and exchange them for armies.
 void closeConnection()
          Close the current connection.
 void countryClicked(java.lang.String country)
          Tell the server that the client has clicked on a country.
 void finishTurn()
          The the server that the client wants to finish their go.
 void fortify()
          Tell the server that the client wants to fortify.
 boolean isConnected()
          Test whether or not we are connected to the server.
 void joinGame(java.lang.String name)
          Join an existing game.
 void message(java.lang.String msg)
          Send a mesage to all parties.
 void message(java.lang.String message, Player player)
          Send a message to the supplied player.
 void newGame(java.lang.String name, boolean random, boolean privacy)
          Start a new game.
 void openConnection(java.lang.String hostname, int port, Player player)
          Open a connection to the server and identify yourself as player.
 void run()
          This method runs in a daemon Thread parsing data from the server.
 void startGame()
          Stop waiting for new players and start playing the game.
 void stopGame(java.lang.String reason)
          Halt the current game.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RiskServerHandler

public RiskServerHandler(RiskClientInterface inter)
Create a new RiskServerHandler.

Method Detail

openConnection

public void openConnection(java.lang.String hostname,
                           int port,
                           Player player)
                    throws java.io.IOException
Open a connection to the server and identify yourself as player.

Specified by:
openConnection in interface RiskServerInterface
java.io.IOException

closeConnection

public void closeConnection()
                     throws java.io.IOException
Close the current connection. This should be considered ill mannered and loutish if a game is in progress,

Specified by:
closeConnection in interface RiskServerInterface
java.io.IOException

isConnected

public boolean isConnected()
Test whether or not we are connected to the server.

Specified by:
isConnected in interface RiskServerInterface

newGame

public void newGame(java.lang.String name,
                    boolean random,
                    boolean privacy)
Start a new game. In single game servers this is ignored since the server IS the game.

Specified by:
newGame in interface RiskServerInterface
Parameters:
random - start with randomly owned countries
privacy - permit private talking on the message system

joinGame

public void joinGame(java.lang.String name)
Join an existing game. On single game servers this will be ignored since joining the server is joining the game.

Specified by:
joinGame in interface RiskServerInterface

startGame

public void startGame()
Stop waiting for new players and start playing the game.

Specified by:
startGame in interface RiskServerInterface

stopGame

public void stopGame(java.lang.String reason)
Halt the current game. This should only be performed in exceptional situations.

Specified by:
stopGame in interface RiskServerInterface
Parameters:
reason - the reason for the game being halted

message

public void message(java.lang.String msg)
Send a mesage to all parties.

Specified by:
message in interface RiskServerInterface
Parameters:
msg - the message

message

public void message(java.lang.String message,
                    Player player)
Send a message to the supplied player.

Specified by:
message in interface RiskServerInterface
Parameters:
message - the message
player - the player to send the message to

countryClicked

public void countryClicked(java.lang.String country)
Tell the server that the client has clicked on a country.

Specified by:
countryClicked in interface RiskServerInterface
Parameters:
country - string giving the country that was clicked on.

cards

public void cards(Card[] cards)
Turn the the supplied cards and exchange them for armies.

Specified by:
cards in interface RiskServerInterface
Parameters:
cards - the card to be exchanged

fortify

public void fortify()
Tell the server that the client wants to fortify.

Specified by:
fortify in interface RiskServerInterface

finishTurn

public void finishTurn()
The the server that the client wants to finish their go.

Specified by:
finishTurn in interface RiskServerInterface

run

public void run()
This method runs in a daemon Thread parsing data from the server.

Specified by:
run in interface java.lang.Runnable