Class GameManager

java.lang.Object
it.polimi.ingsw.eriantys.model.GameManager

public class GameManager extends Object
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 Details

  • Constructor Details

    • GameManager

      public GameManager(List<String> nicknames, boolean expertMode)
      Constructs a GameManager that fits the number of players and the selected game mode.
      Parameters:
      nicknames - the nicknames of the players
      expertMode - true if and only if the instantiated game is to be played in expert mode
  • Method Details

    • setCurrentPlayer

      public void setCurrentPlayer(String currentPlayerNickname) throws InvalidArgumentException
      Sets the current player to the player matching currentPlayerNickname.
      Parameters:
      currentPlayerNickname - the nickname of the current player
      Throws:
      InvalidArgumentException - if the passed parameter is null
    • setupBoard

      public void setupBoard() throws InvalidArgumentException, NoMovementException
      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 cards
      NoMovementException - if an error occurs while setting up the character cards
    • setupEntrances

      public void setupEntrances() throws InvalidArgumentException
      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 a Player in the game.
      Parameters:
      nickname - the Player's nickname
      towerColorLiteral - the string value of the TowerColor which the Player selected
      wizardLiteral - the string value of the Wizard which the Player selected
      Throws:
      InvalidArgumentException - if no player matches the specified nickname or if at least one of the enum literals is not a legal value.
    • setupRound

      public boolean setupRound() throws InvalidArgumentException, NoMovementException
      Prepares the board for a new round to be played by refilling the cloud tiles.
      Returns:
      true if and only if the current round will be the last in the game
      Throws:
      InvalidArgumentException - if an error occurs while refilling the cloud tiles
      NoMovementException - if an error occurs while refilling the cloud tiles
    • getAvailableAssistantCards

      public Map<String,List<String>> getAvailableAssistantCards()
      A getter for each player's remaining assistant cards.
      Returns:
      a Map having the nickname of every player as key set and each player's remaining assistant cards as values
    • handleAssistantCards

      public boolean handleAssistantCards(Map<String,String> playedCards)
      A method to process the assistant cards chosen by the players in the current round.
      Parameters:
      playedCards - a Map which associates a Player with its played assistant card String
      Returns:
      true if and only if the current round will be the last in the game
    • getTurnOrder

      public List<String> getTurnOrder()
      A controller-dedicated getter for a List containing the turn order of the current round.
      Returns:
      the reference to a List containing 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 a String corresponding to the Color of the student that the player wants to move and a String representing the destination. The destination can be an island (ID of the IslandGroup) or the dining room of a player (constant in constants).
      Parameters:
      nickname - the nickname of the Player moving the student
      studentColor - the string corresponding to the name of the Color
      destination - the string representing the destination
      Throws:
      NoMovementException - if an error occurs while moving the student
      IslandNotFoundException - if the specified island cannot be found
      InvalidArgumentException - if no player matches the specified nickname or no Color matches 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 destination IslandGroup
      Returns:
      true if 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 found
      InvalidArgumentException - if an error occurs while resolving the destination island
      NotEnoughMovementsException - if the player performing this action does not have enough Mother Nature movements in order to complete it
    • resolve

      public boolean resolve(IslandGroup island) throws InvalidArgumentException
      Sets the specified IslandGroup's controller to the player with the most influence on the island.
      Parameters:
      island - the island whose controller is set
      Returns:
      true if 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 refilled
      cloudIndex - 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 bounds
      NoMovementException - if the selected cloud is empty
    • changeInfluenceState

      public void changeInfluenceState(InfluenceCalculator calculator) throws InvalidArgumentException
      A method to change the internal influence calculation definition for the InfluenceCalculator state pattern.
      Parameters:
      calculator - the new state (i.e., a concrete instance) for InfluenceCalculator
      Throws:
      InvalidArgumentException - if the passed parameter is null
    • 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 specified params.
      Parameters:
      index - the index of the desired character card
      params - the parameters for the application of the specified character card's effect
      Returns:
      true if 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 island
      NoMovementException - if an error has occurred while moving one or more students
      InvalidArgumentException - if an error has occurred while applying the card's effect
      DuplicateNoEntryTileException - if an error has occurred while placing a no-entry tile on an island
    • cancelCharacterCardEffect

      public void cancelCharacterCardEffect() throws InvalidArgumentException
      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

      public String getWinner()
      A getter for the winner of the game.
      Returns:
      the nickname of the winner of the game, or null if no winner has been declared yet
    • entranceRepresentation

      public Map<String,Integer> entranceRepresentation(String username)
      A method called by BoardStatus in 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

      public Map<String,Integer> diningRoomRepresentation(String username)
      A method called by BoardStatus in 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

      public String towerColorRepresentation(String username)
      A method called by BoardStatus in 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

      public Integer towersRepresentation(String username)
      A method called by BoardStatus in 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

      public Integer coinsRepresentation(String username)
      A method called by BoardStatus in 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 null if the game is not set on expert mode
    • islandsRepresentation

      public List<String> islandsRepresentation()
      A method called by BoardStatus in 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

      public Integer islandSizeRepresentation(String isle)
      A method called by BoardStatus in 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

      public Map<String,Integer> islandStudentsRepresentation(String isle)
      A method called by BoardStatus in 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

      public String islandControllerRepresentation(String isle)
      A method called by BoardStatus in 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

      public String motherNatureIslandRepresentation()
      A method called by BoardStatus in 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

      public Integer islandNoEntryTilesRepresentation(String isle)
      A method called by BoardStatus in 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

      public Map<String,Map<String,Integer>> cloudTilesRepresentation()
      A method called by BoardStatus in 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

      public Map<String,String> professorsRepresentation()
      A method called by BoardStatus in 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

      public List<String> charactersRepresentation()
      A method called by BoardStatus in 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

      public Integer characterCostRepresentation(String c)
      A method called by BoardStatus in 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

      public Map<String,Integer> characterStudentsRepresentation(String c)
      A method called by BoardStatus in 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

      public Integer characterNoEntryTilesRepresentation(String c)
      A method called by BoardStatus in 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