Package it.polimi.ingsw.client.gui
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>boardClientprotected static javafx.scene.ParentboardRootprotected static ChooseGodControllerchooseGodControllerprotected static javafx.scene.ParentchooseGodRootprotected static javafx.scene.ParentcolorRootprotected static javafx.scene.ParentconnectRootprotected static java.util.concurrent.atomic.AtomicBooleanisInLobbyprotected static javafx.scene.ParentlobbyRootprotected static java.lang.StringmyNicknameprotected static javafx.scene.ParentnicknameRootprotected static java.util.concurrent.atomic.AtomicIntegernumberOfPlayersprotected static javafx.scene.ParentnumberOfPlayersRootprotected static java.util.ArrayList<PlayerClient>playersprotected static java.util.concurrent.atomic.AtomicIntegerplayersConnectedprotected static java.util.concurrent.SynchronousQueue<java.lang.Object>queueprotected static javafx.scene.ParentstartPlayerRoot -
Constructor Summary
Constructors Constructor Description GuiManager() -
Method Summary
Modifier and Type Method Description java.lang.StringaskBuildAgainDemeter()Asks to the player that holds Demeter as a God if he wants to build again.java.lang.StringaskBuildAgainHephaestus()Asks to the player that holds Hephaestus as a God if he wants to build again.java.lang.StringaskBuildAgainHestia()Asks to the player that holds Hestia as a God if he wants to build again.java.lang.StringaskBuildingDirection()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.StringaskBuildPrometheus()Asks to the player that holds Prometheus as a God if he wants to build before moving.java.lang.StringaskChosenWorker()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.StringaskMoveAgain()Allows to get the input of the player to move again.java.lang.StringaskMovementDirection()This method asks the user to insert the direction of his next movement.intaskNumberOfPlayers()Asks to the creator of a game how many players will the game hold.java.lang.StringaskPlayerColor(java.util.ArrayList<java.lang.String> availableColors)Asks to the player the color for the game.java.lang.StringaskPlayerGod()Asks to the player which God among the available ones wants to play with during the current game.java.lang.StringaskPlayerNickname()Asks to the player the nickname for the game.java.lang.StringaskWantToMoveEnemy()Allows to get the input of the player to move an enemy's worker.java.lang.StringaskWorkerToMove(java.util.ArrayList<WorkerClient> enemyWorkers, WorkerClient myWorker)Allows to move one worker's enemy.java.lang.StringchallengerChooseStartPlayer()Asks to the challenger which player will be the starting one.voidconnectionOutcome(boolean connected)Shows if the connection to the server wasn't successful.voidcreateGame()Lets the player know he is the creator of a new game.java.lang.StringgetGodFromChallenger(int numOfPlayers, int alreadyChosenGods)Lets the challenger know how many gods he still has to choose.java.lang.StringgetServerAddress()Asks the IP of the server where the client wants to connect to.voidinvalidInitialWorkerPosition()Lets the player know the position he wrote for the initial worker position was wrong.voidjoinGame(int numberOfPlayers)Lets the player know the number of players for the game he's been assigned.booleanlosingView(java.lang.String endgameText)Lets player know that he has lost, and who is the winner.voidnicknameFormatError()Lets the client know that the nickname entered is too long or empty.voidnotAvailableColor()Lets the player know that the chosen color was not available, because another player had already chosen it before.voidnotAvailableNickname()Tells the player that the inserted nickname was not available.voidnotifyOtherPlayerDisconnection(java.lang.String disconnectedPlayer)Displays that a player has been disconnected and reason.voidnotifyPlayersOfLoss(java.lang.String loserNickname)In a 3 players game, this method notifies the other players that a player has lost the game.voidnotifyValidColor()Notifies the player that his color choice was accepted by the server, going to the next scene.voidnotifyValidNick()Notifies the player that his nickname was accepted by the server, going to the next scene.voidotherPlayerChoseGod(java.lang.String otherPlayer, java.lang.String chosenGod)Lets player know the god chosen by another player.voidotherPlayerSettingInitialWorkerPosition(java.lang.String player)Lets player know that another player is choosing the initial position for his workers.voidotherPlayerTurn(java.lang.String currentPlayer)Lets player know that it's another player's turn.voidplayerChoseInvalidGod()Lets the player know that his God's choice was rejected by the server.voidprintBuildBlockErrorScreen()Points out a player is not allowed to build a block in a certain position.java.lang.StringprintBuildDecisionError()Asks the player if he still wants to build during this turn.voidprintBuildGeneralErrorScreen()Points out a player is not allowed to build.voidprintBuildInSamePositionScreen()Points out that a player is not allowed to build again in a certain position.voidprintCannotBuildDomeUnderneath()Warns user of invalid build action: he cannot build a dome underneath himself.voidprintChosenGods(java.util.ArrayList<java.lang.String> chosenGods)Shows all the Gods chosen by the challenger for the current game, going to the correct scene.voidprintMap()This method lets the system show an updated version of the Board.java.lang.StringprintMoveDecisionError()Asks the player if he still wants to move during this turn.voidprintMoveErrorScreen()Points out the player cannot move in a certain position.voidprintStartPlayer(java.lang.String startPlayer)Lets player know who is the start player.voidselectedWorkerCannotMove(java.lang.String sex)Lets the player know the selected worker cannot move.voidsetOtherPlayersInfo(java.lang.String nickname, java.lang.String color)Allows to store in the client memory the general info about other players.booleanunableToBuildLose()Lets the player know he has lost the game because both of his workers cannot build.booleanunableToMoveLose()Lets the player know he has lost the game because both of his workers cannot move.voidupdate(CellClient toUpdateCell)Updates the cell of the board that has changed its contents.voidwaitChallengerChooseGods(java.lang.String challenger)Lets player know that the challenger is choosing the gods for the game.voidwaitChallengerStartPlayer()Lets player know that the challenger is choosing the start player.voidwaitOtherPlayerChooseGod(java.lang.String otherPlayer)Lets player know that another player is choosing his god.booleanwinningView()The player has won the game, so the winning scene is going to be loaded.
-
Field Details
-
players
-
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
-
-
Constructor Details
-
GuiManager
public GuiManager()
-
-
Method Details
-
getServerAddress
public java.lang.String getServerAddress()Asks the IP of the server where the client wants to connect to.- Specified by:
getServerAddressin interfaceView- 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:
connectionOutcomein interfaceView- 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:
notifyOtherPlayerDisconnectionin interfaceView- 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"). -
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:
createGamein interfaceView
-
askNumberOfPlayers
public int askNumberOfPlayers()Asks to the creator of a game how many players will the game hold.- Specified by:
askNumberOfPlayersin interfaceView- Returns:
- The number of players decided by the creator player.
-
askInitialWorkerPosition
public int[] askInitialWorkerPosition(java.lang.String workerSex) throws java.util.InputMismatchExceptionThis 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:
askInitialWorkerPositionin interfaceView- 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:
setOtherPlayersInfoin interfaceView- 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:
invalidInitialWorkerPositionin interfaceView
-
askPlayerNickname
public java.lang.String askPlayerNickname()Asks to the player the nickname for the game.- Specified by:
askPlayerNicknamein interfaceView- 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:
notifyValidNickin interfaceView
-
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:
askPlayerColorin interfaceView- 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:
notifyValidColorin interfaceView
-
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:
askPlayerGodin interfaceView- 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:
playerChoseInvalidGodin interfaceView
-
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:
getGodFromChallengerin interfaceView- 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:
challengerChooseStartPlayerin interfaceView- 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:
notAvailableColorin interfaceView
-
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:
notAvailableNicknamein interfaceView
-
nicknameFormatError
public void nicknameFormatError()Lets the client know that the nickname entered is too long or empty.- Specified by:
nicknameFormatErrorin interfaceView
-
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:
askChosenWorkerin interfaceView- 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:
printCannotBuildDomeUnderneathin interfaceView
-
winningView
public boolean winningView()The player has won the game, so the winning scene is going to be loaded.- Specified by:
winningViewin interfaceView- 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:
unableToMoveLosein interfaceView- 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:
unableToBuildLosein interfaceView- 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:
notifyPlayersOfLossin interfaceView- 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. -
update
Updates the cell of the board that has changed its contents. -
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:
printChosenGodsin interfaceView- 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:
selectedWorkerCannotMovein interfaceView- 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:
askBuildingDirectionin interfaceView- 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:
askBuildingDirectionAtlasin interfaceView- 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:
askMovementDirectionin interfaceView- 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:
askMoveAgainin interfaceView- 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:
askWantToMoveEnemyin interfaceView- 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:
askWorkerToMovein interfaceView- 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:
askBuildAgainHephaestusin interfaceView- 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:
askBuildAgainDemeterin interfaceView- 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:
askBuildAgainHestiain interfaceView- 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:
askBuildPrometheusin interfaceView- 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:
printMoveErrorScreenin interfaceView
-
printMoveDecisionError
public java.lang.String printMoveDecisionError()Asks the player if he still wants to move during this turn.- Specified by:
printMoveDecisionErrorin interfaceView- 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:
printBuildDecisionErrorin interfaceView- 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:
printBuildGeneralErrorScreenin interfaceView
-
printBuildBlockErrorScreen
public void printBuildBlockErrorScreen()Points out a player is not allowed to build a block in a certain position.- Specified by:
printBuildBlockErrorScreenin interfaceView
-
printBuildInSamePositionScreen
public void printBuildInSamePositionScreen()Points out that a player is not allowed to build again in a certain position.- Specified by:
printBuildInSamePositionScreenin interfaceView
-
waitChallengerChooseGods
public void waitChallengerChooseGods(java.lang.String challenger)Lets player know that the challenger is choosing the gods for the game.- Specified by:
waitChallengerChooseGodsin interfaceView- 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:
waitOtherPlayerChooseGodin interfaceView- 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:
otherPlayerChoseGodin interfaceView- 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:
waitChallengerStartPlayerin interfaceView
-
printStartPlayer
public void printStartPlayer(java.lang.String startPlayer)Lets player know who is the start player.- Specified by:
printStartPlayerin interfaceView- 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:
otherPlayerSettingInitialWorkerPositionin interfaceView- 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:
otherPlayerTurnin interfaceView- 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:
losingViewin interfaceView- Parameters:
endgameText- text to display on lose.- Returns:
- Always returns true.
-