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 Details

  • Method Details

    • create

      public void create​(VirtualView newClient)
      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

      public void join​(VirtualView newClient)
      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

      public void setUpGame​(VirtualView firstClient)
      Sets up game and starts the logic flow.
      Parameters:
      firstClient - is the first connected client who creates the game.
    • addPlayer

      public void addPlayer​(VirtualView client)
      Adds a player to the game, setting his attributes of nickname and color.
      Parameters:
      client - client to add.
    • removeClientObserver

      public void removeClientObserver​(VirtualView client)
      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

      public void winGame​(Player winner)
      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

      public java.util.ArrayList<God> getGodsDeck()
    • getGame

      public Game getGame()
    • getGodController

      public GodController getGodController()
    • getTurnHandler

      public TurnHandler 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

      public java.util.ArrayList<VirtualView> getGameClients()
    • isFull

      public boolean isFull()
    • isEnded

      public boolean isEnded()