Package it.polimi.ingsw.Model
Class PlayerBoard
java.lang.Object
it.polimi.ingsw.Model.PlayerBoard
- All Implemented Interfaces:
Serializable
This class represents the Player's part of the board
- See Also:
-
Field Summary
Modifier and TypeFieldDescriptionprivate final AssistantCard[]
private int
private final Map<PawnColour,
Integer> private final List<OptionalValue<PawnColour>>
private final int
private final String
private static final long
-
Constructor Summary
ConstructorDescriptionPlayerBoard
(int id, int numOfPlayers, String nickname, StudentBag studentBag) Generates a board and initializes its structures -
Method Summary
Modifier and TypeMethodDescriptionprotected void
addCoin()
Adds a coin to the balancevoid
addStudentsToEntrance
(List<PawnColour> students) Add multiple students to slots in the entrancevoid
addStudentToEntrance
(PawnColour student) Add a single student to a slot in the entranceint
Get the current coin balance of the playerGet the mappings fromPawnColour
to number of students of that colour in the Dining roomint
getDiningRoomCount
(PawnColour colour) Get the amount of students in a lane of the dining roomint
Get the size of the entrance (can change depending on the number of players)int
Get the amount of free slots in the student entranceGet a list of the active slots usable in the student entranceint
getId()
Get the ID of the playerGet theAssistantCard
s linked to the playerGet the Nickname of the playerboolean
isDiningRoomFull
(PawnColour student) Check to see if the dining room can accommodate more students on a lanevoid
Removes as many coins from the balance as the cost of the paid card.removeStudentFromEntrance
(int pos) Removes a single student from the entrancevoid
removeStudentFromEntrance
(PawnColour colour) Removes a single student from the entrancevoid
setCoinBalance
(int balance) Sets the coin balance for the PlayerBoard.protected boolean
Unsafely add a student to the Dining room.void
Unsafely remove a student from the Dining room.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
nickname
-
assistantCards
-
diningRoom
-
entrance
-
id
private final int id -
coinBalance
private int coinBalance
-
-
Constructor Details
-
PlayerBoard
Generates a board and initializes its structures- Parameters:
id
- the ID of the player, used to reference the board through various classes.numOfPlayers
- when creating a board, the number of players becomes important during initialization of various internal structuresnickname
- every player has a nickname and the board can store it. Nicknames are not guaranteed to be unique, so identifying a board through nicknames is highly insecure.studentBag
- used during the initialization of the board.
-
-
Method Details
-
getMutableAssistantCards
Get theAssistantCard
s linked to the player- Returns:
- an Unmodifiable
List
ofAssistantCard
linked to the player
-
getCoinBalance
public int getCoinBalance()Get the current coin balance of the player- Returns:
- an integer representing the amount of coins owned by the player
-
setCoinBalance
public void setCoinBalance(int balance) Sets the coin balance for the PlayerBoard.
NOTE: This method should only be called by tests- Parameters:
balance
- the amount of coins you want to set thePlayerBoard
's balance to
-
getDiningRoom
Get the mappings fromPawnColour
to number of students of that colour in the Dining room- Returns:
- an Unmodifiable
Map
fromPawnColour
toInteger
-
getEntranceStudents
Get a list of the active slots usable in the student entrance- Returns:
- an Unmodifiable
List
representing each slot of the Entrance
-
getId
public int getId()Get the ID of the player- Returns:
- the ID of the PlayerBoard
-
getNickname
Get the Nickname of the player- Returns:
- the Nickname of the PlayerBoard
-
unsafeAddStudentToDiningRoom
Unsafely add a student to the Dining room. The addition is unsafe because it doesn't track gained coins or teachers. This method is used byModel.addStudentToDiningRoom(PawnColour, PlayerBoard)
which is the "safe" version.- Parameters:
colour
- the colour of the student to add to the dining room- Returns:
- true if a new coin is to be added to the player's balance
- Throws:
FullContainerException
- if the dining room is full on the lane of colour before the addition
-
isDiningRoomFull
Check to see if the dining room can accommodate more students on a lane- Parameters:
student
- selects the lane of the dining room to inspect- Returns:
- true if the dining room's lane is full, false otherwise
-
getDiningRoomCount
Get the amount of students in a lane of the dining room- Parameters:
colour
- selects the lane of the dining room to inspect- Returns:
- the count of students in the lane selected by colour
-
unsafeRemoveStudentFromDiningRoom
Unsafely remove a student from the Dining room. The removal is unsafe because it doesn't track teachers. This method is used byModel.removeStudentFromDiningRoom(PawnColour, PlayerBoard)
which is the "safe" version.- Parameters:
colour
- the colour of the student to remove the dining room- Throws:
EmptyContainerException
- if the dining room is empty on the lane of colour before the removal
-
addStudentsToEntrance
Add multiple students to slots in the entrance- Parameters:
students
- aList
ofPawnColour
containing the students to add to the entrance- Throws:
FullContainerException
- if the entrance isn's capable of holding all the students, the students are not added and the exception is thrown
-
getEntranceSpaceLeft
public int getEntranceSpaceLeft()Get the amount of free slots in the student entrance- Returns:
- the count of free slots in the entrance
-
getEntranceSize
public int getEntranceSize()Get the size of the entrance (can change depending on the number of players)- Returns:
- the size of the entrance
-
addStudentToEntrance
Add a single student to a slot in the entrance- Parameters:
student
- aPawnColour
representing the student to add to the entrance- Throws:
FullContainerException
- if the entrance isn's capable of the student, the student is not added and the exception is thrown
-
removeStudentFromEntrance
Removes a single student from the entrance- Parameters:
pos
- the index of the slot from which to remove the student- Returns:
- the
PawnColour
of the removed student - Throws:
InvalidContainerIndexException
- if the index is out of bounds or the slot was empty before removal
-
removeStudentFromEntrance
Removes a single student from the entrance- Parameters:
colour
- thePawnColour
of the student to remove from the entrance- Throws:
InvalidElementException
- if no students of the same colour could be found in the entrance
-
addCoin
protected void addCoin()Adds a coin to the balance -
payCharacterEffect
Removes as many coins from the balance as the cost of the paid card.- Parameters:
card
- theCharacterCard
to pay for- Throws:
ForbiddenOperationException
- if the balance cannot accommodate for the cost of the card
-