java.lang.Object
it.polimi.ingsw.am13.model.player.Player
- All Implemented Interfaces:
PlayerIF
,Serializable
This class manages a player of match, storing and managing his nickname, token, field, hand cards, personal
objective, starter card, points, whether he is connected or not.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final Field
Player's field which represents the positioning of his played cards.private final List
<CardPlayable> Player's hand of cards, which could be Gold cards or Resource cards.private boolean
Whether a player is currently connected or not (for the corresponding Advanced Function)private int
The points of the player that are given by objective cards.private CardObjective
Player's personal objective.private final PlayerLobby
Player decontextualized from game.private int
Player's points counter.private final List
<CardObjective> The two objective cards among which the player can choose his personal objective.private CardStarter
Player's starter card which has been drawn to him. -
Constructor Summary
ConstructorsConstructorDescriptionPlayer
(PlayerLobby playerLobby) Constructor for the Player class.Constructor for the Player class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addCardToHand
(CardPlayable card) Add a card to player's hand.void
addObjectivePoints
(CardObjective common1, CardObjective common2) Calculate and add points for the personal and common objectives.void
addPoints
(int increment) Increment player's points counter by the given amount.void
Sets the isConnected variable to falsegetField()
int
int
void
initObjective
(CardObjectiveIF cardObj) Sets the player's personal objective.void
initPossiblePersonalObjectives
(CardObjective possiblePersonalObjective0, CardObjective possiblePersonalObjective1) Sets the two objective cards among which the player can choose his personal objective.void
initStarter
(CardStarter cardStr) Sets the drawn starter card for this player.boolean
void
playCard
(CardSidePlayableIF sideToPlay, Coordinates coordToPlay) Play a card side of the player's hand on the field at given coordinates.void
playStarter
(Side side) Play the corresponding given side of the starter card on the player's field.void
Sets the isConnected variable to true
-
Field Details
-
playerLobby
Player decontextualized from game. It stores nickname and token chosen by the player -
field
Player's field which represents the positioning of his played cards. -
handCards
Player's hand of cards, which could be Gold cards or Resource cards. -
personalObjective
Player's personal objective. It affects only player's points when the game ends. -
possiblePersonalObjectives
The two objective cards among which the player can choose his personal objective. They can't change once they have been set. -
startCard
Player's starter card which has been drawn to him. It can't change once it has been set. -
points
private int pointsPlayer's points counter. Initialized with 0 -
objectivePoints
private int objectivePointsThe points of the player that are given by objective cards. They are calculated at the end and are only used to determine the winner when they both have the same total points. -
isConnected
private boolean isConnectedWhether a player is currently connected or not (for the corresponding Advanced Function)
-
-
Constructor Details
-
Player
Constructor for the Player class. It initializes nickname, token, points and starter card (it has to be drawn before creating a Player object). It also initializes an empty field for the player and the space to store the player's hand.- Parameters:
nick
- Nickname chosen by the player.token
- Token color chosen for the player.
-
Player
Constructor for the Player class. It initializes nickname, token, points and starter card (it has to be drawn before creating a Player object). It also initializes an empty field for the player and the space to store the player's hand.- Parameters:
playerLobby
- Player decontextualized from game. It has nickname and token already set.
-
-
Method Details
-
disconnectPlayer
Sets the isConnected variable to false- Throws:
ConnectionException
- if the isConnected variable was already false (repeated disconnection)
-
reconnectPlayer
Sets the isConnected variable to true- Throws:
ConnectionException
- if the isConnected variable was already true (repeated reconnection)
-
isConnected
public boolean isConnected()- Specified by:
isConnected
in interfacePlayerIF
- Returns:
- whether a player is currently connected or not
-
initStarter
Sets the drawn starter card for this player. Once set, it can't be modified!- Parameters:
cardStr
- Starter card already drawn.- Throws:
VariableAlreadySetException
- Exception is thrown if this method has been called before.
-
initPossiblePersonalObjectives
public void initPossiblePersonalObjectives(CardObjective possiblePersonalObjective0, CardObjective possiblePersonalObjective1) throws VariableAlreadySetException Sets the two objective cards among which the player can choose his personal objective. Once set, it can't be modified- Parameters:
possiblePersonalObjective0
- first possible personal objective cardspossiblePersonalObjective1
- first possible personal objective cards- Throws:
VariableAlreadySetException
- if this method has been called before
-
initObjective
public void initObjective(CardObjectiveIF cardObj) throws VariableAlreadySetException, InvalidChoiceException Sets the player's personal objective. Once set, it can't be modified!- Parameters:
cardObj
- Objective card which will be set as personal objective.- Throws:
VariableAlreadySetException
- Exception is thrown if this method has been called before.InvalidChoiceException
- if the objective card does not belong to the list of the possible objective cards
-
playStarter
Play the corresponding given side of the starter card on the player's field.- Parameters:
side
- Starter card's side chosen by the player- Throws:
InvalidPlayCardException
- Positioning error of the card at coordinates (0,0), or startCard is not yet initialized.InvalidChoiceException
-
playCard
public void playCard(CardSidePlayableIF sideToPlay, Coordinates coordToPlay) throws InvalidPlayCardException, RequirementsNotMetException Play a card side of the player's hand on the field at given coordinates. If the card can't be played an exception is thrown.- Parameters:
sideToPlay
- Card side to be played on the field.coordToPlay
- Coordinates where the card side has to be played on the field.- Throws:
InvalidPlayCardException
- Positioning error of the card at given coordinates, or startCard is not yet initialized.RequirementsNotMetException
- At least one Requirement is not satisfied for the given card.
-
addCardToHand
Add a card to player's hand. An exception is thrown if the hand is full.- Parameters:
card
- Card to be added to the hand.- Throws:
PlayerHandException
- Exception thrown when the hand is already full (it should never happen!)
-
addPoints
public void addPoints(int increment) Increment player's points counter by the given amount.- Parameters:
increment
- Number of points to add.
-
addObjectivePoints
Calculate and add points for the personal and common objectives.- Parameters:
common1
- First common objective.common2
- Second common objective.
-
getPlayerLobby
- Specified by:
getPlayerLobby
in interfacePlayerIF
- Returns:
- Player decontextualized from game. It stores nickname and token chosen by the player
-
getStarter
- Specified by:
getStarter
in interfacePlayerIF
- Returns:
- Starter card of the player. Null if player has not been assigned a starter card yet
-
getPoints
public int getPoints() -
getHandCards
- Specified by:
getHandCards
in interfacePlayerIF
- Returns:
- Player's hand of cards, which could be Gold cards or Resource cards.
-
getPersonalObjective
- Specified by:
getPersonalObjective
in interfacePlayerIF
- Returns:
- Player's personal objective. It affects only player's points when the game ends. Null if the personal objective hasn't been initialized yet
-
getPossiblePersonalObjectives
- Specified by:
getPossiblePersonalObjectives
in interfacePlayerIF
- Returns:
- the two objective cards among which the player can choose his personal objective. Null if they have not been set yet
-
getAvailableCoord
- Returns:
- The list of coordinates in which new cards can be played. If game has not started yet, the list is empty
-
getField
-
getObjectivePoints
public int getObjectivePoints()- Returns:
- the points of the player that are given by objective cards
-