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
FieldsModifier and TypeFieldDescriptionprivate final AssistantCard[]private intprivate final Map<PawnColour,Integer> private final List<OptionalValue<PawnColour>>private final intprivate final Stringprivate static final long -
Constructor Summary
ConstructorsConstructorDescriptionPlayerBoard(int id, int numOfPlayers, String nickname, StudentBag studentBag) Generates a board and initializes its structures -
Method Summary
Modifier and TypeMethodDescriptionprotected voidaddCoin()Adds a coin to the balancevoidaddStudentsToEntrance(List<PawnColour> students) Add multiple students to slots in the entrancevoidaddStudentToEntrance(PawnColour student) Add a single student to a slot in the entranceintGet the current coin balance of the playerGet the mappings fromPawnColourto number of students of that colour in the Dining roomintgetDiningRoomCount(PawnColour colour) Get the amount of students in a lane of the dining roomintGet the size of the entrance (can change depending on the number of players)intGet the amount of free slots in the student entranceGet a list of the active slots usable in the student entranceintgetId()Get the ID of the playerGet theAssistantCards linked to the playerGet the Nickname of the playerbooleanisDiningRoomFull(PawnColour student) Check to see if the dining room can accommodate more students on a lanevoidRemoves as many coins from the balance as the cost of the paid card.removeStudentFromEntrance(int pos) Removes a single student from the entrancevoidremoveStudentFromEntrance(PawnColour colour) Removes a single student from the entrancevoidsetCoinBalance(int balance) Sets the coin balance for the PlayerBoard.protected booleanUnsafely add a student to the Dining room.voidUnsafely 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 theAssistantCards linked to the player- Returns:
- an Unmodifiable
ListofAssistantCardlinked 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 fromPawnColourto number of students of that colour in the Dining room- Returns:
- an Unmodifiable
MapfromPawnColourtoInteger
-
getEntranceStudents
Get a list of the active slots usable in the student entrance- Returns:
- an Unmodifiable
Listrepresenting 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- aListofPawnColourcontaining 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- aPawnColourrepresenting 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
PawnColourof 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- thePawnColourof 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- theCharacterCardto pay for- Throws:
ForbiddenOperationException- if the balance cannot accommodate for the cost of the card
-