Class Model

java.lang.Object
it.polimi.ingsw.Model.Model
All Implemented Interfaces:
Serializable

public class Model extends Object implements Serializable
As the name suggests, this class is the game's Model. The Model's role is to keep track of the game's state and provide the tools to modify it. This class is not able to detect changes to the underlying data. If you wish for that functionality look at ModelWrapper
See Also:
  • Field Details

  • Constructor Details

    • Model

      public Model(IslandField islandField, GameMode gameMode, StudentBag studentBag, List<PlayerBoard> playerBoards, Map<PawnColour,PlayerBoard> teachers, TeamMapper teamMap, TurnOrder turnOrder, EffectTracker effects, List<Cloud> clouds, List<CharacterCard> characterCards, int coinReserve, int coinPerPlayerBoard)
      Constructs a DEBUG ONLY version of the model, to be used for testing purposes.
      Parameters:
      islandField - provide a reference to an external IslandField
      gameMode - select the game mode
      studentBag - provide a reference to an external StudentBag
      playerBoards - provide references to external PlayerBoards
      teachers - provide a map from a PawnColour to one of the external PlayerBoards
      teamMap - provide a reference to an external TeamMapper
      turnOrder - provide a reference to an external TurnOrder
      effects - provide a reference to an external EffectTracker
      clouds - provide references to external Clouds
      characterCards - provide references to external CharacterCards
      coinReserve - select the amount of coins left in the bank
      coinPerPlayerBoard - this number times the amount of players will be subtracted from coinReserve
    • Model

      public Model(GameMode gameMode, String... playerNicknames)
      Construct a Model object
      Parameters:
      gameMode - selects the GameMode
      playerNicknames - a vararg list of String representing each player. The first nickname (at index 0) will receive ID = 0, the second ID = 1, and so on and so forth.
  • Method Details

    • refillClouds

      public void refillClouds() throws FullContainerException
      Refill the cloud tiles
      Throws:
      FullContainerException - if one or more cloud tiles were found full while trying to fill them up
    • copy

      public Model copy()
      Serializes the game model to a new object.
      Returns:
      a copy of the GameBoard object or null if the Serialization was not possible
      Note: once called, all changes to the original GameBoard object won't be reflected in the instance returned by this method
    • getSerializedModel

      private byte[] getSerializedModel() throws IOException
      Serializes the game model to a new de-serializable byte array.
      Returns:
      a copy of the GameBoard object.
      Note: once called, all changes to the original GameBoard object won't be reflected in the instance returned by this method
      Throws:
      IOException
    • getCoinReserve

      public int getCoinReserve()
      Returns:
      the amount of coins left in the bank, not yet collected by players
    • getCharacterCards

      public List<CharacterCard> getCharacterCards()
      Returns:
      an Unmodifiable List of the CharacterCards currently in the game
    • getGameMode

      public GameMode getGameMode()
      Returns:
      the GameMode this Model is running
    • getTeachers

      public Map<PawnColour,PlayerBoard> getTeachers()
      Returns:
      an Unmodifiable Map from PawnColour to PlayerBoard, mapping a teacher's colour to its owner. If the teacher has no owner, the mapping will be null.
    • getMutablePlayerBoard

      public PlayerBoard getMutablePlayerBoard(int id) throws InvalidContainerIndexException
      Accessing a PlayerBoard can only be done through its ID since the nicknames can be non-unique
      Parameters:
      id - the ID of the PlayerBoard to fetch for
      Returns:
      the fetched PlayerBoard
      Throws:
      InvalidContainerIndexException - if no board can be found matching the given ID
    • getMutableEffects

      public EffectTracker getMutableEffects()
      Returns:
      a reference to the EffectTracker
    • getWinners

      public OptionalValue<List<PlayerBoard>> getWinners()
      Returns:
      a non-empty OptionalValue containing the winners of the game if isGameOver() returns true, else an empty OptionalValue
    • isGameOver

      public boolean isGameOver()
      Checks to see if the game is over, this function should be called at the end of each complete set of changes to the Model.
      Returns:
      true if the game is over, else false.
    • getMutableTurnOrder

      public TurnOrder getMutableTurnOrder()
      Returns:
      a reference to the TurnOrder
    • getMutableIslandField

      public IslandField getMutableIslandField()
      Returns:
      a reference to the Island
    • getMutablePlayerBoardsByTeamID

      public List<PlayerBoard> getMutablePlayerBoardsByTeamID(TeamID teamID)
      In case there are 4 players, teams are enabled.
      Parameters:
      teamID - the ID of the team you wish to fetch for
      Returns:
      an Unmodifiable List of PlayerBoard/s that are part of the specified Team
    • getTeamMapper

      public TeamMapper getTeamMapper()
      Returns:
      a reference to the TeamMapper
    • getMutablePlayerBoards

      public List<PlayerBoard> getMutablePlayerBoards()
      Returns:
      an Unmodifiable List of the PlayerBoards (which can be modified)
    • getOwnTeamTeacherCount

      private int getOwnTeamTeacherCount(PlayerBoard pb)
      Parameters:
      pb - the PlayerBoard you wish to search the owned teachers of
      Returns:
      the amount of teachers linked to such player
    • getMutableStudentBag

      public StudentBag getMutableStudentBag()
      Returns:
      a reference to the StudentBag
    • getClouds

      public List<Cloud> getClouds()
      Returns:
      an Unmodifiable List of the Clouds (which can be modified)
    • getOwnTeamTeacherCount

      private int getOwnTeamTeacherCount(TeamID teamID)
      Parameters:
      teamID - the TeamID you wish to search the owned teachers of
      Returns:
      the amount of teachers linked to such team
    • getOwnTeachers

      public List<PawnColour> getOwnTeachers(PlayerBoard pb)
      Parameters:
      pb - the PlayerBoard you wish to search the owned teachers of
      Returns:
      an Unmodifiable List of the PawnColours representing the teachers owned by pb
    • moveAndActMotherNature

      public void moveAndActMotherNature(int steps)
      Mother nature can move to an island and, once moved there must act out its power
      Parameters:
      steps - the steps mother nature will take (can be both positive or negative or zero)
    • actMotherNaturePower

      public void actMotherNaturePower(IslandGroup mnp)
      Acts out mother nature's power, unifying IslandGroups adjacent to mnp
      Parameters:
      mnp - an IslandGroup representing Mother nature's position.
    • getInfluencerOf

      public OptionalValue<TeamID> getInfluencerOf(IslandGroup ig)
      Parameters:
      ig - the IslandGroup to find the influencer of
      Returns:
      the TeamID that holds influence over ig, wrapped in a OptionalValue
    • addStudentToDiningRoom

      public void addStudentToDiningRoom(PawnColour student, PlayerBoard pb) throws FullContainerException
      Adds a student to the dining room of a player.
      Parameters:
      student - the PawnColour of the student you wish to add
      pb - the PlayerBoard you wish to add student to
      Throws:
      FullContainerException - if the dining room has no more free space to fit the student
    • setTeacher

      protected void setTeacher(PawnColour teacher, PlayerBoard player)
      Given a teacher, assigns it to a player
      Parameters:
      teacher - the PawnColour of the teacher you wish to select
      player - the PlayerBoard you wish to link teacher to
    • removeStudentFromDiningRoom

      public void removeStudentFromDiningRoom(PawnColour student, PlayerBoard pb) throws EmptyContainerException
      Removes a student to the dining room of a player.
      Parameters:
      student - the PawnColour of the student you wish to remove
      pb - the PlayerBoard you wish to remove student from
      Throws:
      EmptyContainerException - if the dining room has no more students to remove
    • addCoinToReserve

      public void addCoinToReserve(int amount)
      Parameters:
      amount - the amount of currency to bring back into the bank