Class PlayerBoard

java.lang.Object
it.polimi.ingsw.Model.PlayerBoard
All Implemented Interfaces:
Serializable

public class PlayerBoard extends Object implements Serializable
This class represents the Player's part of the board
See Also:
  • Field Details

  • Constructor Details

    • PlayerBoard

      public PlayerBoard(int id, int numOfPlayers, String nickname, StudentBag studentBag)
      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 structures
      nickname - 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

      public List<AssistantCard> getMutableAssistantCards()
      Get the AssistantCards linked to the player
      Returns:
      an Unmodifiable List of AssistantCard 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 the PlayerBoard's balance to
    • getDiningRoom

      public Map<PawnColour,Integer> getDiningRoom()
      Get the mappings from PawnColour to number of students of that colour in the Dining room
      Returns:
      an Unmodifiable Map from PawnColour to Integer
    • getEntranceStudents

      public List<OptionalValue<PawnColour>> 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

      public String getNickname()
      Get the Nickname of the player
      Returns:
      the Nickname of the PlayerBoard
    • unsafeAddStudentToDiningRoom

      protected boolean unsafeAddStudentToDiningRoom(PawnColour colour) throws FullContainerException
      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 by Model.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

      public boolean isDiningRoomFull(PawnColour student)
      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

      public int getDiningRoomCount(PawnColour colour)
      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

      public void unsafeRemoveStudentFromDiningRoom(PawnColour colour) throws EmptyContainerException
      Unsafely remove a student from the Dining room. The removal is unsafe because it doesn't track teachers. This method is used by Model.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

      public void addStudentsToEntrance(List<PawnColour> students) throws FullContainerException
      Add multiple students to slots in the entrance
      Parameters:
      students - a List of PawnColour 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

      public void addStudentToEntrance(PawnColour student) throws FullContainerException
      Add a single student to a slot in the entrance
      Parameters:
      student - a PawnColour 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

      public PawnColour removeStudentFromEntrance(int pos) throws InvalidContainerIndexException
      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

      public void removeStudentFromEntrance(PawnColour colour) throws InvalidElementException
      Removes a single student from the entrance
      Parameters:
      colour - the PawnColour 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

      public void payCharacterEffect(CharacterCard card) throws ForbiddenOperationException
      Removes as many coins from the balance as the cost of the paid card.
      Parameters:
      card - the CharacterCard to pay for
      Throws:
      ForbiddenOperationException - if the balance cannot accommodate for the cost of the card