|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Object | +--au.com.solidsoftware.multimahjong.mmc.game.Player
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.
| 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 |
|
| Field Detail |
public static final int EAST
public static final int SOUTH
public static final int WEST
public static final int NORTH
public static final int NO_MOVE
public static final int PICKUP
public static final int CHOW2SIDES
public static final int CHOW2DOWN
public static final int CHOW2UP
public static final int PUNG
public static final int KONG
public static final int MAHJONG
public static final int DISCARD
public static final int DECLARED_KONG
public static final int EXTEND_PUNG
public static final int EITHER_MOVE
public static final int NOT_ROBBED
public static final int ROBBED_KONG
public static final int WONT_ROB
protected boolean isFishing
protected boolean standingHand
protected Hand playerHand
protected java.lang.String name
protected int score
protected int wind
protected Tile selectedTile
protected javax.swing.ImageIcon icon
protected PlayArea playArea
protected UserGUI userGUI
Payout payout
protected int playerId
| Constructor Detail |
public Player(java.lang.String name,
javax.swing.ImageIcon icon,
int score,
int playerId)
name - Name of the player.icon - Player's selected icon.score - Initial score of the player.playerId - Player's ID.| Method Detail |
public void initPlayer(Payout payout)
Hand at the beginning of
each hand.
payout - class for this hand
public void insertTile(Tile[] tile,
int insertAmount)
Hand, and updates
the PlayArea with the changes.tile - List of tiles to insert.insertAmount - Amount of tiles to insert.public void insertTile(Tile tile)
Hand, and updates
the PlayArea with the changes.tile - Tile to insert.public void discard(Tile lastDiscard)
Hand and updates the
PlayArea with the changes.lastDiscard - Tile to remove.public void runKong(Tile lastDiscard)
Hand with the
given discard. The discard tile is removed from the
the PlayArea and then the tiles are updated.lastDiscard - Tile that will be used to make up the exposed Kong.
public void runChow(Tile lastDiscard,
int selection)
Hand with the
given discard. The discard tile is removed from the
the PlayArea and then the tiles are updated.lastDiscard - Tile that will be used to make up the exposed Chow.selection - Which of the 3 Chow(chow2Down, chow2Up or chow2Sides) to
run.public void runPung(Tile lastDiscard)
Hand with the
given discard. The discard tile is removed from the
the PlayArea and then the tiles are updated.lastDiscard - Tile that will be used to make up the exposed Pung.public void mahjong(Game game)
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;
}
public void runMahjong(Tile lastDiscard)
Hand and runs mahjong with the
last discarded tile.lastDiscard - The last discared tile.
public boolean checkMahjong(Tile lastPickUp,
boolean lastTile)
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;
}
}
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.public boolean checkFishing()
Hand is fishing. If this is
found to be true then the fishing flag is set and the
PlayArea is updated.public void isStandingHand()
public void notStandingHand()
public boolean findKong()
Hand for concealed Kongs.public boolean checkKong(Tile selectedTile)
selectedTile - Tile selected by the player.public int determineCanRob(Tile selectedTile)
selectedTile - Tile that has the potential to be robbed.public void declareKong(Tile selectedTile)
Hand using the
selected tile and updates the PlayArea.selectedTile - Tiles selected to be declared.public void runPung2Kong(Tile selectedTile)
Hand and the PlayArea is updated.selectedTile - Tile to add to Pung.public boolean checkPung2Kong(Tile selectedTile)
Hand for an exposed Pung
similar to the selected tile.selectedTile - Tile selected by the player.public boolean findPung2Kong()
Hands to
determine if pung2Kong is possible.
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;
}
selectedTile - Tile robbed from the current player.lastTile - True if the tile was last discard of the hand.
public int getPlayerSelection(Tile lastDiscard,
int next)
Referee.lastDiscard - Last discarded tile.next - Flag that indicates whether this player can draw
a tile.
public int getDiscard(boolean playerFishing,
Moves currentMove)
playerFishing - True if any player is fishing in the game.currentMove - Storage for player's selected move.public java.lang.String getName()
public javax.swing.ImageIcon getIcon()
public int getScore()
public int getWind()
public int getId()
public void setName(java.lang.String name)
PlayArea with
changes.Name - of the player.public void setIcon(javax.swing.ImageIcon icon)
PlayArea with
changes.icon - Icon of the player.public void setScore(int score)
PlayArea with
changes.score - New score of the player.public void setWind(int wind)
PlayArea with
changes.wind - Wind of the player.public void setPlayArea(PlayArea playArea)
PlayArea.playArea - Location of the player's tiles on the UserGUI.
public void setPlayArea(PlayArea playArea,
UserGUI userGUI)
PlayArea and the
UserGUIplayArea - Location of the player's tiles on the UserGUI.userGUI - Reference to the userGUI.
public void setMove(Tile tile,
int move)
UserGUI. tile - Tile selected by the player.move - Move selected by the player.public void setSelection(int move)
move - Selection made by the player.
|
||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||