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.String askBuildAgainDemeter()
    Sends a message to ask to the player that holds Demeter as a God if he wants to build again.
    java.lang.String askBuildAgainHephaestus()
    Sends a message to ask to the player that holds Hephaestus as a God if he wants to build again.
    java.lang.String askBuildAgainHestia()
    Sends a message to ask to the player that holds Hestia as a God if he wants to build again.
    java.lang.String askBuildingDirection()
    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.String askBuildPrometheus()
    Sends a message to ask to the player that holds Prometheus as a God if he wants to build before moving.
    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.
    int[] askInitialWorkerPosition​(java.lang.String workerSex)
    Sends the message to ask the player to set his worker initial position.
    java.lang.String askMoveAgain()
    Sends a messsage to the user to get the input of the player to move again.
    java.lang.String askMovementDirection()
    Sends a message to ask to the user to insert the direction of his next movement.
    int askNumberOfPlayers()
    Sends the message to ask the first player that connects the number of players of the game.
    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.
    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.
    java.lang.String askPlayerNickname()
    Sends the message to ask to the player the nickname for the game.
    java.lang.String askWantToMoveEnemy()
    Sends a message to get the input of the player to move an enemy's worker.
    java.lang.String askWorkerToMove​(java.util.ArrayList<Worker> enemyWorkers, Worker myWorker)
    Sends a message to ask to move one worker's enemy.
    java.lang.String challengerChooseStartPlayer()
    Sends a message to the challenger and asks to choose which player will be the starting one.
    void createGame()
    Sends the message to let the player know he is the creator of a new game.
    GameController getGameController()  
    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.
    Player getPlayer()  
    java.net.Socket getSocket()  
    void invalidInitialWorkerPosition()
    Sends the message to let the player know the position he wrote for the initial worker position was wrong.
    boolean isInGame()  
    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.
    void killClient()
    Disconnects the client from the server.
    boolean losingView​(java.lang.String winner)
    Sends a message to let the 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()
    Sends a message to let the player know that the chosen color was not available.
    void notAvailableNickname()
    Sends a message to tell the player that the inserted nickname was not available.
    void notifyOtherPlayerDisconnection​(java.lang.String disconnectedPlayer)
    Sends a message to let other players know that someone has disconnected from the game.
    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()
    Sends the message to notify the client that his color has been accepted.
    void notifyValidNick()
    Sends the message to notify the client that his nickname has been accepted.
    void otherPlayerChoseGod​(java.lang.String otherPlayer, java.lang.String chosenGod)
    Sends a message to let the player know the god chosen by another player.
    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.
    void otherPlayerTurn​(java.lang.String currentPlayer)
    Sends a message to let the player know that it's another player's turn.
    void playerChoseInvalidGod()
    Sends to the player the message that the God he chose was not allowed and rejected by the server.
    void printBuildBlockErrorScreen()
    Sends a message to point out that a player is not allowed to build a block in a certain position.
    java.lang.String printBuildDecisionError()
    Sends a message to ask to the player if he still wants to build during this turn.
    void printBuildGeneralErrorScreen()
    Sends a message to point out that a player is not allowed to build.
    void printBuildInSamePositionScreen()
    Sends a message to point out that a player is not allowed to build again in a certain position.
    void printCannotBuildDomeUnderneath()
    Sends a message to the user to warn of invalid build action: he cannot build a dome underneath himself.
    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.
    void printMap()
    Sends a message to make a new print of an updated version of the Board.
    java.lang.String printMoveDecisionError()
    Sends a message to ask to the player if he still wants to move during this turn.
    void printMoveErrorScreen()
    Sends a message to point out the player cannot move in a certain position.
    void printStartPlayer​(java.lang.String startPlayer)
    Sends a message to let the the player know who is the start player.
    void selectedWorkerCannotMove​(java.lang.String sex)
    Sends a message to let the player know the selected worker cannot move.
    protected void sendMessage​(Message message)
    Writes a message to the server.
    void setInGame​(boolean inGame)  
    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.
    void setPlayer​(Player player)
    Sets the class attribute player.
    boolean unableToBuildLose()
    Sends a message to let the player know he has lost the game because both of his workers cannot build.
    boolean unableToMoveLose()
    Sends a message to let the player know he has lost the game because both of his workers cannot move.
    void update​(Cell toUpdateCell)
    Sends a message to update the cell of the board that has changed its contents.
    void waitChallengerChooseGods​(java.lang.String challenger)
    Sends a message to let the player know that the challenger is choosing the gods for the game.
    void waitChallengerStartPlayer()
    Sends a message to let the player know that the challenger is choosing the start player.
    void waitOtherPlayerChooseGod​(java.lang.String otherPlayer)
    Sends a message to let the player know that another player is choosing his god.
    boolean winningView()
    Sends a message to show to screen that the player has won the game.

    Methods inherited from class java.lang.Object

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

  • Method Details

    • getPlayer

      public Player getPlayer()
    • getSocket

      public java.net.Socket getSocket()
    • getGameController

      public GameController getGameController()
    • isInGame

      public boolean isInGame()
    • setInGame

      public void setInGame​(boolean inGame)
    • setPlayer

      public void setPlayer​(Player player)
      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

      public void update​(Cell toUpdateCell)
      Sends a message to update the cell of the board that has changed its contents.
      Specified by:
      update in interface ClientViewObserver
      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

      public java.lang.String askWorkerToMove​(java.util.ArrayList<Worker> enemyWorkers, Worker myWorker)
      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

      protected void sendMessage​(Message message)
      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.