Class GameController
java.lang.Object
it.polimi.ingsw.Server.Controller.GameController
This class represents the controller, which manages the logic of the game, such as login, turn management, chat.
-
Field Summary
Modifier and TypeFieldDescriptionprivate Player
Player who is playing his/her turn at this very momentprivate Game
Game instance associated to the Controllerprivate final String
Controller's identifierprivate Map<ScoreCard,
CommonGoalCard> This attribute indicates a map where are stored pairs of CommonGoalCard and its relative ScoreCardLobby where players wait until the start of the gameprivate int
Maximum number of Players accepted in a gameprivate boolean
This attribute indicates if a game has been re-entered after a disconnection of the server or not -
Constructor Summary
ModifierConstructorDescriptionGameController
(String identifier) GameController creatorprivate
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 Summary
Modifier and TypeMethodDescriptionboolean
acceptPlayer
(String nickname, int maxPlayers) 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 playerGetter method for activePlayergetter method for CommonGoalCardsgetter method for GameBoardgetter method for the Game Identifiergetter method for LastTurnScores (if a player has achieved a CommonGoal)getLobby()
getter method for lobbyint
getter method for MaxPlayersgetMoveIntermediate
(String nickname) getter method for MoveIntermediategetPersonalGoalCard
(String nickname) getter method for PersonalGoalCardgetPlayerByNickname
(String nickname) getter method for PlayerByNicknamegetter method for ScoreBoardgetScoreCardsFromNickname
(String nickname) getter method for Shelfboolean
this method indicates if the game is completedboolean
Getter method for isGameEndedboolean
This method indicates if the game is preparedboolean
This method manages the move m, decided by the Playerprivate void
This method manages turn evolution during the game.This method returns a list of nicknames of the players, who are playing a game (if game isn't null), null otherwiseboolean
reEnterGame
(String nickname) Game's re-entering strategy (related to a game reloaded from a persistency file)Objects refresh following a game reloaded from a persistency file
-
Field Details
-
lobby
Lobby where players wait until the start of the game -
identifier
Controller's identifier -
game
Game instance associated to the Controller -
activePlayer
Player who is playing his/her turn at this very moment -
maxPlayers
private int maxPlayersMaximum number of Players accepted in a game -
refreshed
private boolean refreshedThis attribute indicates if a game has been re-entered after a disconnection of the server or not -
lastTurnScores
This attribute indicates a map where are stored pairs of CommonGoalCard and its relative ScoreCard
-
-
Constructor Details
-
GameController
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
getter method for the Game Identifier- Returns:
- Game's identifier
-
acceptPlayer
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 playermaxPlayers
- 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
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
getter method for GameBoard- Returns:
- Board interface if game isn't null, null otherwise
- Throws:
RemoteException
- related to RMI
-
getShelf
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
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
getter method for CommonGoalCards- Returns:
- List of CommonGoalCard interface if game isn't null, null otherwise
-
getScoreCardsFromNickname
- Parameters:
nickname
- Player's nickname- Returns:
- Player's obtained ScoreCards
-
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
getter method for ScoreBoard- Returns:
- null if game is null, Scoreboard otherwise
-
getMoveIntermediate
getter method for MoveIntermediate- Parameters:
nickname
- player's nickname- Returns:
- MoveIntermediateInterface
- Throws:
RemoteException
- related to RMI
-
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
getter method for LastTurnScores (if a player has achieved a CommonGoal)- Returns:
- a map of ScoreCard and CommonGoalCard
-
make
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
getter method for PlayerByNickname- Parameters:
nickname
- player's nickname- Returns:
- player recognized by his nickname
-
refreshEntities
Objects refresh following a game reloaded from a persistency file- Returns:
- the refreshed controller
- Throws:
RemoteException
- Related to RMI
-
reEnterGame
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
-