Package Model

Class HostModel

All Implemented Interfaces:
Observer

public class HostModel extends PlayerModel implements Observer
Host server class
  • Method Details

    • getHost

      public static HostModel getHost()
      method that return the host model itself
      Returns:
      hostModel
    • getFixedWord

      public String getFixedWord(String word, int row, int col, boolean isVertical)
    • getCharInPosition

      public char getCharInPosition(int row, int col)
    • getHostServer

      public HostServer getHostServer()
      Returns:
      the host server
    • getConnectedPlayers

      public Map<Integer,Player> getConnectedPlayers()
    • loadBooks

      public void loadBooks(String... bookNames)
    • setPlayerName

      public void setPlayerName(String name)
    • connectToBookScrabbleServer

      public void connectToBookScrabbleServer(int myPort, String gameServerIp, int gameServerPort)
      method that connect and start the connection with the server and open its own server.
      Parameters:
      myPort - this is my own port to the connection between the hostModel and the server add host server to the observer
      gameServerIp - this parameter is the ip of the server
      gameServerPort - this parameter is the port of the server
    • startGame

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

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

      public void addPlayer(Socket socket)
      method that add player to the game and create player, add the player to the map and create a string builder of ids Sends the information to the hostServer and notify with the format : requestedId + ":" + method + ":" + inputs
      Parameters:
      socket - - socket parameter that send to the hostServer
    • tryPlaceWord

      public void tryPlaceWord(String word, int col, int row, boolean isVertical)
      A method that try to place the word on the board create tile[] from the string word, create Word. notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs
      Specified by:
      tryPlaceWord in class Model
      Parameters:
      word - a string that represent the word that the player want to place on the board
      col - represent the starting col of the word in the board
      row - represent the starting row of the word in the board
      isVertical - represent if the word is vertical or not with boolean parameter
    • challenge

      public void challenge(String word)
      A method which check if the word is valid or not send the information to the handler with the method sendToHandler() notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs
      Specified by:
      challenge in class Model
      Parameters:
      word - a given word to check if it valid or not
    • takeTileFromBag

      public void takeTileFromBag()
      A method which take on tile randomly from the bag and put it in the player list of tiles notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs
      Specified by:
      takeTileFromBag in class Model
    • refillPlayerHand

      public void refillPlayerHand(int playerId)
      The refillPlayerHand function is called when a player's hand has less than 7 tiles. It adds the missing number of tiles to the player's hand, and updates all players with the new number of tiles in their hands and in the bag.
      Parameters:
      playerId - int | Identify the player that is requesting to refill his hand
    • passTheTurn

      public void passTheTurn()
      A method which increase the turns in the game notify to the binding objects by a format - requestedId + ":" + method + ":" + inputs
    • setBoardStatus

      public void setBoardStatus()
      A method that set the prev-board to the new state of the board and notify to the other players that the board has changed notify to the binding objects by a format - requestedId + ":" +method + ":" + inputs
    • tilesWithScores

      public String tilesWithScores()
      a method that create a string include char and score
      Returns:
      tiles with the scores in string
    • getBoardStatus

      public Character[][] getBoardStatus()
      A method that return the status of the board
      Specified by:
      getBoardStatus in class Model
      Returns:
      the board status in a Tile matrix
    • getNumberOfTilesInBag

      public int getNumberOfTilesInBag()
      A method that return the numbers of tile in the bag
      Specified by:
      getNumberOfTilesInBag in class Model
      Returns:
      the number of the tile which are in the bag with the parameter totalTiles
    • getPlayersScores

      public HashMap<Integer,Integer> getPlayersScores()
      A method that create a map with all the players scores
      Specified by:
      getPlayersScores in class Model
      Returns:
      a map from key: id of the players to value: player score
    • getPlayersNumberOfTiles

      public HashMap<Integer,Integer> getPlayersNumberOfTiles()
      A method that create map with all the players number of tiles
      Specified by:
      getPlayersNumberOfTiles in class Model
      Returns:
      a map from key: id of the players to value: player number of tiles
    • getMyHand

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

      public void update(Observable o, Object arg)
      A method that take care of the reading by the format we have created and calls the method we need format: requestedId+":"+method+":"+inputs
      Specified by:
      update in interface Observer
      Parameters:
      o - the observable object.
      arg - an argument passed to the notifyObservers method.