|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.lang.Thread | +--Client
The Client class is a communications interface for an individual user who wants to join a multiplayer game of Sokoban.
Fields inherited from class java.lang.Thread |
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY |
Constructor Summary | |
Client(Game owner,
java.lang.String ip,
int port)
Client constructor |
Method Summary | |
void |
disconnect()
Sends a disconnect message to the server. |
java.lang.String |
getIP()
Returns the ip address to connect to. |
int |
getPort()
Returns the port to connect to. |
int |
getRobotNumber()
Returns the robot number of this client. |
boolean |
isConnected()
Returns true if a connection to a server exists and false if a connection to a server doesn't exist. |
void |
postCommand(java.lang.String command)
Sends the command to the server. |
void |
processCommand(java.lang.String command)
Checks the command received from the server and determines what to do with the information |
void |
run()
Connects to and receives input from a server. |
void |
sendChangeLevelAccept(boolean accepted,
java.lang.String level)
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendChangeLevelRequest(java.lang.String level)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendChat(java.lang.String user,
java.lang.String message)
Creates a chat command String for the robot passed and sends the command to to the server. |
void |
sendMove(int robot,
Direction dir)
Creates a move command String for the robot passed and sends the command to the server. |
void |
sendRestartAccept(boolean accepted)
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendRestartRequest()
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients. |
void |
sendUndo(int robot)
Creates an undo command String for the robot passed and sends the command to to the server. |
void |
setIP(java.lang.String ip)
Sets the ip address to connect to. |
void |
setOwner(Game owner)
Sets the owner attribute. |
void |
setPort(int port)
Sets the port to connect to. |
Methods inherited from class java.lang.Thread |
activeCount, checkAccess, countStackFrames, currentThread, destroy, dumpStack, enumerate, getContextClassLoader, getName, getPriority, getThreadGroup, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, resume, setContextClassLoader, setDaemon, setName, setPriority, sleep, sleep, start, stop, stop, suspend, toString, yield |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
public Client(Game owner, java.lang.String ip, int port)
Client constructor
Pre-condition: none
Post-condition: Client class created; connectIP set to value of ip parameter; port set to value of port parameter
ip
- the IP address of the computer to connect toport
- the port to connect toMethod Detail |
public void run()
Connects to and receives input from a server.
Pre-condition: none
Post-condition: client thread is running
run
in class java.lang.Thread
public void processCommand(java.lang.String command)
Checks the command received from the server and determines what to do with the information
Pre-condition: command contains the input sent from server
Post-condition: the input has been processed and the Game is updated
command
- the String recieved from the server to be processedpublic void sendMove(int robot, Direction dir)
Creates a move command String for the robot passed and sends the command to the server.
Pre-condition: none
Post-condition: a move command String is created and sent to the server.
robot
- the robot number of the robot movingdir
- the direction the robot is movingpublic void sendUndo(int robot)
Creates an undo command String for the robot passed and sends the command to to the server.
Pre-condition: none
Post-condition: an undo command String is created and sent to the server.
robot
- the robot number of the robot movingdirection
- the direction the robot is movingpublic void sendChat(java.lang.String user, java.lang.String message)
Creates a chat command String for the robot passed and sends the command to to the server.
Pre-condition: none
Post-condition: a chat command String is created and sent to the server.
user
- the user name of the user who sent the messagemessage
- the message sent by the userpublic void sendChangeLevelAccept(boolean accepted, java.lang.String level)
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void sendChangeLevelRequest(java.lang.String level)
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void sendRestartAccept(boolean accepted)
Creates a restartMap command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void sendRestartRequest()
Creates a restart request command String for the robot passed and calls the sendToAll() method to send the command to all connected clients.
Pre-condition: none
Post-condition: a restart command String is created and sent to the sendToAll() method.
public void disconnect()
Sends a disconnect message to the server.
Pre-condition: existing socket connection to a server
Post-condition: disconnect command sent to the server; socket is closed
public void postCommand(java.lang.String command)
Sends the command to the server.
Pre-condition: existing socket connection to a server
Post-condition: command parameter is sent to the server
command
- information to be sent to the serverpublic void setOwner(Game owner)
Sets the owner attribute.
owner
- provides a link back to the game.public void setPort(int port)
Sets the port to connect to.
port
- the port to connect topublic int getPort()
Returns the port to connect to.
public void setIP(java.lang.String ip)
Sets the ip address to connect to.
ip
- the IP address of the computer to connect topublic java.lang.String getIP()
Returns the ip address to connect to.
public int getRobotNumber()
Returns the robot number of this client.
public boolean isConnected()
Returns true if a connection to a server exists and false if a connection to a server doesn't exist.
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |