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
Modifier and TypeFieldDescriptionprivate final int
private final Stack<NoEntryTile>
private static final long
-
Constructor Summary
ConstructorDescriptionConstruct an IslandGroup starting from a singleIsland
IslandGroup
(IslandGroup... islandGroups) Construct a new amalgamation of groups. -
Method Summary
Modifier and TypeMethodDescriptionvoid
addNoEntry
(NoEntryTile tile) adds aNoEntryTile
to the groupboolean
canJoin
(IslandGroup... groups) returns true if the inputtedIslandGroup
all contain the same type of towerboolean
Checks to see if an island is contained in the groupint
getId()
Get the colour of the towers stored on the islands.int
void
removes aNoEntryTile
from the stack of tiles and puts it back on the character card where it came fromvoid
multipleTower
s 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 thePawnColour
on each group, the sum of theNoEntryTile
s 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 inputtedIslandGroup
all contain the same type of tower- Parameters:
groups
- the groups you'd like to join
-
getMutableIslands
-
getMutableNoEntryTiles
- Returns:
- an unmodifiable
List
containing all theNoEntryTile
s 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
OptionalValue
containing theTowerColour
, if present. Note: if at least an island doesn't match theTowerColour
of 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
Map
aPawnColour
to the amount of students of that colour in the group.
-
getStudents
- Returns:
- an unmodifiable
List
containing all thePawnColour
s in the group.
-
contains
Checks to see if an island is contained in the group- Parameters:
i
- theIsland
you wish to search for in the group- Returns:
- true if the island is contained, false otherwise
-
addNoEntry
adds aNoEntryTile
to the group- Parameters:
tile
- the no entry tile to add
-
resetNoEntry
public void resetNoEntry()removes aNoEntryTile
from the stack of tiles and puts it back on the character card where it came from -
swapTower
multipleTower
s may need to be swapped or added during the Group's lifespan, this method can be used for that- Parameters:
ts
- the newTowerStorage
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.
-