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
ConstructorsConstructorDescriptionBoard(int cloudNumber, int cloudSize) Constructs aBoard, initializing the islands, bag and cloud tiles. -
Method Summary
Modifier and TypeMethodDescriptionvoiddrawStudents(int cloudIndex, Player recipient) Moves all the students on a cloud tile to theSchoolBoardentrance of therecipient.getBag()A getter for theBagof this game object.A helper-getter method to fulfill theBoardStatuscreation process.intA getter for the steps required by Mother Nature pawn to reach thetargetisland.Returns theIslandGroupwhoseidmatches the specified one.intA getter for the current number of islands.A helper-getter method to fulfill theBoardStatuscreation process.A getter for theIslandGroupwhere Mother Nature is currently located.booleanmoveMotherNature(IslandGroup destination) Returnstrueif and only ifdestinationis a valid island, in which case the Mother Nature pawn is placed on the specified island.booleannoEntryEnforced(IslandGroup island) Returnstrueif 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 theHerbGrannycharacter card.voidRefills the cloud tiles by taking the necessary amount of students from thebag.voidsetReturnNoEntryTile(Consumer<Integer> returnTileFunction) Sets thereturnTileattribute toreturnTileFunction.voidsetup()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.voidunifyIslands(IslandGroup target) Checks if the island whose id matchestargetcan 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 theIslandGroupwhoseidmatches the specified one.- Parameters:
id- the requested island's identifier- Returns:
- the
IslandGroupwhoseidmatches the specified one - Throws:
IslandNotFoundException- if no island matching the specifiedidcan 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 theIslandGroupwhere Mother Nature is currently located.- Returns:
- the
IslandGroupwhere Mother Nature is currently located, ornullif Mother Nature has not been deployed yet
-
getBag
A getter for theBagof this game object.- Returns:
- the
Bagcontaining the student discs
-
setReturnNoEntryTile
public void setReturnNoEntryTile(Consumer<Integer> returnTileFunction) throws InvalidArgumentException Sets thereturnTileattribute toreturnTileFunction.- Parameters:
returnTileFunction- the desiredreturnTileConsumer<Integer>- Throws:
InvalidArgumentException- ifreturnTileFunctionisnull
-
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 arenullNoMovementException- 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 theSchoolBoardentrance of therecipient.- Parameters:
cloudIndex- the target cloud tile's indexrecipient- the targetPlayer- Throws:
InvalidArgumentException- ifrecipientisnullorcloudIndexis out of boundsNoMovementException- if the cloud at indexcloudIndexis empty
-
moveMotherNature
Returnstrueif and only ifdestinationis 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:
trueif and only ifdestinationis a valid island
-
refillClouds
Refills the cloud tiles by taking the necessary amount of students from thebag.- Throws:
InvalidArgumentException- if the bag isnullNoMovementException- if the bag does not contain enough students to fill the clouds
-
noEntryEnforced
Returnstrueif 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 theHerbGrannycharacter card.- Parameters:
island- theIslandGroupon which the no-entry tile could be placed- Returns:
trueif 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 matchestargetcan 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 specifiedtargetcannot be foundInvalidArgumentException- iftargetisnull
-
getDistanceFromMotherNature
A getter for the steps required by Mother Nature pawn to reach thetargetisland.- 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
targetisland
-
getIslandsRepresentation
A helper-getter method to fulfill theBoardStatuscreation process.- Returns:
- a representation for the islands on the game field
-
getCloudTiles
A helper-getter method to fulfill theBoardStatuscreation process.- Returns:
- a representation for the cloud tiles on the game field
-