Class GuiManager

java.lang.Object
it.polimi.ingsw.client.gui.GuiManager
All Implemented Interfaces:
View

public class GuiManager
extends java.lang.Object
implements View
Manages the display of requests and answers to the server. Guarantees a proper evolution of the scenes of the game.
  • Field Summary

    Fields 
    Modifier and Type Field Description
    protected static java.util.concurrent.atomic.AtomicReference<BoardClient> boardClient  
    protected static javafx.scene.Parent boardRoot  
    protected static ChooseGodController chooseGodController  
    protected static javafx.scene.Parent chooseGodRoot  
    protected static javafx.scene.Parent colorRoot  
    protected static javafx.scene.Parent connectRoot  
    protected static java.util.concurrent.atomic.AtomicBoolean isInLobby  
    protected static javafx.scene.Parent lobbyRoot  
    protected static java.lang.String myNickname  
    protected static javafx.scene.Parent nicknameRoot  
    protected static java.util.concurrent.atomic.AtomicInteger numberOfPlayers  
    protected static javafx.scene.Parent numberOfPlayersRoot  
    protected static java.util.ArrayList<PlayerClient> players  
    protected static java.util.concurrent.atomic.AtomicInteger playersConnected  
    protected static java.util.concurrent.SynchronousQueue<java.lang.Object> queue  
    protected static javafx.scene.Parent startPlayerRoot  
  • Constructor Summary

    Constructors 
    Constructor Description
    GuiManager()  
  • Method Summary

    Modifier and Type Method Description
    java.lang.String askBuildAgainDemeter()
    Asks to the player that holds Demeter as a God if he wants to build again.
    java.lang.String askBuildAgainHephaestus()
    Asks to the player that holds Hephaestus as a God if he wants to build again.
    java.lang.String askBuildAgainHestia()
    Asks to the player that holds Hestia as a God if he wants to build again.
    java.lang.String askBuildingDirection()
    This method asks the user to insert the position where he wants to build.
    java.lang.String[] askBuildingDirectionAtlas()
    This method asks to Atlas' owner to insert the position where he wants to build and what type of building.
    java.lang.String askBuildPrometheus()
    Asks to the player that holds Prometheus as a God if he wants to build before moving.
    java.lang.String askChosenWorker()
    Asks to the player which one of his worker wants to play with during the current turn.
    int[] askInitialWorkerPosition​(java.lang.String workerSex)
    This method asks the player to set his worker initial position.
    java.lang.String askMoveAgain()
    Allows to get the input of the player to move again.
    java.lang.String askMovementDirection()
    This method asks the user to insert the direction of his next movement.
    int askNumberOfPlayers()
    Asks to the creator of a game how many players will the game hold.
    java.lang.String askPlayerColor​(java.util.ArrayList<java.lang.String> availableColors)
    Asks to the player the color for the game.
    java.lang.String askPlayerGod()
    Asks to the player which God among the available ones wants to play with during the current game.
    java.lang.String askPlayerNickname()
    Asks to the player the nickname for the game.
    java.lang.String askWantToMoveEnemy()
    Allows to get the input of the player to move an enemy's worker.
    java.lang.String askWorkerToMove​(java.util.ArrayList<WorkerClient> enemyWorkers, WorkerClient myWorker)
    Allows to move one worker's enemy.
    java.lang.String challengerChooseStartPlayer()
    Asks to the challenger which player will be the starting one.
    void connectionOutcome​(boolean connected)
    Shows if the connection to the server wasn't successful.
    void createGame()
    Lets the player know he is the creator of a new game.
    java.lang.String getGodFromChallenger​(int numOfPlayers, int alreadyChosenGods)
    Lets the challenger know how many gods he still has to choose.
    java.lang.String getServerAddress()
    Asks the IP of the server where the client wants to connect to.
    void invalidInitialWorkerPosition()
    Lets the player know the position he wrote for the initial worker position was wrong.
    void joinGame​(int numberOfPlayers)
    Lets the player know the number of players for the game he's been assigned.
    boolean losingView​(java.lang.String endgameText)
    Lets player know that he has lost, and who is the winner.
    void nicknameFormatError()
    Lets the client know that the nickname entered is too long or empty.
    void notAvailableColor()
    Lets the player know that the chosen color was not available, because another player had already chosen it before.
    void notAvailableNickname()
    Tells the player that the inserted nickname was not available.
    void notifyOtherPlayerDisconnection​(java.lang.String disconnectedPlayer)
    Displays that a player has been disconnected and reason.
    void notifyPlayersOfLoss​(java.lang.String loserNickname)
    In a 3 players game, this method notifies the other players that a player has lost the game.
    void notifyValidColor()
    Notifies the player that his color choice was accepted by the server, going to the next scene.
    void notifyValidNick()
    Notifies the player that his nickname was accepted by the server, going to the next scene.
    void otherPlayerChoseGod​(java.lang.String otherPlayer, java.lang.String chosenGod)
    Lets player know the god chosen by another player.
    void otherPlayerSettingInitialWorkerPosition​(java.lang.String player)
    Lets player know that another player is choosing the initial position for his workers.
    void otherPlayerTurn​(java.lang.String currentPlayer)
    Lets player know that it's another player's turn.
    void playerChoseInvalidGod()
    Lets the player know that his God's choice was rejected by the server.
    void printBuildBlockErrorScreen()
    Points out a player is not allowed to build a block in a certain position.
    java.lang.String printBuildDecisionError()
    Asks the player if he still wants to build during this turn.
    void printBuildGeneralErrorScreen()
    Points out a player is not allowed to build.
    void printBuildInSamePositionScreen()
    Points out that a player is not allowed to build again in a certain position.
    void printCannotBuildDomeUnderneath()
    Warns user of invalid build action: he cannot build a dome underneath himself.
    void printChosenGods​(java.util.ArrayList<java.lang.String> chosenGods)
    Shows all the Gods chosen by the challenger for the current game, going to the correct scene.
    void printMap()
    This method lets the system show an updated version of the Board.
    java.lang.String printMoveDecisionError()
    Asks the player if he still wants to move during this turn.
    void printMoveErrorScreen()
    Points out the player cannot move in a certain position.
    void printStartPlayer​(java.lang.String startPlayer)
    Lets player know who is the start player.
    void selectedWorkerCannotMove​(java.lang.String sex)
    Lets the player know the selected worker cannot move.
    void setOtherPlayersInfo​(java.lang.String nickname, java.lang.String color)
    Allows to store in the client memory the general info about other players.
    boolean unableToBuildLose()
    Lets the player know he has lost the game because both of his workers cannot build.
    boolean unableToMoveLose()
    Lets the player know he has lost the game because both of his workers cannot move.
    void update​(CellClient toUpdateCell)
    Updates the cell of the board that has changed its contents.
    void waitChallengerChooseGods​(java.lang.String challenger)
    Lets player know that the challenger is choosing the gods for the game.
    void waitChallengerStartPlayer()
    Lets player know that the challenger is choosing the start player.
    void waitOtherPlayerChooseGod​(java.lang.String otherPlayer)
    Lets player know that another player is choosing his god.
    boolean winningView()
    The player has won the game, so the winning scene is going to be loaded.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • players

      protected static final java.util.ArrayList<PlayerClient> players
    • boardClient

      protected static final java.util.concurrent.atomic.AtomicReference<BoardClient> boardClient
    • numberOfPlayers

      protected static final java.util.concurrent.atomic.AtomicInteger numberOfPlayers
    • playersConnected

      protected static final java.util.concurrent.atomic.AtomicInteger playersConnected
    • isInLobby

      protected static final java.util.concurrent.atomic.AtomicBoolean isInLobby
    • queue

      protected static final java.util.concurrent.SynchronousQueue<java.lang.Object> queue
    • myNickname

      protected static java.lang.String myNickname
    • numberOfPlayersRoot

      protected static javafx.scene.Parent numberOfPlayersRoot
    • nicknameRoot

      protected static javafx.scene.Parent nicknameRoot
    • colorRoot

      protected static javafx.scene.Parent colorRoot
    • chooseGodRoot

      protected static javafx.scene.Parent chooseGodRoot
    • startPlayerRoot

      protected static javafx.scene.Parent startPlayerRoot
    • boardRoot

      protected static javafx.scene.Parent boardRoot
    • lobbyRoot

      protected static javafx.scene.Parent lobbyRoot
    • connectRoot

      protected static javafx.scene.Parent connectRoot
    • chooseGodController

      protected static ChooseGodController chooseGodController
  • Constructor Details

  • Method Details

    • getServerAddress

      public java.lang.String getServerAddress()
      Asks the IP of the server where the client wants to connect to.
      Specified by:
      getServerAddress in interface View
      Returns:
      The IP of the server to connect to.
    • connectionOutcome

      public void connectionOutcome​(boolean connected)
      Shows if the connection to the server wasn't successful.
      Specified by:
      connectionOutcome in interface View
      Parameters:
      connected - True if the connection was established, false otherwise.
    • notifyOtherPlayerDisconnection

      public void notifyOtherPlayerDisconnection​(java.lang.String disconnectedPlayer)
      Displays that a player has been disconnected and reason.
      Specified by:
      notifyOtherPlayerDisconnection in interface View
      Parameters:
      disconnectedPlayer - The name of the disconnected player.
    • joinGame

      public void joinGame​(int numberOfPlayers)
      Lets the player know the number of players for the game he's been assigned. The player in this specific case did not choose the number of players for the game, but someone else did (the so called "creator").
      Specified by:
      joinGame in interface View
      Parameters:
      numberOfPlayers - The number of players of the game the player has been assigned to.
    • createGame

      public void createGame()
      Lets the player know he is the creator of a new game. Loads the choosing number of players scene.
      Specified by:
      createGame in interface View
    • askNumberOfPlayers

      public int askNumberOfPlayers()
      Asks to the creator of a game how many players will the game hold.
      Specified by:
      askNumberOfPlayers in interface View
      Returns:
      The number of players decided by the creator player.
    • askInitialWorkerPosition

      public int[] askInitialWorkerPosition​(java.lang.String workerSex) throws java.util.InputMismatchException
      This method asks the player to set his worker initial position. It will be invoked both for the male worker and the female worker of every player.
      Specified by:
      askInitialWorkerPosition in interface View
      Parameters:
      workerSex - This is the sex of the worker to be placed on the board.
      Returns:
      Array with x,y coordinates of the chosen position.
      Throws:
      java.util.InputMismatchException
    • setOtherPlayersInfo

      public void setOtherPlayersInfo​(java.lang.String nickname, java.lang.String color)
      Allows to store in the client memory the general info about other players.
      Specified by:
      setOtherPlayersInfo in interface View
      Parameters:
      nickname - Nickname of the player to register.
      color - Color chosen by that specific player for the current game.
    • invalidInitialWorkerPosition

      public void invalidInitialWorkerPosition()
      Lets the player know the position he wrote for the initial worker position was wrong.
      Specified by:
      invalidInitialWorkerPosition in interface View
    • askPlayerNickname

      public java.lang.String askPlayerNickname()
      Asks to the player the nickname for the game.
      Specified by:
      askPlayerNickname in interface View
      Returns:
      The nickname chosen by the player.
    • notifyValidNick

      public void notifyValidNick()
      Notifies the player that his nickname was accepted by the server, going to the next scene.
      Specified by:
      notifyValidNick in interface View
    • askPlayerColor

      public java.lang.String askPlayerColor​(java.util.ArrayList<java.lang.String> availableColors)
      Asks to the player the color for the game. Only three colors are available: blue, white and beige.
      Specified by:
      askPlayerColor in interface View
      Parameters:
      availableColors - available colors for the game.
      Returns:
      The color chosen by the player.
    • notifyValidColor

      public void notifyValidColor()
      Notifies the player that his color choice was accepted by the server, going to the next scene.
      Specified by:
      notifyValidColor in interface View
    • askPlayerGod

      public java.lang.String askPlayerGod()
      Asks to the player which God among the available ones wants to play with during the current game.
      Specified by:
      askPlayerGod in interface View
      Returns:
      The name of the chosen God.
    • playerChoseInvalidGod

      public void playerChoseInvalidGod()
      Lets the player know that his God's choice was rejected by the server.
      Specified by:
      playerChoseInvalidGod in interface View
    • getGodFromChallenger

      public java.lang.String getGodFromChallenger​(int numOfPlayers, int alreadyChosenGods)
      Lets the challenger know how many gods he still has to choose. Then the challenger, if other gods need to be selected, chooses another god for the game.
      Specified by:
      getGodFromChallenger in interface View
      Parameters:
      numOfPlayers - The number of players of the current game.
      alreadyChosenGods - The number of gods that the challenger has already chosen for the game.
      Returns:
      Another name of the God the challenger chooses for the current game.
    • challengerChooseStartPlayer

      public java.lang.String challengerChooseStartPlayer()
      Asks to the challenger which player will be the starting one.
      Specified by:
      challengerChooseStartPlayer in interface View
      Returns:
      The nickname of the starting player.
    • notAvailableColor

      public void notAvailableColor()
      Lets the player know that the chosen color was not available, because another player had already chosen it before.
      Specified by:
      notAvailableColor in interface View
    • notAvailableNickname

      public void notAvailableNickname()
      Tells the player that the inserted nickname was not available. This error can occur when the length of the nickname is too long or when the same nick was already chosen by another player.
      Specified by:
      notAvailableNickname in interface View
    • nicknameFormatError

      public void nicknameFormatError()
      Lets the client know that the nickname entered is too long or empty.
      Specified by:
      nicknameFormatError in interface View
    • askChosenWorker

      public java.lang.String askChosenWorker()
      Asks to the player which one of his worker wants to play with during the current turn.
      Specified by:
      askChosenWorker in interface View
      Returns:
      The sex of the worker the player wants to play with.
    • printCannotBuildDomeUnderneath

      public void printCannotBuildDomeUnderneath()
      Warns user of invalid build action: he cannot build a dome underneath himself. This error can only occur if player uses Zeus' power.
      Specified by:
      printCannotBuildDomeUnderneath in interface View
    • winningView

      public boolean winningView()
      The player has won the game, so the winning scene is going to be loaded.
      Specified by:
      winningView in interface View
      Returns:
      Generic return to ensure server waits for confirmation from client before disconnecting it.
    • unableToMoveLose

      public boolean unableToMoveLose()
      Lets the player know he has lost the game because both of his workers cannot move.
      Specified by:
      unableToMoveLose in interface View
      Returns:
      Generic return to ensure server waits for confirmation from client before disconnecting it.
    • unableToBuildLose

      public boolean unableToBuildLose()
      Lets the player know he has lost the game because both of his workers cannot build.
      Specified by:
      unableToBuildLose in interface View
      Returns:
      Generic return to ensure server waits for confirmation from client before disconnecting it.
    • notifyPlayersOfLoss

      public void notifyPlayersOfLoss​(java.lang.String loserNickname)
      In a 3 players game, this method notifies the other players that a player has lost the game.
      Specified by:
      notifyPlayersOfLoss in interface View
      Parameters:
      loserNickname - The nickname of the player that has lost the game.
    • printMap

      public void printMap()
      This method lets the system show an updated version of the Board.
      Specified by:
      printMap in interface View
    • update

      public void update​(CellClient toUpdateCell)
      Updates the cell of the board that has changed its contents.
      Specified by:
      update in interface View
      Parameters:
      toUpdateCell - The cell that needs to be updated.
    • printChosenGods

      public void printChosenGods​(java.util.ArrayList<java.lang.String> chosenGods)
      Shows all the Gods chosen by the challenger for the current game, going to the correct scene.
      Specified by:
      printChosenGods in interface View
      Parameters:
      chosenGods - The list of the chosen gods.
    • selectedWorkerCannotMove

      public void selectedWorkerCannotMove​(java.lang.String sex)
      Lets the player know the selected worker cannot move.
      Specified by:
      selectedWorkerCannotMove in interface View
      Parameters:
      sex - The sex of the selected worker
    • askBuildingDirection

      public java.lang.String askBuildingDirection()
      This method asks the user to insert the position where he wants to build.
      Specified by:
      askBuildingDirection in interface View
      Returns:
      The compass direction of the place where to build.
    • askBuildingDirectionAtlas

      public java.lang.String[] askBuildingDirectionAtlas()
      This method asks to Atlas' owner to insert the position where he wants to build and what type of building.
      Specified by:
      askBuildingDirectionAtlas in interface View
      Returns:
      The compass direction of the place where to build.
    • askMovementDirection

      public java.lang.String askMovementDirection()
      This method asks the user to insert the direction of his next movement.
      Specified by:
      askMovementDirection in interface View
      Returns:
      The compass direction of the movement.
    • askMoveAgain

      public java.lang.String askMoveAgain()
      Allows to get the input of the player to move again.
      Specified by:
      askMoveAgain in interface View
      Returns:
      The will of the player on keeping going moving his worker on the board.
    • askWantToMoveEnemy

      public java.lang.String askWantToMoveEnemy()
      Allows to get the input of the player to move an enemy's worker.
      Specified by:
      askWantToMoveEnemy in interface View
      Returns:
      The will of the player to move an enemy's worker
    • askWorkerToMove

      public java.lang.String askWorkerToMove​(java.util.ArrayList<WorkerClient> enemyWorkers, WorkerClient myWorker)
      Allows to move one worker's enemy.
      Specified by:
      askWorkerToMove in interface View
      Parameters:
      enemyWorkers - It's the list of the neighbour movable enemy workers.
      myWorker - It's the chosen worker of the current player.
      Returns:
      The Worker to move selected by the player, null if there aren't enemies around.
    • askBuildAgainHephaestus

      public java.lang.String askBuildAgainHephaestus()
      Asks to the player that holds Hephaestus as a God if he wants to build again.
      Specified by:
      askBuildAgainHephaestus in interface View
      Returns:
      The will of the player to build again.
    • askBuildAgainDemeter

      public java.lang.String askBuildAgainDemeter()
      Asks to the player that holds Demeter as a God if he wants to build again.
      Specified by:
      askBuildAgainDemeter in interface View
      Returns:
      The will of the player to build again.
    • askBuildAgainHestia

      public java.lang.String askBuildAgainHestia()
      Asks to the player that holds Hestia as a God if he wants to build again.
      Specified by:
      askBuildAgainHestia in interface View
      Returns:
      The will of the player to build again.
    • askBuildPrometheus

      public java.lang.String askBuildPrometheus()
      Asks to the player that holds Prometheus as a God if he wants to build before moving.
      Specified by:
      askBuildPrometheus in interface View
      Returns:
      The will of the player to build before moving.
    • printMoveErrorScreen

      public void printMoveErrorScreen()
      Points out the player cannot move in a certain position.
      Specified by:
      printMoveErrorScreen in interface View
    • printMoveDecisionError

      public java.lang.String printMoveDecisionError()
      Asks the player if he still wants to move during this turn.
      Specified by:
      printMoveDecisionError in interface View
      Returns:
      Y for a positive answer, N for a negative one.
    • printBuildDecisionError

      public java.lang.String printBuildDecisionError()
      Asks the player if he still wants to build during this turn.
      Specified by:
      printBuildDecisionError in interface View
      Returns:
      Y for a positive answer, N for a negative one.
    • printBuildGeneralErrorScreen

      public void printBuildGeneralErrorScreen()
      Points out a player is not allowed to build.
      Specified by:
      printBuildGeneralErrorScreen in interface View
    • printBuildBlockErrorScreen

      public void printBuildBlockErrorScreen()
      Points out a player is not allowed to build a block in a certain position.
      Specified by:
      printBuildBlockErrorScreen in interface View
    • printBuildInSamePositionScreen

      public void printBuildInSamePositionScreen()
      Points out that a player is not allowed to build again in a certain position.
      Specified by:
      printBuildInSamePositionScreen in interface View
    • waitChallengerChooseGods

      public void waitChallengerChooseGods​(java.lang.String challenger)
      Lets player know that the challenger is choosing the gods for the game.
      Specified by:
      waitChallengerChooseGods in interface View
      Parameters:
      challenger - nickname of the challenger.
    • waitOtherPlayerChooseGod

      public void waitOtherPlayerChooseGod​(java.lang.String otherPlayer)
      Lets player know that another player is choosing his god.
      Specified by:
      waitOtherPlayerChooseGod in interface View
      Parameters:
      otherPlayer - the player that is choosing his god.
    • otherPlayerChoseGod

      public void otherPlayerChoseGod​(java.lang.String otherPlayer, java.lang.String chosenGod)
      Lets player know the god chosen by another player.
      Specified by:
      otherPlayerChoseGod in interface View
      Parameters:
      otherPlayer - player who chose the god.
      chosenGod - god chosen by the otherPlayer.
    • waitChallengerStartPlayer

      public void waitChallengerStartPlayer()
      Lets player know that the challenger is choosing the start player.
      Specified by:
      waitChallengerStartPlayer in interface View
    • printStartPlayer

      public void printStartPlayer​(java.lang.String startPlayer)
      Lets player know who is the start player.
      Specified by:
      printStartPlayer in interface View
      Parameters:
      startPlayer - start player nickname.
    • otherPlayerSettingInitialWorkerPosition

      public void otherPlayerSettingInitialWorkerPosition​(java.lang.String player)
      Lets player know that another player is choosing the initial position for his workers.
      Specified by:
      otherPlayerSettingInitialWorkerPosition in interface View
      Parameters:
      player - player who is performing the action.
    • otherPlayerTurn

      public void otherPlayerTurn​(java.lang.String currentPlayer)
      Lets player know that it's another player's turn.
      Specified by:
      otherPlayerTurn in interface View
      Parameters:
      currentPlayer - nickname of the player that is playing his turn.
    • losingView

      public boolean losingView​(java.lang.String endgameText)
      Lets player know that he has lost, and who is the winner.
      Specified by:
      losingView in interface View
      Parameters:
      endgameText - text to display on lose.
      Returns:
      Always returns true.