bluegammon.io
Class PlayerListenerProxy

java.lang.Object
  extended bybluegammon.io.PlayerListenerProxy
All Implemented Interfaces:
PlayerListener

public class PlayerListenerProxy
extends java.lang.Object
implements PlayerListener

This class serializes all events from sent to a PlayerListener and sends them to specified output stream. In this game there is a RemotePlayer on the other side of the connection. The RemotePlayer is also a PlayerListener and will get same listener events as this proxy via streams.

Relies on that specified outstream delivers and handles all fuzziness with I/O.

Author:
Peter Andersson

Field Summary
static byte EXIT
          Identification byte for reporting a player's shutdown.
static byte MOVE
          Identification byte for reporting a piece movement.
static byte MSG
          Identification byte for sending a message to remote player.
static byte TURN
          Identification byte for reporting a committed turn.
static byte UNDO
          Identification byte for reporting an undo.
 
Fields inherited from interface bluegammon.logic.PlayerListener
LOCAL_GIVE_UP, LOCAL_QUIT, REMOTE_GIVE_UP, REMOTE_QUIT
 
Constructor Summary
PlayerListenerProxy(java.io.DataOutputStream out)
          Creates a new PlayerListenerProxy that sends received PlayerListener events via specified output stream.
 
Method Summary
 void gameExited(int id, int reason)
          Called when player exits the game for some reason.
 void messageSent(int id, char[] msg)
          Called when player sent a message.
 void moveMade(int id, int moveIndex)
          Called when a player performs a move.
 void turnCommit(int id)
          Called when player is finished with his/her turn.
 void undoPerformed(int id)
          Called when player performs an undo.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MOVE

public static final byte MOVE
Identification byte for reporting a piece movement. Following is an ID integer and an move index integer.

See Also:
Constant Field Values

UNDO

public static final byte UNDO
Identification byte for reporting an undo. Following is an ID integer.

See Also:
Constant Field Values

TURN

public static final byte TURN
Identification byte for reporting a committed turn. Following is an ID integer.

See Also:
Constant Field Values

MSG

public static final byte MSG
Identification byte for sending a message to remote player. Following is an ID integer and a UTF-8-string.

See Also:
Constant Field Values

EXIT

public static final byte EXIT
Identification byte for reporting a player's shutdown. Following is an ID integer and a reason integer.

See Also:
Constant Field Values
Constructor Detail

PlayerListenerProxy

public PlayerListenerProxy(java.io.DataOutputStream out)
Creates a new PlayerListenerProxy that sends received PlayerListener events via specified output stream.

Parameters:
out - The stream to send events to.
Method Detail

moveMade

public void moveMade(int id,
                     int moveIndex)
Description copied from interface: PlayerListener
Called when a player performs a move.

Specified by:
moveMade in interface PlayerListener
Parameters:
id - Player id.
moveIndex - The moveindex in possible move array used for move.

undoPerformed

public void undoPerformed(int id)
Description copied from interface: PlayerListener
Called when player performs an undo.

Specified by:
undoPerformed in interface PlayerListener
Parameters:
id - Player id.

turnCommit

public void turnCommit(int id)
Description copied from interface: PlayerListener
Called when player is finished with his/her turn.

Specified by:
turnCommit in interface PlayerListener
Parameters:
id - Player id.

messageSent

public void messageSent(int id,
                        char[] msg)
Description copied from interface: PlayerListener
Called when player sent a message.

Specified by:
messageSent in interface PlayerListener
Parameters:
id - Player id.
msg - The message.

gameExited

public void gameExited(int id,
                       int reason)
Description copied from interface: PlayerListener
Called when player exits the game for some reason.

Specified by:
gameExited in interface PlayerListener
Parameters:
id - Player id.
reason - The reason for exiting game.