Class GameController

java.lang.Object
it.polimi.ingsw.Server.Controller.GameController

public class GameController extends Object
This class represents the controller, which manages the logic of the game, such as login, turn management, chat.
  • Field Details

    • lobby

      private final List<String> lobby
      Lobby where players wait until the start of the game
    • identifier

      private final String identifier
      Controller's identifier
    • game

      private Game game
      Game instance associated to the Controller
    • activePlayer

      private Player activePlayer
      Player who is playing his/her turn at this very moment
    • maxPlayers

      private int maxPlayers
      Maximum number of Players accepted in a game
    • refreshed

      private boolean refreshed
      This attribute indicates if a game has been re-entered after a disconnection of the server or not
    • lastTurnScores

      private Map<ScoreCard,CommonGoalCard> lastTurnScores
      This attribute indicates a map where are stored pairs of CommonGoalCard and its relative ScoreCard
  • Constructor Details

    • GameController

      public GameController(String identifier)
      GameController creator
      Parameters:
      identifier - ID of this Controller
    • GameController

      private GameController(List<String> lobby, String identifier, Game game, Player activePlayer, int maxPlayers, boolean refreshed, Map<ScoreCard,CommonGoalCard> lastTurnScores)
      Related to Game's refresh strategy
  • Method Details

    • getIdentifier

      public String getIdentifier()
      getter method for the Game Identifier
      Returns:
      Game's identifier
    • acceptPlayer

      public boolean acceptPlayer(String nickname, int maxPlayers) throws Exception
      This method accepts a new Player in the lobby, if his/her nickname is a regular expression of alphanumeric strings and if the number of players waiting in the lobby is less than the maxPlayers number, chosed by the first player
      Parameters:
      nickname - nickname chosen by the player
      maxPlayers - maximum number of players chosen by the first player
      Returns:
      true if the player has been accepted, false otherwise
      Throws:
      Exception - if prepareGame() or newPlayer() return an Exception
    • getLobby

      public List<String> getLobby()
      getter method for lobby
      Returns:
      List of nicknames (players who are waiting in the lobby)
    • getMaxPlayers

      public int getMaxPlayers()
      getter method for MaxPlayers
      Returns:
      maxPlayers
    • isGamePrepared

      public boolean isGamePrepared()
      This method indicates if the game is prepared
      Returns:
      false if the game doesn't exist or the game isn't prepared, true otherwise
    • getGameBoard

      public BoardInterface getGameBoard() throws RemoteException
      getter method for GameBoard
      Returns:
      Board interface if game isn't null, null otherwise
      Throws:
      RemoteException - related to RMI
    • getShelf

      public ShelfInterface getShelf(String nickname)
      getter method for Shelf
      Parameters:
      nickname - player's nickname
      Returns:
      Shelf interface of the player with this nickname (if game isn't null), null otherwise
    • getPersonalGoalCard

      public PersonalGoalCardInterface getPersonalGoalCard(String nickname)
      getter method for PersonalGoalCard
      Parameters:
      nickname - player's nickname
      Returns:
      PersonalGoalCard interface of the player with this nickname (if game isn't null), null otherwise
    • getCommonGoalCards

      public List<CommonGoalCardInterface> getCommonGoalCards()
      getter method for CommonGoalCards
      Returns:
      List of CommonGoalCard interface if game isn't null, null otherwise
    • getScoreCardsFromNickname

      public Stack<ScoreCard> getScoreCardsFromNickname(String nickname)
      Parameters:
      nickname - Player's nickname
      Returns:
      Player's obtained ScoreCards
    • 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
    • getScoreboard

      public Scoreboard getScoreboard()
      getter method for ScoreBoard
      Returns:
      null if game is null, Scoreboard otherwise
    • getMoveIntermediate

      public MoveIntermediateInterface getMoveIntermediate(String nickname) throws RemoteException
      getter method for MoveIntermediate
      Parameters:
      nickname - player's nickname
      Returns:
      MoveIntermediateInterface
      Throws:
      RemoteException - related to RMI
    • getActivePlayer

      public Player getActivePlayer()
      Getter method for activePlayer
      Returns:
      activePlayer
    • nextPlayer

      private void nextPlayer()
      This method manages turn evolution during the game. Turn order is decided in class Game.
    • getLastTurnScores

      public Map<ScoreCard,CommonGoalCard> getLastTurnScores()
      getter method for LastTurnScores (if a player has achieved a CommonGoal)
      Returns:
      a map of ScoreCard and CommonGoalCard
    • make

      public boolean make(Move m) throws Exception
      This method manages the move m, decided by the Player
      Parameters:
      m - Move
      Returns:
      true if move has been correctly accomplished, false otherwise
      Throws:
      Exception - if updateScore() in gameComplete() throws an Exception
    • isGameEnded

      public boolean isGameEnded()
      Getter method for isGameEnded
      Returns:
      true if the game has ended, false otherwise
    • isGameComplete

      public boolean isGameComplete()
      this method indicates if the game is completed
      Returns:
      false if game is null or isn't completed, true otherwise
    • getPlayerByNickname

      public Player getPlayerByNickname(String nickname)
      getter method for PlayerByNickname
      Parameters:
      nickname - player's nickname
      Returns:
      player recognized by his nickname
    • refreshEntities

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

      public boolean reEnterGame(String nickname)
      Game's re-entering strategy (related to a game reloaded from a persistency file)
      Parameters:
      nickname - of the player
      Returns:
      completion of the admission phase