Package it.polimi.ingsw.eriantys.model
Class Board
java.lang.Object
it.polimi.ingsw.eriantys.model.Board
This class contains the game objects that every player can interact with.
It exposes methods which should generally be called by the
GameManager
,
including one to handle the setup of the game, one to refill the cloud tiles and one to automatically check and unify islands.-
Constructor Summary
ConstructorDescriptionBoard
(int cloudNumber, int cloudSize) Constructs aBoard
, initializing the islands, bag and cloud tiles. -
Method Summary
Modifier and TypeMethodDescriptionvoid
drawStudents
(int cloudIndex, Player recipient) Moves all the students on a cloud tile to theSchoolBoard
entrance of therecipient
.getBag()
A getter for theBag
of this game object.A helper-getter method to fulfill theBoardStatus
creation process.int
A getter for the steps required by Mother Nature pawn to reach thetarget
island.Returns theIslandGroup
whoseid
matches the specified one.int
A getter for the current number of islands.A helper-getter method to fulfill theBoardStatus
creation process.A getter for theIslandGroup
where Mother Nature is currently located.boolean
moveMotherNature
(IslandGroup destination) Returnstrue
if and only ifdestination
is a valid island, in which case the Mother Nature pawn is placed on the specified island.boolean
noEntryEnforced
(IslandGroup island) Returnstrue
if and only if the specified island has at least one no-entry tile on it, in which case the last added tile is removed and returned to theHerbGranny
character card.void
Refills the cloud tiles by taking the necessary amount of students from thebag
.void
setReturnNoEntryTile
(Consumer<Integer> returnTileFunction) Sets thereturnTile
attribute toreturnTileFunction
.void
setup()
Sets up the game by placing Mother Nature on a random island and placing a random student on each island, excluding the one with Mother Nature on it and the one opposite to it.void
unifyIslands
(IslandGroup target) Checks if the island whose id matchestarget
can be unified with any of the neighboring islands, and if so unifies them.
-
Constructor Details
-
Board
public Board(int cloudNumber, int cloudSize) Constructs aBoard
, initializing the islands, bag and cloud tiles. The number and capacity of the cloud tiles are constants inGameManager
.- Parameters:
cloudNumber
- the number of cloud tiles to be instantiatedcloudSize
- the size of each cloud tile
-
-
Method Details
-
getIsland
Returns theIslandGroup
whoseid
matches the specified one.- Parameters:
id
- the requested island's identifier- Returns:
- the
IslandGroup
whoseid
matches the specified one - Throws:
IslandNotFoundException
- if no island matching the specifiedid
can be found
-
getIslandNumber
public int getIslandNumber()A getter for the current number of islands.- Returns:
- the number of islands on the board
-
getMotherNatureIsland
A getter for theIslandGroup
where Mother Nature is currently located.- Returns:
- the
IslandGroup
where Mother Nature is currently located, ornull
if Mother Nature has not been deployed yet
-
getBag
A getter for theBag
of this game object.- Returns:
- the
Bag
containing the student discs
-
setReturnNoEntryTile
public void setReturnNoEntryTile(Consumer<Integer> returnTileFunction) throws InvalidArgumentException Sets thereturnTile
attribute toreturnTileFunction
.- Parameters:
returnTileFunction
- the desiredreturnTile
Consumer<Integer>
- Throws:
InvalidArgumentException
- ifreturnTileFunction
isnull
-
setup
Sets up the game by placing Mother Nature on a random island and placing a random student on each island, excluding the one with Mother Nature on it and the one opposite to it.- Throws:
InvalidArgumentException
- if one or more of the islands and colors used arenull
NoMovementException
- if the bag is empty- See Also:
-
drawStudents
public void drawStudents(int cloudIndex, Player recipient) throws InvalidArgumentException, NoMovementException Moves all the students on a cloud tile to theSchoolBoard
entrance of therecipient
.- Parameters:
cloudIndex
- the target cloud tile's indexrecipient
- the targetPlayer
- Throws:
InvalidArgumentException
- ifrecipient
isnull
orcloudIndex
is out of boundsNoMovementException
- if the cloud at indexcloudIndex
is empty
-
moveMotherNature
Returnstrue
if and only ifdestination
is a valid island, in which case the Mother Nature pawn is placed on the specified island.- Parameters:
destination
- the desired destination for the Mother Nature pawn- Returns:
true
if and only ifdestination
is a valid island
-
refillClouds
Refills the cloud tiles by taking the necessary amount of students from thebag
.- Throws:
InvalidArgumentException
- if the bag isnull
NoMovementException
- if the bag does not contain enough students to fill the clouds
-
noEntryEnforced
Returnstrue
if and only if the specified island has at least one no-entry tile on it, in which case the last added tile is removed and returned to theHerbGranny
character card.- Parameters:
island
- theIslandGroup
on which the no-entry tile could be placed- Returns:
true
if and only if the specified island has at least one no-entry tile on it
-
unifyIslands
public void unifyIslands(IslandGroup target) throws IslandNotFoundException, InvalidArgumentException Checks if the island whose id matchestarget
can be unified with any of the neighboring islands, and if so unifies them. This method should be called every time the player controlling an island changes.- Parameters:
target
- the target island- Throws:
IslandNotFoundException
- if the specifiedtarget
cannot be foundInvalidArgumentException
- iftarget
isnull
-
getDistanceFromMotherNature
A getter for the steps required by Mother Nature pawn to reach thetarget
island.- Parameters:
target
- the destination island- Returns:
- the number of steps required for Mother Nature to move from
the island where it is currently placed to the
target
island
-
getIslandsRepresentation
A helper-getter method to fulfill theBoardStatus
creation process.- Returns:
- a representation for the islands on the game field
-
getCloudTiles
A helper-getter method to fulfill theBoardStatus
creation process.- Returns:
- a representation for the cloud tiles on the game field
-