Package it.polimi.ingsw.eriantys.model
Class GameManager
java.lang.Object
it.polimi.ingsw.eriantys.model.GameManager
This class represents the current state of a game, including all game objects and participating players. It exposes
various modifier methods, which are only meant to be called by the controller, as
GameManager constitutes the
only access point to the model. It also exposes observer methods, which return representations of the desired game
objects based solely on java.util classes and interfaces, such as List and Map: this ensures
that the internal structure of the model is not exposed.-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionGameManager(List<String> nicknames, boolean expertMode) Constructs aGameManagerthat fits the number of players and the selected game mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidCancels the effect of the desired character card at the end of the current turn.voidchangeInfluenceState(InfluenceCalculator calculator) A method to change the internal influence calculation definition for theInfluenceCalculatorstate pattern.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.coinsRepresentation(String username) A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.diningRoomRepresentation(String username) A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.entranceRepresentation(String username) A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A getter for each player's remaining assistant cards.A controller-dedicated getter for aListcontaining the turn order of the current round.A getter for the winner of the game.booleanhandleAssistantCards(Map<String, String> playedCards) A method to process the assistant cards chosen by the players in the current round.booleanhandleCharacterCard(int index, com.google.gson.JsonObject params) Applies the effect of the desired character card with the specifiedparams.booleanhandleMotherNatureMovement(String islandDestination) Moves the Mother Nature pawn to the specified destination island, then resolves that island.voidhandleMovedStudent(String nickname, String studentColor, String destination) voidhandleSelectedCloud(String nickname, int cloudIndex) Transfers all the students in the specified cloud tile to the specified player's entrance.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.booleanresolve(IslandGroup island) Sets the specifiedIslandGroup's controller to the player with the most influence on the island.voidsetCurrentPlayer(String currentPlayerNickname) Sets the current player to the player matchingcurrentPlayerNickname.voidPrepares the game by setting up the board and, if the game is in expert mode, the selected character cards.voidPrepares the game by setting up every player's school board entrance, filling it with the appropriate number of student discs.voidsetupPlayer(String nickname, String towerColorLiteral, String wizardLiteral) A method to complete the setup of aPlayerin the game.booleanPrepares the board for a new round to be played by refilling the cloud tiles.towerColorRepresentation(String username) A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.towersRepresentation(String username) A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.
-
Field Details
-
constants
-
-
Constructor Details
-
GameManager
Constructs aGameManagerthat fits the number of players and the selected game mode.- Parameters:
nicknames- the nicknames of the playersexpertMode-trueif and only if the instantiated game is to be played in expert mode
-
-
Method Details
-
setCurrentPlayer
Sets the current player to the player matchingcurrentPlayerNickname.- Parameters:
currentPlayerNickname- the nickname of the current player- Throws:
InvalidArgumentException- if the passed parameter isnull
-
setupBoard
Prepares the game by setting up the board and, if the game is in expert mode, the selected character cards.- Throws:
InvalidArgumentException- if an error occurs while setting up the board or the character cardsNoMovementException- if an error occurs while setting up the character cards
-
setupEntrances
Prepares the game by setting up every player's school board entrance, filling it with the appropriate number of student discs.- Throws:
InvalidArgumentException- if an error occurs during one of the movements
-
setupPlayer
public void setupPlayer(String nickname, String towerColorLiteral, String wizardLiteral) throws InvalidArgumentException A method to complete the setup of aPlayerin the game.- Parameters:
nickname- thePlayer's nicknametowerColorLiteral- the string value of theTowerColorwhich thePlayerselectedwizardLiteral- the string value of theWizardwhich thePlayerselected- Throws:
InvalidArgumentException- if no player matches the specified nickname or if at least one of the enum literals is not a legal value.
-
setupRound
Prepares the board for a new round to be played by refilling the cloud tiles.- Returns:
trueif and only if the current round will be the last in the game- Throws:
InvalidArgumentException- if an error occurs while refilling the cloud tilesNoMovementException- if an error occurs while refilling the cloud tiles
-
getAvailableAssistantCards
A getter for each player's remaining assistant cards.- Returns:
- a
Maphaving the nickname of every player as key set and each player's remaining assistant cards as values
-
handleAssistantCards
A method to process the assistant cards chosen by the players in the current round. -
getTurnOrder
A controller-dedicated getter for aListcontaining the turn order of the current round.- Returns:
- the reference to a
Listcontaining the nicknames of the players and stating the turn order
-
handleMovedStudent
public void handleMovedStudent(String nickname, String studentColor, String destination) throws NoMovementException, IslandNotFoundException, InvalidArgumentException Receives aStringcorresponding to theColorof the student that the player wants to move and aStringrepresenting the destination. The destination can be an island (ID of theIslandGroup) or the dining room of a player (constant inconstants).- Parameters:
nickname- the nickname of thePlayermoving the studentstudentColor- the string corresponding to the name of theColordestination- the string representing the destination- Throws:
NoMovementException- if an error occurs while moving the studentIslandNotFoundException- if the specified island cannot be foundInvalidArgumentException- if no player matches the specified nickname or noColormatches the specified color
-
handleMotherNatureMovement
public boolean handleMotherNatureMovement(String islandDestination) throws IslandNotFoundException, InvalidArgumentException, NotEnoughMovementsException Moves the Mother Nature pawn to the specified destination island, then resolves that island.- Parameters:
islandDestination- the destinationIslandGroup- Returns:
trueif and only if the game ends as a result of Mother Nature's movement- Throws:
IslandNotFoundException- if no island matching the specified id can be foundInvalidArgumentException- if an error occurs while resolving the destination islandNotEnoughMovementsException- if the player performing this action does not have enough Mother Nature movements in order to complete it
-
resolve
Sets the specifiedIslandGroup's controller to the player with the most influence on the island.- Parameters:
island- the island whose controller is set- Returns:
trueif and only if the island's controller has changed as a result of this method- Throws:
InvalidArgumentException- if an error occurs while calculating a player's influence
-
handleSelectedCloud
public void handleSelectedCloud(String nickname, int cloudIndex) throws InvalidArgumentException, NoMovementException Transfers all the students in the specified cloud tile to the specified player's entrance.- Parameters:
nickname- the nickname of the player whose entrance will be refilledcloudIndex- the index of the cloud tile to be emptied- Throws:
InvalidArgumentException- if there is no such player with the specified nickname, or if the requested cloud tile index is out of boundsNoMovementException- if the selected cloud is empty
-
changeInfluenceState
A method to change the internal influence calculation definition for theInfluenceCalculatorstate pattern.- Parameters:
calculator- the new state (i.e., a concrete instance) forInfluenceCalculator- Throws:
InvalidArgumentException- if the passed parameter isnull
-
handleCharacterCard
public boolean handleCharacterCard(int index, com.google.gson.JsonObject params) throws ItemNotAvailableException, NoMovementException, InvalidArgumentException, DuplicateNoEntryTileException Applies the effect of the desired character card with the specifiedparams.- Parameters:
index- the index of the desired character cardparams- the parameters for the application of the specified character card's effect- Returns:
trueif and only if the current round will be the last in the game- Throws:
ItemNotAvailableException- if an error has occurred while removing a no-entry tile from an islandNoMovementException- if an error has occurred while moving one or more studentsInvalidArgumentException- if an error has occurred while applying the card's effectDuplicateNoEntryTileException- if an error has occurred while placing a no-entry tile on an island
-
cancelCharacterCardEffect
Cancels the effect of the desired character card at the end of the current turn.- Throws:
InvalidArgumentException- if an error has occurred while canceling the card's effect
-
getWinner
A getter for the winner of the game.- Returns:
- the nickname of the winner of the game, or
nullif no winner has been declared yet
-
entranceRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
username- the username of the target player- Returns:
- a representation for the entrance of the specified player
- See Also:
-
diningRoomRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
username- the username of the target player- Returns:
- a representation for the dining room of the specified player
- See Also:
-
towerColorRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
username- the username of the target player- Returns:
- a representation for the tower color of the specified player
-
towersRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
username- the username of the target player- Returns:
- a representation for the number of towers on the school board of the specified player
-
coinsRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
username- the username of the target player- Returns:
- a representation for the number of coins owned by the specified player,
or
nullif the game is not set on expert mode
-
islandsRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Returns:
- a representation for the islands on the game board
- See Also:
-
islandSizeRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
isle- the identifier of the target isle- Returns:
- a representation for the aggregate size
- See Also:
-
islandStudentsRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
isle- the identifier of the target isle- Returns:
- a representation for the students on the specified aggregate
- See Also:
-
islandControllerRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
isle- the identifier of the target isle- Returns:
- a representation for the username of the controller of the specified aggregate
-
motherNatureIslandRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Returns:
- a representation for the identifier of the aggregate on which Mother Nature is currently placed
-
islandNoEntryTilesRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
isle- the identifier of the target isle- Returns:
- a representation for the number of no-entry tiles placed on the specified aggregate if and only if expert mode is enabled
- See Also:
-
cloudTilesRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Returns:
- a representation for the cloud tiles on the game board
- See Also:
-
professorsRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Returns:
- a representation for the username of the owner, when existent, of the game professors
- See Also:
-
charactersRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Returns:
- a representation for the character cards of the game if and only if expert mode is enabled
- See Also:
-
characterCostRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
c- the target character card literal- Returns:
- a representation for the cost of the specified character card if and only if expert mode is enabled
-
characterStudentsRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
c- the target character card literal- Returns:
- a representation for the students on the specified character card if and only if expert mode is enabled
- See Also:
-
characterNoEntryTilesRepresentation
A method called byBoardStatusin order to obtain a view-oriented representation within the MVC pattern for the game.- Parameters:
c- the target character card literal- Returns:
- a representation for the number of no-entry tiles placed on the Herb Granny character card
if and only if expert mode is enabled and the target literal coincide with
CharacterCard.getName()return value
-