Package it.polimi.ingsw.server
Class VirtualView
java.lang.Object
it.polimi.ingsw.server.VirtualView
- All Implemented Interfaces:
ClientViewObserver
public class VirtualView extends java.lang.Object implements ClientViewObserver
Represents a mock instance of the client server side.
Allows to send to the client through the network the messages and receive the client's answer when needed.
-
Constructor Summary
Constructors Constructor Description VirtualView(java.net.Socket socket, GameController gameController) -
Method Summary
Modifier and Type Method Description java.lang.StringaskBuildAgainDemeter()Sends a message to ask to the player that holds Demeter as a God if he wants to build again.java.lang.StringaskBuildAgainHephaestus()Sends a message to ask to the player that holds Hephaestus as a God if he wants to build again.java.lang.StringaskBuildAgainHestia()Sends a message to ask to the player that holds Hestia as a God if he wants to build again.java.lang.StringaskBuildingDirection()Sends a message to ask the user to insert the position where he wants to build.java.lang.String[]askBuildingDirectionAtlas()Sends a message to ask to Atlas' owner to insert the position where he wants to build and what type of building.java.lang.StringaskBuildPrometheus()Sends a message to ask to the player that holds Prometheus as a God if he wants to build before moving.java.lang.StringaskChosenWorker()Sends a message to ask to the player which one of his worker wants to play with during the current turn.int[]askInitialWorkerPosition(java.lang.String workerSex)Sends the message to ask the player to set his worker initial position.java.lang.StringaskMoveAgain()Sends a messsage to the user to get the input of the player to move again.java.lang.StringaskMovementDirection()Sends a message to ask to the user to insert the direction of his next movement.intaskNumberOfPlayers()Sends the message to ask the first player that connects the number of players of the game.java.lang.StringaskPlayerColor(java.util.ArrayList<java.lang.String> availableColors)Sends to the client the message to ask to the player the color for the game.java.lang.StringaskPlayerGod()Sends the message to ask to the player which God among the available ones wants to play with during the current game.java.lang.StringaskPlayerNickname()Sends the message to ask to the player the nickname for the game.java.lang.StringaskWantToMoveEnemy()Sends a message to get the input of the player to move an enemy's worker.java.lang.StringaskWorkerToMove(java.util.ArrayList<Worker> enemyWorkers, Worker myWorker)Sends a message to ask to move one worker's enemy.java.lang.StringchallengerChooseStartPlayer()Sends a message to the challenger and asks to choose which player will be the starting one.voidcreateGame()Sends the message to let the player know he is the creator of a new game.GameControllergetGameController()java.lang.StringgetGodFromChallenger(int numOfPlayers, int alreadyChosenGods)Sends a message to the challenger to let him know how many gods he still has to choose.PlayergetPlayer()java.net.SocketgetSocket()voidinvalidInitialWorkerPosition()Sends the message to let the player know the position he wrote for the initial worker position was wrong.booleanisInGame()voidjoinGame(int numberOfPlayers)Sends the message to the player, to let him know the number of players for the game he's been assigned.voidkillClient()Disconnects the client from the server.booleanlosingView(java.lang.String winner)Sends a message to let the 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()Sends a message to let the player know that the chosen color was not available.voidnotAvailableNickname()Sends a message to tell the player that the inserted nickname was not available.voidnotifyOtherPlayerDisconnection(java.lang.String disconnectedPlayer)Sends a message to let other players know that someone has disconnected from the game.voidnotifyPlayersOfLoss(java.lang.String loserNickname)In a 3 players game, this method notifies the other players that a player has lost the game.voidnotifyValidColor()Sends the message to notify the client that his color has been accepted.voidnotifyValidNick()Sends the message to notify the client that his nickname has been accepted.voidotherPlayerChoseGod(java.lang.String otherPlayer, java.lang.String chosenGod)Sends a message to let the player know the god chosen by another player.voidotherPlayerSettingInitialWorkerPosition(java.lang.String player)Sends a message to let the player know that another player is choosing the initial position for his workers.voidotherPlayerTurn(java.lang.String currentPlayer)Sends a message to let the player know that it's another player's turn.voidplayerChoseInvalidGod()Sends to the player the message that the God he chose was not allowed and rejected by the server.voidprintBuildBlockErrorScreen()Sends a message to point out that a player is not allowed to build a block in a certain position.java.lang.StringprintBuildDecisionError()Sends a message to ask to the player if he still wants to build during this turn.voidprintBuildGeneralErrorScreen()Sends a message to point out that a player is not allowed to build.voidprintBuildInSamePositionScreen()Sends a message to point out that a player is not allowed to build again in a certain position.voidprintCannotBuildDomeUnderneath()Sends a message to the user to warn of invalid build action: he cannot build a dome underneath himself.voidprintChosenGods(java.util.ArrayList<java.lang.String> chosenGods)Sends a message to show all the Gods chosen by the challenger for the current game.voidprintMap()Sends a message to make a new print of an updated version of the Board.java.lang.StringprintMoveDecisionError()Sends a message to ask to the player if he still wants to move during this turn.voidprintMoveErrorScreen()Sends a message to point out the player cannot move in a certain position.voidprintStartPlayer(java.lang.String startPlayer)Sends a message to let the the player know who is the start player.voidselectedWorkerCannotMove(java.lang.String sex)Sends a message to let the player know the selected worker cannot move.protected voidsendMessage(Message message)Writes a message to the server.voidsetInGame(boolean inGame)voidsetOtherPlayersInfo(java.lang.String nickname, java.lang.String color)Sends the message to the client to set and to store in the local interface memory the general info of other players.voidsetPlayer(Player player)Sets the class attribute player.booleanunableToBuildLose()Sends a message to let the player know he has lost the game because both of his workers cannot build.booleanunableToMoveLose()Sends a message to let the player know he has lost the game because both of his workers cannot move.voidupdate(Cell toUpdateCell)Sends a message to update the cell of the board that has changed its contents.voidwaitChallengerChooseGods(java.lang.String challenger)Sends a message to let the player know that the challenger is choosing the gods for the game.voidwaitChallengerStartPlayer()Sends a message to let the player know that the challenger is choosing the start player.voidwaitOtherPlayerChooseGod(java.lang.String otherPlayer)Sends a message to let the player know that another player is choosing his god.booleanwinningView()Sends a message to show to screen that the player has won the game.
-
Constructor Details
-
Method Details
-
getPlayer
-
getSocket
public java.net.Socket getSocket() -
getGameController
-
isInGame
public boolean isInGame() -
setInGame
public void setInGame(boolean inGame) -
setPlayer
Sets the class attribute player.- Parameters:
player- player associated to the instance of this class.
-
joinGame
public void joinGame(int numberOfPlayers)Sends the message to the player, to let him 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").- Parameters:
numberOfPlayers- The number of players of the game the player has been assigned to.
-
createGame
public void createGame()Sends the message to let the player know he is the creator of a new game. -
askNumberOfPlayers
public int askNumberOfPlayers()Sends the message to ask the first player that connects the number of players of the game.- Returns:
- The number of players.
-
askInitialWorkerPosition
public int[] askInitialWorkerPosition(java.lang.String workerSex)Sends the message to ask the player to set his worker initial position.- 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.
-
invalidInitialWorkerPosition
public void invalidInitialWorkerPosition()Sends the message to let the player know the position he wrote for the initial worker position was wrong. -
askPlayerNickname
public java.lang.String askPlayerNickname()Sends the message to ask to the player the nickname for the game.- Returns:
- The nickname chosen by the player.
-
nicknameFormatError
public void nicknameFormatError()Lets the client know that the nickname entered is too long or empty. -
notifyValidNick
public void notifyValidNick()Sends the message to notify the client that his nickname has been accepted. -
notifyValidColor
public void notifyValidColor()Sends the message to notify the client that his color has been accepted. -
askPlayerColor
public java.lang.String askPlayerColor(java.util.ArrayList<java.lang.String> availableColors)Sends to the client the message to ask to the player the color for the game. Only three colors are available: blue, white and beige.- Parameters:
availableColors- list of available colors.- Returns:
- The color chosen by the player.
-
setOtherPlayersInfo
public void setOtherPlayersInfo(java.lang.String nickname, java.lang.String color)Sends the message to the client to set and to store in the local interface memory the general info of other players.- Parameters:
nickname- Nickname of the player to register.color- Color chosen by that specific player for the current game.
-
askPlayerGod
public java.lang.String askPlayerGod()Sends the message to ask to the player which God among the available ones wants to play with during the current game.- Returns:
- The name of the chosen God.
-
playerChoseInvalidGod
public void playerChoseInvalidGod()Sends to the player the message that the God he chose was not allowed and rejected by the server. -
getGodFromChallenger
public java.lang.String getGodFromChallenger(int numOfPlayers, int alreadyChosenGods)Sends a message to the challenger to let him know how many gods he still has to choose.- 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()Sends a message to the challenger and asks to choose which player will be the starting one.- Returns:
- The nickname of the starting player.
-
notAvailableColor
public void notAvailableColor()Sends a message to let the player know that the chosen color was not available. -
notAvailableNickname
public void notAvailableNickname()Sends a message to tell the player that the inserted nickname was not available. -
askChosenWorker
public java.lang.String askChosenWorker()Sends a message to ask to the player which one of his worker wants to play with during the current turn.- Returns:
- The sex of the worker the player wants to play with.
-
winningView
public boolean winningView()Sends a message to show to screen that the player has won the game.- Returns:
- true if the client has correctly seen the winning view.
-
unableToMoveLose
public boolean unableToMoveLose()Sends a message to let the player know he has lost the game because both of his workers cannot move.- Returns:
- true if the client has correctly seen the losing view.
-
unableToBuildLose
public boolean unableToBuildLose()Sends a message to let the player know he has lost the game because both of his workers cannot build.- Returns:
- true if the client has correctly seen the losing view.
-
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.- Parameters:
loserNickname- The nickname of the player that has lost the game.
-
printMap
public void printMap()Sends a message to make a new print of an updated version of the Board. -
update
Sends a message to update the cell of the board that has changed its contents.- Specified by:
updatein interfaceClientViewObserver- Parameters:
toUpdateCell- The cell that needs to be updated.
-
printChosenGods
public void printChosenGods(java.util.ArrayList<java.lang.String> chosenGods)Sends a message to show all the Gods chosen by the challenger for the current game.- Parameters:
chosenGods- The list of the chosen gods.
-
selectedWorkerCannotMove
public void selectedWorkerCannotMove(java.lang.String sex)Sends a message to let the player know the selected worker cannot move.- Parameters:
sex- The sex of the selected worker
-
askBuildingDirection
public java.lang.String askBuildingDirection()Sends a message to ask the user to insert the position where he wants to build.- Returns:
- The compass direction of the place where to build.
-
askBuildingDirectionAtlas
public java.lang.String[] askBuildingDirectionAtlas()Sends a message to ask to Atlas' owner to insert the position where he wants to build and what type of building.- Returns:
- The compass direction of the place where to build.
-
askMovementDirection
public java.lang.String askMovementDirection()Sends a message to ask to the user to insert the direction of his next movement.- Returns:
- The compass direction of the movement.
-
askMoveAgain
public java.lang.String askMoveAgain()Sends a messsage to the user to get the input of the player to move again.- Returns:
- The will of the player on keeping going moving his worker on the board.
-
askWantToMoveEnemy
public java.lang.String askWantToMoveEnemy()Sends a message to get the input of the player to move an enemy's worker.- Returns:
- The will of the player to move an enemy's worker
-
askWorkerToMove
Sends a message to ask to move one worker's enemy.- 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()Sends a message to ask to the player that holds Hephaestus as a God if he wants to build again.- Returns:
- The will of the player to build again.
-
askBuildAgainDemeter
public java.lang.String askBuildAgainDemeter()Sends a message to ask to the player that holds Demeter as a God if he wants to build again.- Returns:
- The will of the player to build again.
-
askBuildAgainHestia
public java.lang.String askBuildAgainHestia()Sends a message to ask to the player that holds Hestia as a God if he wants to build again.- Returns:
- The will of the player to build again.
-
askBuildPrometheus
public java.lang.String askBuildPrometheus()Sends a message to ask to the player that holds Prometheus as a God if he wants to build before moving.- Returns:
- The will of the player to build before moving.
-
printMoveErrorScreen
public void printMoveErrorScreen()Sends a message to point out the player cannot move in a certain position. -
printCannotBuildDomeUnderneath
public void printCannotBuildDomeUnderneath()Sends a message to the user to warn of invalid build action: he cannot build a dome underneath himself. This error can only occur if player uses Zeus' power. -
printMoveDecisionError
public java.lang.String printMoveDecisionError()Sends a message to ask to the player if he still wants to move during this turn.- Returns:
- Y for a positive answer, N for a negative one.
-
printBuildDecisionError
public java.lang.String printBuildDecisionError()Sends a message to ask to the player if he still wants to build during this turn.- Returns:
- Y for a positive answer, N for a negative one.
-
printBuildGeneralErrorScreen
public void printBuildGeneralErrorScreen()Sends a message to point out that a player is not allowed to build. -
printBuildBlockErrorScreen
public void printBuildBlockErrorScreen()Sends a message to point out that a player is not allowed to build a block in a certain position. -
printBuildInSamePositionScreen
public void printBuildInSamePositionScreen()Sends a message to point out that a player is not allowed to build again in a certain position. -
waitChallengerChooseGods
public void waitChallengerChooseGods(java.lang.String challenger)Sends a message to let the player know that the challenger is choosing the gods for the game.- Parameters:
challenger- nickname of the challenger.
-
waitOtherPlayerChooseGod
public void waitOtherPlayerChooseGod(java.lang.String otherPlayer)Sends a message to let the player know that another player is choosing his god.- Parameters:
otherPlayer- the player that is choosing his god.
-
otherPlayerChoseGod
public void otherPlayerChoseGod(java.lang.String otherPlayer, java.lang.String chosenGod)Sends a message to let the player know the god chosen by another player.- Parameters:
otherPlayer- player who chose the god.chosenGod- god chosen by the otherPlayer.
-
waitChallengerStartPlayer
public void waitChallengerStartPlayer()Sends a message to let the player know that the challenger is choosing the start player. -
printStartPlayer
public void printStartPlayer(java.lang.String startPlayer)Sends a message to let the the player know who is the start player.- Parameters:
startPlayer- The start player's nickname.
-
otherPlayerSettingInitialWorkerPosition
public void otherPlayerSettingInitialWorkerPosition(java.lang.String player)Sends a message to let the player know that another player is choosing the initial position for his workers.- Parameters:
player- The player who is performing the action.
-
otherPlayerTurn
public void otherPlayerTurn(java.lang.String currentPlayer)Sends a message to let the player know that it's another player's turn.- Parameters:
currentPlayer- The nickname of the player that is playing his turn.
-
losingView
public boolean losingView(java.lang.String winner)Sends a message to let the player know that he has lost, and who is the winner.- Parameters:
winner- nickname of the winner- Returns:
- Always returns true.
-
notifyOtherPlayerDisconnection
public void notifyOtherPlayerDisconnection(java.lang.String disconnectedPlayer)Sends a message to let other players know that someone has disconnected from the game.- Parameters:
disconnectedPlayer- The nickname of the disconnected player.
-
sendMessage
Writes a message to the server.- Parameters:
message- The message the player sends to the client during the game.
-
killClient
public void killClient()Disconnects the client from the server.
-