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 ModelObserver controller  
    protected DevelopCardDeck developCardDeck  
    protected boolean endGame  
    protected 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
    void addPlayer​(java.lang.String username)
    Adds a new player in this game
    void disconnectPlayer​(java.lang.String username)
    Sets the specified player as disconnected
    void gameStarted()
    Notify the game that the setup phase is finished
    java.util.List<java.lang.String> getOrderedPlayers()  
    PlayerBoard getPlayerBoard​(java.lang.String username)
    Returns the player board of the specified player
    int initialFaith​(java.lang.String username)
    Returns the amount of the initial faith of the specified player
    void initialMoveForward()
    Performs the initial move forward on the playerBoards that require it
    int initialResources​(java.lang.String username)
    Returns the amount of the initial resources of the specified player
    boolean isFirst​(java.lang.String username)
    Returns true if the specified player is first in the turn order
    boolean isFirstConnected​(java.lang.String username)
    Check if the specified player is the first (among of connected players)
    boolean isGameStarted()
    Returns true if the game has already started, false otherwise
    boolean isPlayerConnected​(java.lang.String username)
    Check if the specified player is connected or not
    java.lang.String nextConnectedPlayer​(java.lang.String currentPlayer)
    Returns the player that must play after the specified player (presumably the current player)
    void notifyLeaderSetup​(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 documentation
    void reconnectPlayer​(java.lang.String username)
    Sets the specified player as connected
    java.lang.String startGame()
    Starts this game
    void update​(boolean onySinglePlayer)  

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • developCardDeck

      protected final DevelopCardDeck developCardDeck
    • playerBoards

      protected final java.util.List<Pair<PlayerBoard,​java.lang.Boolean>> playerBoards
    • endGame

      protected boolean endGame
    • controller

      protected final transient ModelObserver controller
  • Constructor Details

    • Game

      public Game​(ModelObserver controller) throws java.io.IOException
      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, MaximumNumberOfPlayersException
      Adds 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 files
      MaximumNumberOfPlayersException - 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 InvalidUsernameException
      Returns 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

      public PlayerBoard getPlayerBoard​(java.lang.String username) throws InvalidUsernameException
      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, NoConnectedPlayerException
      Sets the specified player as disconnected
      Parameters:
      username - the username of the player
      Throws:
      InvalidUsernameException - if the specified player doesn't exist
      NoConnectedPlayerException
    • reconnectPlayer

      public void reconnectPlayer​(java.lang.String username) throws InvalidUsernameException
      Sets the specified player as connected
      Parameters:
      username - the username of the player
      Throws:
      InvalidUsernameException - if the specified player doesn't exist
    • isPlayerConnected

      public boolean isPlayerConnected​(java.lang.String username) throws InvalidUsernameException
      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

      public void notifyLeaderSetup​(java.lang.String username, LeaderSetup msg)
      Description copied from interface: LeaderSetupObservable
      Notify 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:
      notifyLeaderSetup in interface LeaderSetupObservable
      msg - the update object representing a leader card setup containing the initial leader cards of a player
    • update

      public void update​(boolean onySinglePlayer)
      Specified by:
      update in interface EndGameObserver