Class Client

java.lang.Object
  extended byClient
All Implemented Interfaces:
java.lang.Runnable

public class Client
extends java.lang.Object
implements java.lang.Runnable

This class creates a client from the Scrabble lobby. A client can be created from either the server or client lobbies, in the former case a client connects locally. Class provides methods called when the client receives a move (decodeLetterMove), for receiving a dictionary from the server (receiveDictionary), and all other protocol messages.

Version:
2.0
Author:
3GP01 - Hardev Bhamra, Deepak Chandarana, James Tompkin
See Also:
Server, ServerThread

Constructor Summary
Client()
           
 
Method Summary
 void checkDictionary(java.lang.String dictionary)
          Method that checks to see whether the client has the dictionary that the server is using.
 void clientLeftGame(int uid)
          Passes information to the RemoteScrabble game, informing it that a client with specific uid has left the game.
 void clientLeftLobby(int uid)
          Removes a specific client with uid from the lobby interface.
 void clientServerException(java.lang.Exception e)
          Method to display an exception dialog to the client, informing them that the server has errored.
 void close()
          Method to close the client's input/output streams, and finally close the client's socket.
 void createClient(java.lang.String hostLocation)
          Creates an IRS client.
 void createDownloadingDialog()
          Method to create a dialog showing the player that a dictionary is being downloaded from the server.
 void decodeLetterMove(java.lang.String letterMoves)
          A method to decode a received letter move, and call the end of the turn.
 java.lang.String getHostLocation()
          Returns the location of the host.
 Move getMove()
          Returns a Move, stored locally as move.
 Scrabble getScrabble()
          Returns the current Scrabble program instance.
 java.lang.String getServerDictionary()
          Returns the dictionary the server is using as a String dictionary name.
 void receiveDictionary(java.lang.String firstLine)
          Method that accepts the incoming dictionary set from the ServerThread.
 void run()
          Client run, starts createClient method.
 void setMessageOutput(int messageType, java.lang.String messageOutput)
          Method to write to the ServerThread.
 void setNames(int uid, java.lang.String name)
          Sets the name locally of a specific player in the game.
 void start()
          Client thread start.
 void swapLetterMove(java.lang.String swapMove)
          A method to handle an incoming swap letters move.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Client

public Client()
Method Detail

getScrabble

public Scrabble getScrabble()
Returns the current Scrabble program instance.

Returns:
Scrabble

getServerDictionary

public java.lang.String getServerDictionary()
Returns the dictionary the server is using as a String dictionary name.

Returns:
String

getHostLocation

public java.lang.String getHostLocation()
Returns the location of the host.

Returns:
String The location of the host as an IP.

createClient

public void createClient(java.lang.String hostLocation)
Creates an IRS client. Client will try to connect to the host, and upon success, will begin waiting for messages. If a connection to the server is at any time lost, the client will fatal exception, present dialog, and close.

Parameters:
hostLocation - The location of the server.

setNames

public void setNames(int uid,
                     java.lang.String name)
Sets the name locally of a specific player in the game.

Parameters:
uid - The unique identifier of the player.
name - The name of the player.

setMessageOutput

public void setMessageOutput(int messageType,
                             java.lang.String messageOutput)
Method to write to the ServerThread. Method will process information depending on the ScrabbleProtocol before sending it out.

Parameters:
messageType - The type of message required for sending.
messageOutput - The body of the message, as a String.

clientLeftGame

public void clientLeftGame(int uid)
Passes information to the RemoteScrabble game, informing it that a client with specific uid has left the game.

Parameters:
uid - The unique identifier of the player.

clientLeftLobby

public void clientLeftLobby(int uid)
Removes a specific client with uid from the lobby interface.

Parameters:
uid - The unique identifier of the player.

swapLetterMove

public void swapLetterMove(java.lang.String swapMove)
A method to handle an incoming swap letters move. The method removes letters from the rack, replaces them into the bag, and takes the necessary new letters.

Parameters:
swapMove - The required letters to be swapped, formed as a String.

decodeLetterMove

public void decodeLetterMove(java.lang.String letterMoves)
A method to decode a received letter move, and call the end of the turn.

Parameters:
letterMoves - The required letters to be placed, formed as a String.

getMove

public Move getMove()
Returns a Move, stored locally as move. Called when the client needs to wait for response of a move.

Returns:
Move

checkDictionary

public void checkDictionary(java.lang.String dictionary)
Method that checks to see whether the client has the dictionary that the server is using. If it is not, it sends a message to the ServerThread telling it to send the dictionary

Parameters:
dictionary -

receiveDictionary

public void receiveDictionary(java.lang.String firstLine)
Method that accepts the incoming dictionary set from the ServerThread.

Parameters:
firstLine - The first line of the dictionary - ensures it is written.

createDownloadingDialog

public void createDownloadingDialog()
Method to create a dialog showing the player that a dictionary is being downloaded from the server.


clientServerException

public void clientServerException(java.lang.Exception e)
Method to display an exception dialog to the client, informing them that the server has errored.

Parameters:
e - The exception caused.

close

public void close()
Method to close the client's input/output streams, and finally close the client's socket.


start

public void start()
Client thread start.


run

public void run()
Client run, starts createClient method.

Specified by:
run in interface java.lang.Runnable