Class Game

java.lang.Object
it.polimi.ingsw.Server.Model.Game

public class Game extends Object
This class contains general information about the current game, such as CommonGoalCards and number of Players.
  • Field Details

    • MAX_PLAYERS

      public final int MAX_PLAYERS
      final attribute, which indicates the maximum number of players who can join a game
      See Also:
    • identifier

      private final String identifier
      Identifier is the game id. It is chosen by the first player, who joins the game, and it can be used by other players to join a pre-existing game
    • players

      private final Map<Integer,Player> players
      Map used to store Players, associated to an Integer key, which indicates their position in the game
    • maxPlayers

      private final int maxPlayers
      Number of players, chosen by the first player, when he/she creates a new game
    • personalCards

      private final List<PersonalGoalCard> personalCards
      List of personalCards associated to each player
    • scoreboard

      private Scoreboard scoreboard
      Game scoreboard
    • board

      private Board board
      board used in the game
    • playerCount

      private int playerCount
      number of players who have already joined the game
    • cgCard1

      private CommonGoalCard cgCard1
      It's the first CommonGoalCard drawn for the game
    • cgCard2

      private CommonGoalCard cgCard2
      It's the second CommonGoalCard drawn for the game
    • objectCards

      private List<ObjectCard> objectCards
      Object Cards extracted in the related game
    • gameEnded

      private boolean gameEnded
      this attribute is true if a player has already filled his/her shelf, false otherwise
    • prepared

      private boolean prepared
      this attribute is true if the game has started
  • Constructor Details

    • Game

      public Game(String identifier, int maxPlayers) throws Exception
      game constructor
      Parameters:
      identifier - ID of the game, chosen by the Player who creates the game
      maxPlayers - maximum number of players, who can join the game (chosen by the first player)
      Throws:
      Exception - if the maximum number of players is higher than the MAX_PLAYERS number
    • Game

      public Game(String identifier, Map<Integer,Player> players, int maxPlayers, List<PersonalGoalCard> personalCards, Scoreboard scoreboard, Board board, int playerCount, CommonGoalCard cgCard1, CommonGoalCard cgCard2, List<ObjectCard> objectCards, boolean gameEnded, boolean prepared)
      Related to Game's refresh strategy
  • Method Details

    • getBoard

      public Board getBoard()
      Getter method for the board
      Returns:
      Board
    • getMaxPlayers

      public int getMaxPlayers()
      Getter method for the attribute, which indicates the maximum number of players, who can join the game
      Returns:
      maxPlayers
    • getPlayers

      public Map<Integer,Player> getPlayers()
      Getter method for players. An integer is associated to each Player, who is playing the game
      Returns:
      a map of Players
    • newPlayer

      public Player newPlayer(String newNickname) throws RemoteException
      This method adds a new player to "players" Map.
      Parameters:
      newNickname - player's nickname
      Returns:
      Player who's been added to players
      Throws:
      RemoteException - if the new instance of class Player hasn't been created
    • getPlayerFromNickname

      public Player getPlayerFromNickname(String nickname)
      getter method to recognize a player from nickname
      Parameters:
      nickname - player's nickname
      Returns:
      players if nickname != null, null otherwise
    • getShelfInterfaceFromNickname

      public ShelfInterface getShelfInterfaceFromNickname(String nickname)
      this method is a getter for the shelf interface obtained from nickname
      Parameters:
      nickname - player's nickname
      Returns:
      player's shelf interface
    • getPersonalGoalCardInterfaceFromNickname

      public PersonalGoalCardInterface getPersonalGoalCardInterfaceFromNickname(String nickname)
      this method is a getter of PersonalGoalCard obtained from nickname
      Parameters:
      nickname - player's nickname
      Returns:
      player's PersonalGoalCard
    • getCommonGoalCards

      public List<CommonGoalCardInterface> getCommonGoalCards()
      this method is a getter for CommonGoalCards
      Returns:
      a list of CommonGoalCards
    • getShelfFromNickname

      public Shelf getShelfFromNickname(String nickname)
      this method is a getter for player's shelf obtained from nickname
      Parameters:
      nickname - player's nickname
      Returns:
      player's shelf
    • getScoreCardsFromNickname

      public Stack<ScoreCard> getScoreCardsFromNickname(String nickname)
      this method is a getter for ScoreCards obtained from Nickname
      Parameters:
      nickname - player's nickname
      Returns:
      a stack of player's ScoreCard
    • nicknames

      public List<String> nicknames()
      This method returns a list of nicknames of the players, who are playing a game (if game isn't null), null otherwise
      Returns:
      a list of player's nicknames
    • prepareGame

      public void prepareGame() throws Exception
      This method includes setup procedures, such as drawing personal goal cards and common goal cards, choosing randomly the first player and placing ObjectCards on the board.
      Throws:
      Exception - if the number of drawn personal goal cards has exceeded the limit
    • isPrepared

      public boolean isPrepared()
      This method indicates if the game is prepared
      Returns:
      true if the game is prepared, false otherwise
    • checkEndGame

      public boolean checkEndGame(Player activePlayer) throws Exception
      This method checks if the active player has completely filled his/her shelf
      Parameters:
      activePlayer - represents the player who is playing in the current turn
      Returns:
      true if the player has filled all the spaces, false otherwise
      Throws:
      Exception - If the coordinates are invalid
    • gameComplete

      public boolean gameComplete() throws Exception
      This method is used for endgame procedures, such as final scoring.
      Returns:
      true if the game is completed, false otherwise
      Throws:
      Exception - if updateScore() throws an Exception
    • getScoreboard

      public Scoreboard getScoreboard()
      this method is a getter for attribute scoreboard
      Returns:
      scoreboard
    • isGameEnded

      public boolean isGameEnded()
      this method is a getter for attribute gameEnded
      Returns:
      true if game has ended, false otherwise
    • refreshEntities

      public Game refreshEntities() throws RemoteException
      Objects refresh following a game reloaded from a persistency file
      Returns:
      the refreshed game
      Throws:
      RemoteException - Related to RMI