Class GameController
java.lang.Object
it.polimi.ingsw.server.controller.GameController
public class GameController
extends java.lang.Object
Controls the flow of the setup of the game.
-
Constructor Summary
Constructors Constructor Description GameController() -
Method Summary
Modifier and Type Method Description voidaddPlayer(VirtualView client)Adds a player to the game, setting his attributes of nickname and color.protected booleancolorIsAvailable(java.lang.String chosenColor)Helper method to check color validity.protected booleancolorIsValid(java.lang.String chosenColor)Helper method to check color validity.voidcreate(VirtualView newClient)The first client that finds that no game is available then creates a new one.java.util.concurrent.ExecutorServicegetExecutorPlayerAdder()GamegetGame()java.util.ArrayList<VirtualView>getGameClients()GodControllergetGodController()java.util.ArrayList<God>getGodsDeck()TurnHandlergetTurnHandler()voidhandleGameDisconnection(java.lang.String disconnectedPlayer)Allows to notify the disconnection to the game.voidincrementClients()booleanisEnded()booleanisFull()voidjoin(VirtualView newClient)The joiner client is added to a game that is already been created.protected booleannicknameIsAvailable(java.lang.String chosenNickname)Helper method to check nickname validity.voidnotifyPlayersOfLoss(java.lang.String loserNickname)Notifies players someone lost the game.voidremoveClientObserver(VirtualView client)Removes client from observing the cells of the map.voidsetUpGame(VirtualView firstClient)Sets up game and starts the logic flow.voidwinGame(Player winner)The winner of the game is notified of his success, while the others are notified of their lose.
-
Constructor Details
-
GameController
public GameController()
-
-
Method Details
-
create
The first client that finds that no game is available then creates a new one. So the client sets up the new game and is been added to it.- Parameters:
newClient- The client that creates the new game and sets it up.
-
join
The joiner client is added to a game that is already been created.- Parameters:
newClient- The client that has just joined the game and needs to be added to it.
-
incrementClients
public void incrementClients() -
setUpGame
Sets up game and starts the logic flow.- Parameters:
firstClient- is the first connected client who creates the game.
-
addPlayer
Adds a player to the game, setting his attributes of nickname and color.- Parameters:
client- client to add.
-
removeClientObserver
Removes client from observing the cells of the map.- Parameters:
client- The client that is removed from the list of the observers.
-
colorIsValid
protected boolean colorIsValid(java.lang.String chosenColor)Helper method to check color validity. A color is valid if no one has already chosen it and if it is one of the available colors of the game: blue, white, beige.- Parameters:
chosenColor- The color chosen by the player.- Returns:
- True if the color is valid, false otherwise.
-
nicknameIsAvailable
protected boolean nicknameIsAvailable(java.lang.String chosenNickname)Helper method to check nickname validity.- Parameters:
chosenNickname- The nickname chosen by the player.- Returns:
- True if the nickname is valid, false otherwise.
-
colorIsAvailable
protected boolean colorIsAvailable(java.lang.String chosenColor)Helper method to check color validity. A color is valid if no one has already chosen it and if it is one of the available colors of the game: blue, white, beige.- Parameters:
chosenColor- The color chosen by the player.- Returns:
- True if the color is available, false otherwise.
-
winGame
The winner of the game is notified of his success, while the others are notified of their lose. The turn handler stops his flow.- Parameters:
winner- The player that has won the game.
-
getGodsDeck
-
getGame
-
getGodController
-
getTurnHandler
-
getExecutorPlayerAdder
public java.util.concurrent.ExecutorService getExecutorPlayerAdder() -
handleGameDisconnection
public void handleGameDisconnection(java.lang.String disconnectedPlayer)Allows to notify the disconnection to the game.- Parameters:
disconnectedPlayer- The player that has disconnected from the game.
-
notifyPlayersOfLoss
public void notifyPlayersOfLoss(java.lang.String loserNickname)Notifies players someone lost the game.- Parameters:
loserNickname- The nickname of the player who lost the game.
-
getGameClients
-
isFull
public boolean isFull() -
isEnded
public boolean isEnded()
-