au.com.solidsoftware.multimahjong.mmc.game
Class Player

java.lang.Object
  |
  +--au.com.solidsoftware.multimahjong.mmc.game.Player
Direct Known Subclasses:
ComputerOpponent, Human

public class Player
extends java.lang.Object

SRS - 4.2.2.1, 4.2.2.2.

This class forms the representation of a player in the game of mahjong. All relevant information connected to a single player will be contained in the attributes of this class.

The main responsibility of the Player class will be to act as a bridge between the Game and Hand classes. Whenever a change needs to be made to the player's Hand the Game class will call the appropriate method in this class, which will in turn update the Hand. All changes to the player's attributes are then passed to the PlayArea class to update the screen.

Author:
Dean Cortinovis

Field Summary
static int CHOW2DOWN
           
static int CHOW2SIDES
           
static int CHOW2UP
           
static int DECLARED_KONG
           
static int DISCARD
           
static int EAST
           
static int EITHER_MOVE
          Either extendPung or declare Kong move- doesn't matter which
static int EXTEND_PUNG
           
protected  javax.swing.ImageIcon icon
          Player's selected icon.
protected  boolean isFishing
          Flag- True if player is fishing.
static int KONG
           
static int MAHJONG
           
protected  java.lang.String name
          Contains player's name.
static int NO_MOVE
           
static int NORTH
           
static int NOT_ROBBED
          Signifies kong has not been robbed.
(package private)  Payout payout
          Reference to the Game's payout
static int PICKUP
           
protected  PlayArea playArea
          Reference to the playArea.
protected  Hand playerHand
          Holds player's Hand.
protected  int playerId
          Identifies the location of the player.
static int PUNG
           
static int ROBBED_KONG
          Signifies kong has been robbed.
protected  int score
          Player's score.
protected  Tile selectedTile
          Tile last selected by the player.
static int SOUTH
           
protected  boolean standingHand
          Flag- True if standing hand.
protected  UserGUI userGUI
          Reference to the userGUI.
static int WEST
           
protected  int wind
          Wind of the player.
static int WONT_ROB
          Signifies player won't rob the kong.
 
Constructor Summary
Player(java.lang.String name, javax.swing.ImageIcon icon, int score, int playerId)
          Initialises the Player's name, icon, inserts the initial score and the player id.
 
Method Summary
 boolean checkFishing()
          Checks to see if the player's Hand is fishing.
 boolean checkKong(Tile selectedTile)
          Looks to see if the player can declare a concealed kong with the selected tile.
 boolean checkMahjong(Tile lastPickUp, boolean lastTile)
          The function checks to see if the Hand has Mahjong after picking up tile from the Wall.
 boolean checkPung2Kong(Tile selectedTile)
          CheckPung2Kong checks player's Hand for an exposed Pung similar to the selected tile.
 void declareKong(Tile selectedTile)
          Exposes a concealed Kong in the player's Hand using the selected tile and updates the PlayArea.
 int determineCanRob(Tile selectedTile)
          Determines whether the player can rob the Kong with the given tile.
 void discard(Tile lastDiscard)
          Removes the given tile in the player's Hand and updates the PlayArea with the changes.
 boolean findKong()
          Looks in the player's Hand for concealed Kongs.
 boolean findPung2Kong()
          Looks in the player's concealed and exposed Hands to determine if pung2Kong is possible.
 int getDiscard(boolean playerFishing, Moves currentMove)
          Retrieves the discard or special Kong move from the current player.
 javax.swing.ImageIcon getIcon()
          Retrieves the player's icon.
 int getId()
          Returns the player's id.
 java.lang.String getName()
          Retrieves the player's name.
 int getPlayerSelection(Tile lastDiscard, int next)
          Retrieves a selection from the player to be sent to the Referee.
 int getScore()
          Returns player's score.
 int getWind()
          Returns wind of the player.
 void initPlayer(Payout payout)
          Re-initialises the classes fishing and standing hand attributes and the player's Hand at the beginning of each hand.
 void insertTile(Tile tile)
          Inserts the given tile into the player's Hand, and updates the PlayArea with the changes.
 void insertTile(Tile[] tile, int insertAmount)
          Insert a list of tiles into the player's Hand, and updates the PlayArea with the changes.
 void isStandingHand()
          Sets standing hand flag to true.
 void mahjong(Game game)
          This function is run when the winning player has won Mahjong.
 void notStandingHand()
          Removes standing hand flag.
 void robbedKong(Tile robbedTile, boolean lastTile)
          RobbedKong is run if the player has successfully rob the Kong.
 void runChow(Tile lastDiscard, int selection)
          Exposes a Chow from the player's concealed Hand with the given discard.
 void runKong(Tile lastDiscard)
          Exposes a Kong from the player's concealed Hand with the given discard.
 void runMahjong(Tile lastDiscard)
          Inserts the tile into the Hand and runs mahjong with the last discarded tile.
 void runPung(Tile lastDiscard)
          Exposes a Pung from the player's concealed Hand with the given discard.
 void runPung2Kong(Tile selectedTile)
          This function is run if the player has selected to and can successfully add a tile to an exposed Pung.
 void setIcon(javax.swing.ImageIcon icon)
          Updates the player's icon, and updates the PlayArea with changes.
 void setMove(Tile tile, int move)
          Inserts a selected move made by the player from the UserGUI.
 void setName(java.lang.String name)
          Updates the player's name, and updates the PlayArea with changes.
 void setPlayArea(PlayArea playArea)
          Receives a reference to the PlayArea.
 void setPlayArea(PlayArea playArea, UserGUI userGUI)
          Receives a reference to the PlayArea and the UserGUI
 void setScore(int score)
          Updates the player's score, and updates the PlayArea with changes.
 void setSelection(int move)
          Inserts the selected move that a player has chosen with the last discarded tile, if it is possible.
 void setWind(int wind)
          Updates the player's wind, and updates the PlayArea with changes.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

EAST

public static final int EAST

SOUTH

public static final int SOUTH

WEST

public static final int WEST

NORTH

public static final int NORTH

NO_MOVE

public static final int NO_MOVE

PICKUP

public static final int PICKUP

CHOW2SIDES

public static final int CHOW2SIDES

CHOW2DOWN

public static final int CHOW2DOWN

CHOW2UP

public static final int CHOW2UP

PUNG

public static final int PUNG

KONG

public static final int KONG

MAHJONG

public static final int MAHJONG

DISCARD

public static final int DISCARD

DECLARED_KONG

public static final int DECLARED_KONG

EXTEND_PUNG

public static final int EXTEND_PUNG

EITHER_MOVE

public static final int EITHER_MOVE
Either extendPung or declare Kong move- doesn't matter which

NOT_ROBBED

public static final int NOT_ROBBED
Signifies kong has not been robbed.

ROBBED_KONG

public static final int ROBBED_KONG
Signifies kong has been robbed.

WONT_ROB

public static final int WONT_ROB
Signifies player won't rob the kong.

isFishing

protected boolean isFishing
Flag- True if player is fishing.

standingHand

protected boolean standingHand
Flag- True if standing hand.

playerHand

protected Hand playerHand
Holds player's Hand.

name

protected java.lang.String name
Contains player's name.

score

protected int score
Player's score.

wind

protected int wind
Wind of the player.

selectedTile

protected Tile selectedTile
Tile last selected by the player.

icon

protected javax.swing.ImageIcon icon
Player's selected icon.

playArea

protected PlayArea playArea
Reference to the playArea.

userGUI

protected UserGUI userGUI
Reference to the userGUI.

payout

Payout payout
Reference to the Game's payout

playerId

protected int playerId
Identifies the location of the player.
Constructor Detail

Player

public Player(java.lang.String name,
              javax.swing.ImageIcon icon,
              int score,
              int playerId)
Initialises the Player's name, icon, inserts the initial score and the player id.

Parameters:
name - Name of the player.
icon - Player's selected icon.
score - Initial score of the player.
playerId - Player's ID.
Method Detail

initPlayer

public void initPlayer(Payout payout)
Re-initialises the classes fishing and standing hand attributes and the player's Hand at the beginning of each hand.

Parameters:
payout - class for this hand

insertTile

public void insertTile(Tile[] tile,
                       int insertAmount)
Insert a list of tiles into the player's Hand, and updates the PlayArea with the changes.

Parameters:
tile - List of tiles to insert.
insertAmount - Amount of tiles to insert.

insertTile

public void insertTile(Tile tile)
Inserts the given tile into the player's Hand, and updates the PlayArea with the changes.

Parameters:
tile - Tile to insert.

discard

public void discard(Tile lastDiscard)
Removes the given tile in the player's Hand and updates the PlayArea with the changes.

Parameters:
lastDiscard - Tile to remove.

runKong

public void runKong(Tile lastDiscard)
Exposes a Kong from the player's concealed Hand with the given discard. The discard tile is removed from the the PlayArea and then the tiles are updated.

Parameters:
lastDiscard - Tile that will be used to make up the exposed Kong.

runChow

public void runChow(Tile lastDiscard,
                    int selection)
Exposes a Chow from the player's concealed Hand with the given discard. The discard tile is removed from the the PlayArea and then the tiles are updated.

Parameters:
lastDiscard - Tile that will be used to make up the exposed Chow.
selection - Which of the 3 Chow(chow2Down, chow2Up or chow2Sides) to run.

runPung

public void runPung(Tile lastDiscard)
Exposes a Pung from the player's concealed Hand with the given discard. The discard tile is removed from the the PlayArea and then the tiles are updated.

Parameters:
lastDiscard - Tile that will be used to make up the exposed Pung.

mahjong

public void mahjong(Game game)
This function is run when the winning player has won Mahjong. All flags in the Player are sent to the Payout class to calculate scoring.

 void mahjong() {
     if the player has a standing hand then {
         update standing hand in the payout;
     }

     run mahjong checks on Hand;
 }


runMahjong

public void runMahjong(Tile lastDiscard)
Inserts the tile into the Hand and runs mahjong with the last discarded tile.

Parameters:
lastDiscard - The last discared tile.

checkMahjong

public boolean checkMahjong(Tile lastPickUp,
                            boolean lastTile)
The function checks to see if the Hand has Mahjong after picking up tile from the Wall. If this is the case then the appropriate flags are sent to the Payout class. If the tile was the last in the Wall, the last tile flag is given.

 boolean checkMahjong(Tile lastPickUp, boolean lastTile) {
     if player is fishing and the Hand is a mahjong combination then {
         if tile is the last tile to be discarded then {
             payout.lastPickUp(last tile);
         }
         else {
             payout.lastPickUp(Wall);
         }

         return true;
     }
     else {
         return false;
     }
 }

Parameters:
lastPickUp - Last tile picked up from the Wall.
lastTile - Flag- True if last tile to be picked up from the Wall was the last tile.
Returns:
Mahjong flag.

checkFishing

public boolean checkFishing()
Checks to see if the player's Hand is fishing. If this is found to be true then the fishing flag is set and the PlayArea is updated.

Returns:
Fishing flag.

isStandingHand

public void isStandingHand()
Sets standing hand flag to true.


notStandingHand

public void notStandingHand()
Removes standing hand flag.


findKong

public boolean findKong()
Looks in the player's Hand for concealed Kongs.

Returns:
True if a concealed Kong does exist in the Hand.

checkKong

public boolean checkKong(Tile selectedTile)
Looks to see if the player can declare a concealed kong with the selected tile.

Parameters:
selectedTile - Tile selected by the player.
Returns:
True if the player can declare kong with the selected tile.

determineCanRob

public int determineCanRob(Tile selectedTile)
Determines whether the player can rob the Kong with the given tile.

Parameters:
selectedTile - Tile that has the potential to be robbed.
Returns:
Selected action of the player.

declareKong

public void declareKong(Tile selectedTile)
Exposes a concealed Kong in the player's Hand using the selected tile and updates the PlayArea.

Parameters:
selectedTile - Tiles selected to be declared.

runPung2Kong

public void runPung2Kong(Tile selectedTile)
This function is run if the player has selected to and can successfully add a tile to an exposed Pung. The tile is added to the exposed Hand and the PlayArea is updated.

Parameters:
selectedTile - Tile to add to Pung.

checkPung2Kong

public boolean checkPung2Kong(Tile selectedTile)
CheckPung2Kong checks player's Hand for an exposed Pung similar to the selected tile.

Parameters:
selectedTile - Tile selected by the player.
Returns:
True if possible pung2Kong is possible with the selected tile.

findPung2Kong

public boolean findPung2Kong()
Looks in the player's concealed and exposed Hands to determine if pung2Kong is possible.

Returns:
True if pung2Kong is possible anywhere in the Hand.

robbedKong

public void robbedKong(Tile robbedTile,
                       boolean lastTile)
RobbedKong is run if the player has successfully rob the Kong. The relevant flags sent to the Payout class.

 void robbedKong(Tile selectedTile) {
     payout.isRobbedKong();
     insert robbed tile into the payout;
     insert tile into Hand;
 }

Parameters:
selectedTile - Tile robbed from the current player.
lastTile - True if the tile was last discard of the hand.

getPlayerSelection

public int getPlayerSelection(Tile lastDiscard,
                              int next)
Retrieves a selection from the player to be sent to the Referee.

Parameters:
lastDiscard - Last discarded tile.
next - Flag that indicates whether this player can draw a tile.
Returns:
The player's selection.

getDiscard

public int getDiscard(boolean playerFishing,
                      Moves currentMove)
Retrieves the discard or special Kong move from the current player.

Parameters:
playerFishing - True if any player is fishing in the game.
currentMove - Storage for player's selected move.
Returns:
Selected move made.

getName

public java.lang.String getName()
Retrieves the player's name.

Returns:
The name of the player.

getIcon

public javax.swing.ImageIcon getIcon()
Retrieves the player's icon.

Returns:
The player's icon.

getScore

public int getScore()
Returns player's score.

Returns:
Score of the player.

getWind

public int getWind()
Returns wind of the player.

Returns:
Wind of the player.

getId

public int getId()
Returns the player's id.

Returns:
Id of the player.

setName

public void setName(java.lang.String name)
Updates the player's name, and updates the PlayArea with changes.

Parameters:
Name - of the player.

setIcon

public void setIcon(javax.swing.ImageIcon icon)
Updates the player's icon, and updates the PlayArea with changes.

Parameters:
icon - Icon of the player.

setScore

public void setScore(int score)
Updates the player's score, and updates the PlayArea with changes.

Parameters:
score - New score of the player.

setWind

public void setWind(int wind)
Updates the player's wind, and updates the PlayArea with changes.

Parameters:
wind - Wind of the player.

setPlayArea

public void setPlayArea(PlayArea playArea)
Receives a reference to the PlayArea.

Parameters:
playArea - Location of the player's tiles on the UserGUI.

setPlayArea

public void setPlayArea(PlayArea playArea,
                        UserGUI userGUI)
Receives a reference to the PlayArea and the UserGUI
Parameters:
playArea - Location of the player's tiles on the UserGUI.
userGUI - Reference to the userGUI.

setMove

public void setMove(Tile tile,
                    int move)
Inserts a selected move made by the player from the UserGUI.

Parameters:
tile - Tile selected by the player.
move - Move selected by the player.

setSelection

public void setSelection(int move)
Inserts the selected move that a player has chosen with the last discarded tile, if it is possible.

Parameters:
move - Selection made by the player.