net.sourceforge.yagurashogi.server
Class Player

java.lang.Object
  extended by net.sourceforge.yagurashogi.server.Player

public class Player
extends java.lang.Object

This object manages all the information about each connected player.


Field Summary
static int GAME
           
static int GAME_WAITING
           
static int IDLE
           
 
Constructor Summary
Player(ShogiServer shogiServer, java.net.Socket sock, java.lang.String login, java.lang.String pass)
          Creates new player for a user that logged in.
 
Method Summary
 void chat(java.lang.String message)
          Sends a message from this user to the others.
 void enterGame(Game g)
          Associates player with chosen game;
 Game getGame()
          Returns the game that this user plays.
 java.lang.String getMessage()
          Retrieves any new messages for this user.
 java.lang.String getName()
          Returns this user's name.
 int getState()
          Returns the state in which the player currently is.
 boolean isAvailable()
          Checks if this player wants to be paired up.
 void leaveGame()
          Makes player ready for a new game.
 void remove()
          Removes this user from the server.
 void send(java.lang.String message)
          Sends this user a message.
 void setAvailable(boolean avail)
          Sets this player's availability for pairing up to a new value.
 void setState(int st)
          Sets this player's state to a new value.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDLE

public static final int IDLE
See Also:
Constant Field Values

GAME_WAITING

public static final int GAME_WAITING
See Also:
Constant Field Values

GAME

public static final int GAME
See Also:
Constant Field Values
Constructor Detail

Player

public Player(ShogiServer shogiServer,
              java.net.Socket sock,
              java.lang.String login,
              java.lang.String pass)
Creates new player for a user that logged in.

Parameters:
shogiServer - the server that the user is on
sock - the socket through which the communication takes place
login - the name with which the user logged in
pass - password supplied by this user
Method Detail

enterGame

public void enterGame(Game g)
Associates player with chosen game;

Parameters:
g - the game that this user plays

leaveGame

public void leaveGame()
Makes player ready for a new game.


getGame

public Game getGame()
Returns the game that this user plays.

Returns:
this player's game

getName

public java.lang.String getName()
Returns this user's name.

Returns:
this player's name

getState

public int getState()
Returns the state in which the player currently is.

Returns:
this player's state

setState

public void setState(int st)
Sets this player's state to a new value.

Parameters:
st - new state value

remove

public void remove()
Removes this user from the server.


isAvailable

public boolean isAvailable()
Checks if this player wants to be paired up.

Returns:
true if the player is available, false otherwise

setAvailable

public void setAvailable(boolean avail)
Sets this player's availability for pairing up to a new value.

Parameters:
avail - true if the player wants to be paired up, false otherwise

send

public void send(java.lang.String message)
Sends this user a message.

Parameters:
message - the text to be delivered

getMessage

public java.lang.String getMessage()
Retrieves any new messages for this user.

Returns:
messages' content or null when none

chat

public void chat(java.lang.String message)
Sends a message from this user to the others.

Parameters:
message - message's content