Package ViewModel

Class ViewModel

All Implemented Interfaces:
Observer

public class ViewModel extends Observable implements Observer
  • Field Details

    • vm

      public static ViewModel vm
    • changesList

      public List<DataChanges> changesList
    • numberOfTilesInBagProperty

      public javafx.beans.property.StringProperty numberOfTilesInBagProperty
  • Method Details

    • getViewModel

      public static ViewModel getViewModel()
      create a new ViewModel if it doesn't exist, and return it (singleton)
      Returns:
      the ViewModel
    • getPlayers

      public Map<Integer,PlayerVVM> getPlayers()
    • getMyPlayer

      public MyPlayerVVM getMyPlayer()
    • getCurrentPlayerId

      public int getCurrentPlayerId()
    • getBoard

      public Character[][] getBoard()
    • startGame

      public void startGame()
    • setModel

      public void setModel(Model model)
      set the model only if it is null (to avoid setting it twice)
      Parameters:
      model - - the model that the ViewModel is observing (GuestModel or HostModel)
    • resetModel

      public void resetModel()
      The resetModel function is used to reset the model of the game. This function is called when a new game is started, and it deletes any observers that are attached to the old model. It then sets this.model = null; so that we can create a new instance of our GameModel class in our startGame function in GameController class.
    • close

      public void close()
      The close function closes the connection. If the model is GuestModel, it closes the connection to the server. If the model is HostModel, it closes the connection to the BookScrabbleServer (MyServer) and close the HostServer.
    • tryPlaceWord

      public void tryPlaceWord()
      Run when the player clicks the "Place Word" button. Tries to place the word on the board if it is valid (from changesList) using the Model. If the word is invalid, notify the view
    • challenge

      public void challenge(String word)
    • takeTileFromBag

      public void takeTileFromBag()
    • update

      public void update(Observable o, Object arg)
      this method start when the observable object (the model [HostModel/GuestModel]) notify to the observer (VM)
      Specified by:
      update in interface Observer
      Parameters:
      o - the observable object.
      arg - an argument passed to the notifyObservers method. (the message from the model to the VM, type: String)