au.com.solidsoftware.multimahjong.shared
Class Referee

java.lang.Object
  |
  +--java.rmi.server.RemoteObject
        |
        +--java.rmi.server.RemoteServer
              |
              +--java.rmi.server.UnicastRemoteObject
                    |
                    +--au.com.solidsoftware.multimahjong.shared.Referee
Direct Known Subclasses:
RemoteReferee

public class Referee
extends java.rmi.server.UnicastRemoteObject
implements RefereeIntf

Referee is in charge of initialising the game and delivering the moves to each player. The Game class has a reference to the Referee and it calls it to place the player's next move. The Referee also has references to all of the Observers, which in turn have references to the respective Game classes on each MMC.

Author:
Dean Cortinovis
See Also:
RegistrarImpl, Serialized Form

Field Summary
private  ObserverIntf[] game
          List of games.
(package private)  Wall gameWall
          Temp hold for players.
private  int limit
          Games limit
static int MAX_CLIENTS
           
protected  int noOfClients
          Number of clients present.
(package private)  int[] player
          Temp holder for wall.
private  MiniPlayer[] players
          Players in the game
private  int[] positions
          Indicated the location of the players.
private  boolean[] received
          Indicates whether wall has been receieved.
(package private)  int[] robSelection
          List of moves for robbing the kong.
(package private)  int[] selection
          List of moves selected by players
private  int selectionsMade
          Selections placed on the Referee
 boolean serverInitialised
          Flag to signal if server wall has been reinitialised
(package private)  Tile[] wall
           
 
Fields inherited from class java.rmi.server.UnicastRemoteObject
csf, port, portFactoryParamTypes, portParamTypes, serialVersionUID, ssf
 
Fields inherited from class java.rmi.server.RemoteServer
log, logname, serialVersionUID
 
Fields inherited from class java.rmi.server.RemoteObject
ref, serialVersionUID
 
Constructor Summary
Referee(java.lang.String name, int limit, int iconID, ObserverIntf creatorObserver)
          Server Constructor- constructs wall and players positions.
 
Method Summary
 int addPlayer(ObserverIntf observer, java.lang.String name, int iconID)
           
 void beginGame()
           
 void determineRobKong(int willRob, int playerPosition, int currentPlayer)
          Players enter there selections, if they can and want to rob kong.
 void exitGame()
           
 int getLimit()
           
 MiniPlayer[] getPlayers()
           
 int getPos()
          Get the next players position and removes position from the list once retrieved.
 int[] getPositions()
           
 Wall getWall()
          Given a tile position in the wall getWall returns the contents of this given position.
 void initServer()
          Initialise wall and player positions.
 void placePlayerAction(Moves currentMove, int action)
          Inserts the selected tile to kong into the server3 and notifies all other waiting threads that the new discard has been placed.
 void placeSelection(int selectionNo, int playerNo, int currentPlayer)
          Inserts a players selection into the selection storage, and checks to see if all selections have been placed.
 
Methods inherited from class java.rmi.server.UnicastRemoteObject
, clone, exportObject, exportObject, exportObject, exportObject, readObject, reexport, unexportObject
 
Methods inherited from class java.rmi.server.RemoteServer
getClientHost, getLog, setLog
 
Methods inherited from class java.rmi.server.RemoteObject
equals, getRef, hashCode, toString, toStub, writeObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, registerNatives, wait, wait, wait
 

Field Detail

MAX_CLIENTS

public static final int MAX_CLIENTS

serverInitialised

public boolean serverInitialised
Flag to signal if server wall has been reinitialised

wall

Tile[] wall

player

int[] player
Temp holder for wall.

gameWall

Wall gameWall
Temp hold for players.

selection

int[] selection
List of moves selected by players

robSelection

int[] robSelection
List of moves for robbing the kong.

game

private ObserverIntf[] game
List of games.

positions

private int[] positions
Indicated the location of the players.

players

private MiniPlayer[] players
Players in the game

received

private boolean[] received
Indicates whether wall has been receieved.

noOfClients

protected int noOfClients
Number of clients present.

limit

private int limit
Games limit

selectionsMade

private int selectionsMade
Selections placed on the Referee
Constructor Detail

Referee

public Referee(java.lang.String name,
               int limit,
               int iconID,
               ObserverIntf creatorObserver)
        throws java.rmi.RemoteException
Server Constructor- constructs wall and players positions.
Method Detail

getPlayers

public MiniPlayer[] getPlayers()
                        throws java.rmi.RemoteException
Specified by:
getPlayers in interface RefereeIntf

getPositions

public int[] getPositions()
                   throws java.rmi.RemoteException
Specified by:
getPositions in interface RefereeIntf

getLimit

public int getLimit()
             throws java.rmi.RemoteException
Specified by:
getLimit in interface RefereeIntf

addPlayer

public int addPlayer(ObserverIntf observer,
                     java.lang.String name,
                     int iconID)
              throws java.rmi.RemoteException
Specified by:
addPlayer in interface RefereeIntf

beginGame

public void beginGame()
               throws java.rmi.RemoteException
Specified by:
beginGame in interface RefereeIntf

initServer

public void initServer()
                throws java.rmi.RemoteException
Initialise wall and player positions. Wall built by placing tiles in order into the wall- then shuffling tiles around.
Specified by:
initServer in interface RefereeIntf

getPos

public int getPos()
           throws java.rmi.RemoteException
Get the next players position and removes position from the list once retrieved.
Specified by:
getPos in interface RefereeIntf
Returns:
int Returns the players position. Number between 0 and 3.

getWall

public Wall getWall()
             throws java.rmi.RemoteException
Given a tile position in the wall getWall returns the contents of this given position.
Specified by:
getWall in interface RefereeIntf
Parameters:
tileNo - The location at which the game thread wants the next tile.
Returns:
Tile The tile at the given location is returned.

placeSelection

public void placeSelection(int selectionNo,
                           int playerNo,
                           int currentPlayer)
                    throws java.rmi.RemoteException
Inserts a players selection into the selection storage, and checks to see if all selections have been placed. If so changes the flag and notifies of the change.
Specified by:
placeSelection in interface RefereeIntf
Parameters:
selectionNo - Players selection.
playerNo - Position of player making this selection.

placePlayerAction

public void placePlayerAction(Moves currentMove,
                              int action)
                       throws java.rmi.RemoteException
Inserts the selected tile to kong into the server3 and notifies all other waiting threads that the new discard has been placed.
Specified by:
placePlayerAction in interface RefereeIntf
Parameters:
selectedTile - Tile to try and reveal.
action - Whether to continue revealing kongs. 1-Continue, 0-Don't.
Returns:
No return type.

determineRobKong

public void determineRobKong(int willRob,
                             int playerPosition,
                             int currentPlayer)
                      throws java.rmi.RemoteException
Players enter there selections, if they can and want to rob kong.
Specified by:
determineRobKong in interface RefereeIntf
Parameters:
willrob - 0- if cant or don't want to rob kong. 1- if select to rob.
playerPosition - Player making the selection.

exitGame

public void exitGame()
              throws java.rmi.RemoteException
Specified by:
exitGame in interface RefereeIntf