Class IslandGroup

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

public class IslandGroup extends Object implements Serializable
Every Island can be contained in an IslandGroup and multiple Islands can be grouped up.
See Also:
  • Field Details

  • Constructor Details

    • IslandGroup

      public IslandGroup(Island i)
      Construct an IslandGroup starting from a single Island
      Parameters:
      i - a single Island, its Island.getId() becomes the group's ID
    • IslandGroup

      public IslandGroup(IslandGroup... islandGroups) throws OperationException
      Construct a new amalgamation of groups. The new group contains the sum of all the PawnColour on each group, the sum of the NoEntryTiles on each group. Groups can only be joined if their Tower.getColour() returns the same value.
      The ID assigned to the new group will be the lowest between the input groups.
      Parameters:
      islandGroups - an array of groups to be merged into one
      Throws:
      OperationException - if the groups cannot be joined
  • Method Details

    • canJoin

      public boolean canJoin(IslandGroup... groups)
      returns true if the inputted IslandGroup all contain the same type of tower
      Parameters:
      groups - the groups you'd like to join
    • getMutableIslands

      public List<Island> getMutableIslands()
      Returns:
      an unmodifiable List containing all the Islands in the group. Each element on the list CAN be modified, the list itself can't.
    • getMutableNoEntryTiles

      public List<NoEntryTile> getMutableNoEntryTiles()
      Returns:
      an unmodifiable List containing all the NoEntryTiles in the group. Each element on the list CAN be modified, the list itself can't.
    • getId

      public int getId()
      Returns:
      the ID of the group
    • getTowerColour

      public OptionalValue<TowerColour> getTowerColour()
      Get the colour of the towers stored on the islands.
      Returns:
      a non empty OptionalValue containing the TowerColour, if present. Note: if at least an island doesn't match the TowerColour of the others, this method will return an empty OptionalValue.
    • getTowerCount

      public int getTowerCount()
      Returns:
      the amount of towers in the group (either 0 or equal to the number of islands in the group)
    • getStudentCount

      public Map<PawnColour,Integer> getStudentCount()
      Returns:
      an unmodifiable Map a PawnColour to the amount of students of that colour in the group.
    • getStudents

      public List<PawnColour> getStudents()
      Returns:
      an unmodifiable List containing all the PawnColours in the group.
    • contains

      public boolean contains(Island i)
      Checks to see if an island is contained in the group
      Parameters:
      i - the Island you wish to search for in the group
      Returns:
      true if the island is contained, false otherwise
    • addNoEntry

      public void addNoEntry(NoEntryTile tile)
      adds a NoEntryTile to the group
      Parameters:
      tile - the no entry tile to add
    • resetNoEntry

      public void resetNoEntry()
      removes a NoEntryTile from the stack of tiles and puts it back on the character card where it came from
    • swapTower

      public void swapTower(TowerStorage ts)
      multiple Towers may need to be swapped or added during the Group's lifespan, this method can be used for that
      Parameters:
      ts - the new TowerStorage where towers are coming from. the old towers (if any were present) will all be returned to its rightful storage automatically. If the new tower storage runs out of towers before swapping out all the towers from the group, then some islands fill be left empty while others will be full. Note that the empty islands will keep staying in the group, which is going to become un-join able.