Package it.polimi.ingsw.model
Class Game
java.lang.Object
it.polimi.ingsw.model.Game
- All Implemented Interfaces:
EndGameObserver,LeaderSetupObservable
- Direct Known Subclasses:
SinglePlayer
public class Game extends java.lang.Object implements LeaderSetupObservable, EndGameObserver
Represents a game
-
Field Summary
Fields Modifier and Type Field Description protected ModelObservercontrollerprotected DevelopCardDeckdevelopCardDeckprotected booleanendGameprotected java.util.List<Pair<PlayerBoard,java.lang.Boolean>>playerBoards -
Constructor Summary
Constructors Constructor Description Game(ModelObserver controller)Create a new multi player game -
Method Summary
Modifier and Type Method Description voidaddPlayer(java.lang.String username)Adds a new player in this gamevoiddisconnectPlayer(java.lang.String username)Sets the specified player as disconnectedvoidgameStarted()Notify the game that the setup phase is finishedjava.util.List<java.lang.String>getOrderedPlayers()PlayerBoardgetPlayerBoard(java.lang.String username)Returns the player board of the specified playerintinitialFaith(java.lang.String username)Returns the amount of the initial faith of the specified playervoidinitialMoveForward()Performs the initial move forward on the playerBoards that require itintinitialResources(java.lang.String username)Returns the amount of the initial resources of the specified playerbooleanisFirst(java.lang.String username)Returns true if the specified player is first in the turn orderbooleanisFirstConnected(java.lang.String username)Check if the specified player is the first (among of connected players)booleanisGameStarted()Returns true if the game has already started, false otherwisebooleanisPlayerConnected(java.lang.String username)Check if the specified player is connected or notjava.lang.StringnextConnectedPlayer(java.lang.String currentPlayer)Returns the player that must play after the specified player (presumably the current player)voidnotifyLeaderSetup(java.lang.String username, LeaderSetup msg)Notify the model observers that initial leaders have been chosen Along with the notification sends the proper update Object as further explained in project documentationvoidreconnectPlayer(java.lang.String username)Sets the specified player as connectedjava.lang.StringstartGame()Starts this gamevoidupdate(boolean onySinglePlayer)Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Field Details
-
developCardDeck
-
playerBoards
-
endGame
protected boolean endGame -
controller
-
-
Constructor Details
-
Game
Create a new multi player game- Parameters:
controller- the observer of the model- Throws:
java.io.IOException- if there are some problems loading the configuration files
-
-
Method Details
-
addPlayer
public void addPlayer(java.lang.String username) throws java.io.IOException, MaximumNumberOfPlayersExceptionAdds a new player in this game- Parameters:
username- username of the new player- Throws:
java.io.IOException- if there are some problems loading the configuration filesMaximumNumberOfPlayersException- there are already four players in this game
-
startGame
public java.lang.String startGame()Starts this game- Returns:
- the username of the first player
-
initialMoveForward
public void initialMoveForward()Performs the initial move forward on the playerBoards that require it -
nextConnectedPlayer
public java.lang.String nextConnectedPlayer(java.lang.String currentPlayer) throws InvalidUsernameExceptionReturns the player that must play after the specified player (presumably the current player)- Parameters:
currentPlayer- username of the current player- Returns:
- username of next connected player
- Throws:
InvalidUsernameException- if the specified player doesn't exist
-
initialResources
public int initialResources(java.lang.String username)Returns the amount of the initial resources of the specified player- Parameters:
username- the username of the player- Returns:
- resources' number
-
initialFaith
public int initialFaith(java.lang.String username)Returns the amount of the initial faith of the specified player- Parameters:
username- the username of the player- Returns:
- faith' number
-
getPlayerBoard
Returns the player board of the specified player- Parameters:
username- the username of the player- Returns:
- the player board of the player
- Throws:
InvalidUsernameException- if the specified player doesn't exist
-
getOrderedPlayers
public java.util.List<java.lang.String> getOrderedPlayers()- Returns:
- ordered usernames of all the payers in this game
-
disconnectPlayer
public void disconnectPlayer(java.lang.String username) throws InvalidUsernameException, NoConnectedPlayerExceptionSets the specified player as disconnected- Parameters:
username- the username of the player- Throws:
InvalidUsernameException- if the specified player doesn't existNoConnectedPlayerException
-
reconnectPlayer
Sets the specified player as connected- Parameters:
username- the username of the player- Throws:
InvalidUsernameException- if the specified player doesn't exist
-
isPlayerConnected
Check if the specified player is connected or not- Parameters:
username- the username of the player- Returns:
- true if player is connected, false otherwise
- Throws:
InvalidUsernameException- if the specified player doesn't exist
-
isFirstConnected
public boolean isFirstConnected(java.lang.String username)Check if the specified player is the first (among of connected players)- Parameters:
username- the username of the player- Returns:
- true if player is the first, false otherwise
-
isFirst
public boolean isFirst(java.lang.String username)Returns true if the specified player is first in the turn order- Parameters:
username- , username of the player of which to verify the property- Returns:
- true if the specified player is first in the turn order
-
gameStarted
public void gameStarted()Notify the game that the setup phase is finished -
isGameStarted
public boolean isGameStarted()Returns true if the game has already started, false otherwise- Returns:
- true if the game has already started
-
notifyLeaderSetup
Description copied from interface:LeaderSetupObservableNotify the model observers that initial leaders have been chosen Along with the notification sends the proper update Object as further explained in project documentation- Specified by:
notifyLeaderSetupin interfaceLeaderSetupObservablemsg- the update object representing a leader card setup containing the initial leader cards of a player
-
update
public void update(boolean onySinglePlayer)- Specified by:
updatein interfaceEndGameObserver
-