Package it.polimi.ingsw.Model
Class Model
java.lang.Object
it.polimi.ingsw.Model.Model
- All Implemented Interfaces:
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 Summary
Modifier and TypeFieldDescriptionprivate final List<CharacterCard>
private int
private final EffectTracker
private final GameMode
private final IslandField
private final List<PlayerBoard>
private static final long
private final StudentBag
private final Map<PawnColour,
PlayerBoard> private final TeamMapper
private final TurnOrder
-
Constructor Summary
ConstructorDescriptionConstruct a Model objectModel
(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. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Acts out mother nature's power, unifyingIslandGroup
s adjacent to mnpvoid
addCoinToReserve
(int amount) void
addStudentToDiningRoom
(PawnColour student, PlayerBoard pb) Adds a student to the dining room of a player.copy()
Serializes the game model to a new object.int
getMutablePlayerBoard
(int id) Accessing aPlayerBoard
can only be done through its ID since the nicknames can be non-uniquegetMutablePlayerBoardsByTeamID
(TeamID teamID) In case there are 4 players, teams are enabled.private int
getOwnTeamTeacherCount
(TeamID teamID) private int
private byte[]
Serializes the game model to a new de-serializable byte array.boolean
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.void
moveAndActMotherNature
(int steps) Mother nature can move to an island and, once moved there must act out its powervoid
Refill the cloud tilesvoid
removeStudentFromDiningRoom
(PawnColour student, PlayerBoard pb) Removes a student to the dining room of a player.protected void
setTeacher
(PawnColour teacher, PlayerBoard player) Given a teacher, assigns it to a player
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
islandField
-
gameMode
-
studentBag
-
playerBoards
-
teachers
-
teamMap
-
turnOrder
-
effects
-
clouds
-
characterCards
-
coinReserve
private int coinReserve
-
-
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 externalIslandField
gameMode
- select the game modestudentBag
- provide a reference to an externalStudentBag
playerBoards
- provide references to externalPlayerBoard
steachers
- provide a map from aPawnColour
to one of the externalPlayerBoard
steamMap
- provide a reference to an externalTeamMapper
turnOrder
- provide a reference to an externalTurnOrder
effects
- provide a reference to an externalEffectTracker
clouds
- provide references to externalCloud
scharacterCards
- provide references to externalCharacterCard
scoinReserve
- select the amount of coins left in the bankcoinPerPlayerBoard
- this number times the amount of players will be subtracted from coinReserve
-
Model
Construct a Model object
-
-
Method Details
-
refillClouds
Refill the cloud tiles- Throws:
FullContainerException
- if one or more cloud tiles were found full while trying to fill them up
-
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
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
- Returns:
- an Unmodifiable
List
of theCharacterCard
s currently in the game
-
getGameMode
- Returns:
- the
GameMode
this Model is running
-
getTeachers
- Returns:
- an Unmodifiable
Map
fromPawnColour
toPlayerBoard
, mapping a teacher's colour to its owner. If the teacher has no owner, the mapping will be null.
-
getMutablePlayerBoard
Accessing aPlayerBoard
can only be done through its ID since the nicknames can be non-unique- Parameters:
id
- the ID of thePlayerBoard
to fetch for- Returns:
- the fetched
PlayerBoard
- Throws:
InvalidContainerIndexException
- if no board can be found matching the given ID
-
getMutableEffects
- Returns:
- a reference to the
EffectTracker
-
getWinners
- Returns:
- a non-empty
OptionalValue
containing the winners of the game ifisGameOver()
returns true, else an emptyOptionalValue
-
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
- Returns:
- a reference to the
TurnOrder
-
getMutableIslandField
- Returns:
- a reference to the
Island
-
getMutablePlayerBoardsByTeamID
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
ofPlayerBoard
/s that are part of the specified Team
-
getTeamMapper
- Returns:
- a reference to the
TeamMapper
-
getMutablePlayerBoards
- Returns:
- an Unmodifiable
List
of thePlayerBoard
s (which can be modified)
-
getOwnTeamTeacherCount
- Parameters:
pb
- thePlayerBoard
you wish to search the owned teachers of- Returns:
- the amount of teachers linked to such player
-
getMutableStudentBag
- Returns:
- a reference to the
StudentBag
-
getClouds
-
getOwnTeamTeacherCount
- Parameters:
teamID
- theTeamID
you wish to search the owned teachers of- Returns:
- the amount of teachers linked to such team
-
getOwnTeachers
- Parameters:
pb
- thePlayerBoard
you wish to search the owned teachers of- Returns:
- an Unmodifiable
List
of thePawnColour
s 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
Acts out mother nature's power, unifyingIslandGroup
s adjacent to mnp- Parameters:
mnp
- anIslandGroup
representing Mother nature's position.
-
getInfluencerOf
- Parameters:
ig
- theIslandGroup
to find the influencer of- Returns:
- the
TeamID
that holds influence over ig, wrapped in aOptionalValue
-
addStudentToDiningRoom
public void addStudentToDiningRoom(PawnColour student, PlayerBoard pb) throws FullContainerException Adds a student to the dining room of a player.- Parameters:
student
- thePawnColour
of the student you wish to addpb
- thePlayerBoard
you wish to add student to- Throws:
FullContainerException
- if the dining room has no more free space to fit the student
-
setTeacher
Given a teacher, assigns it to a player- Parameters:
teacher
- thePawnColour
of the teacher you wish to selectplayer
- thePlayerBoard
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
- thePawnColour
of the student you wish to removepb
- thePlayerBoard
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
-