Package it.polimi.ingsw.Model
Class IslandGroup
java.lang.Object
it.polimi.ingsw.Model.IslandGroup
- All Implemented Interfaces:
Serializable
Every
Island can be contained in an IslandGroup and multiple Islands can be grouped up.- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final Stack<NoEntryTile>private static final long -
Constructor Summary
ConstructorsConstructorDescriptionConstruct an IslandGroup starting from a singleIslandIslandGroup(IslandGroup... islandGroups) Construct a new amalgamation of groups. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddNoEntry(NoEntryTile tile) adds aNoEntryTileto the groupbooleancanJoin(IslandGroup... groups) returns true if the inputtedIslandGroupall contain the same type of towerbooleanChecks to see if an island is contained in the groupintgetId()Get the colour of the towers stored on the islands.intvoidremoves aNoEntryTilefrom the stack of tiles and puts it back on the character card where it came fromvoidmultipleTowers may need to be swapped or added during the Group's lifespan, this method can be used for that
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
id
private final int id -
islands
-
noEntryTiles
-
-
Constructor Details
-
IslandGroup
Construct an IslandGroup starting from a singleIsland- Parameters:
i- a singleIsland, itsIsland.getId()becomes the group's ID
-
IslandGroup
Construct a new amalgamation of groups. The new group contains the sum of all thePawnColouron each group, the sum of theNoEntryTiles on each group. Groups can only be joined if theirTower.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
returns true if the inputtedIslandGroupall contain the same type of tower- Parameters:
groups- the groups you'd like to join
-
getMutableIslands
-
getMutableNoEntryTiles
- Returns:
- an unmodifiable
Listcontaining all theNoEntryTiles 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
Get the colour of the towers stored on the islands.- Returns:
- a non empty
OptionalValuecontaining theTowerColour, if present. Note: if at least an island doesn't match theTowerColourof the others, this method will return an emptyOptionalValue.
-
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
- Returns:
- an unmodifiable
MapaPawnColourto the amount of students of that colour in the group.
-
getStudents
- Returns:
- an unmodifiable
Listcontaining all thePawnColours in the group.
-
contains
Checks to see if an island is contained in the group- Parameters:
i- theIslandyou wish to search for in the group- Returns:
- true if the island is contained, false otherwise
-
addNoEntry
adds aNoEntryTileto the group- Parameters:
tile- the no entry tile to add
-
resetNoEntry
public void resetNoEntry()removes aNoEntryTilefrom the stack of tiles and puts it back on the character card where it came from -
swapTower
multipleTowers may need to be swapped or added during the Group's lifespan, this method can be used for that- Parameters:
ts- the newTowerStoragewhere 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.
-