Package Model

Class GuestModel

All Implemented Interfaces:
Observer

public class GuestModel extends PlayerModel implements Observer
Guest model class
  • Constructor Details

    • GuestModel

      public GuestModel(String ip, int port, String name)
      build a model for the guest and connect to the host server using clientCommunication
      Parameters:
      ip - = ip of the host server
      port - = port of the host server
      name - = name of the player
  • Method Details

    • startGame

      public void startGame()
      Specified by:
      startGame in class Model
    • connectToHostServer

      public void connectToHostServer()
    • closeConnection

      public void closeConnection()
      Specified by:
      closeConnection in class Model
    • tryPlaceWord

      public void tryPlaceWord(String word, int col, int row, boolean isVertical)
      will ask from the server to put a word on the board
      Specified by:
      tryPlaceWord in class Model
      Parameters:
      word - - string of the word that the user is trying to put on the board
      col - - index of the starting column of the word
      row - - index of the starting row of the word
      isVertical - - a boolean indicating if the word is vertical(true) or horizontal(false)
    • challenge

      public void challenge(String word)
      will ask from the server to challenge the word
      Specified by:
      challenge in class Model
      Parameters:
      word - - the word that will be sent to the server
    • takeTileFromBag

      public void takeTileFromBag()
      takeTileFromBag function that will ask from the server to take a tile from the bag
      Specified by:
      takeTileFromBag in class Model
    • getBoardStatus

      public Character[][] getBoardStatus()
      Specified by:
      getBoardStatus in class Model
      Returns:
      - the most updated state of the board
    • setBoardStatus

      public void setBoardStatus(Character[][] board)
      will update the board status
      Parameters:
      board - - represent the updated state of the board
    • getNumberOfTilesInBag

      public int getNumberOfTilesInBag()
      Specified by:
      getNumberOfTilesInBag in class Model
      Returns:
      - the current number of tiles in the bag
    • getPlayersScores

      public HashMap<Integer,Integer> getPlayersScores()
      Specified by:
      getPlayersScores in class Model
      Returns:
      - a map from a player's id to the player's score
    • getClientCommunication

      public ClientCommunication getClientCommunication()
    • getPlayersNameMap

      public HashMap<Integer,String> getPlayersNameMap()
    • getPlayersNumberOfTiles

      public HashMap<Integer,Integer> getPlayersNumberOfTiles()
      Specified by:
      getPlayersNumberOfTiles in class Model
      Returns:
      - a map from a player's id to the player's score
    • stringToCharacterMatrix

      public Character[][] stringToCharacterMatrix(String s)
      Parameters:
      s - - a string that represents the current state of the board
      Returns:
      - a matrix of characters that represent the "s" string
    • getMyHand

      public List<Character> getMyHand()
      Specified by:
      getMyHand in class Model
      Returns:
      - the hand of the player
    • update

      public void update(Observable o, Object arg)
      receive updates from the observable object
      Specified by:
      update in interface Observer
      Parameters:
      o - the observable object
      arg - an argument passed to the notifyObservers method.