Package ViewModel

Class ScrabbleViewModel

java.lang.Object
ViewModel.ScrabbleViewModel
All Implemented Interfaces:
Observer

public class ScrabbleViewModel extends Object implements Observer
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    final javafx.beans.property.BooleanProperty
     
    final javafx.beans.property.BooleanProperty
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    The ScrabbleViewModel function is the constructor for the ScrabbleViewModel class.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    The disconnect function disconnects the client from the server.
    javafx.beans.property.ObjectProperty<Character[][]>
    The getBoard function returns the boardProperty object.
    javafx.beans.property.BooleanProperty
    The getDisconnect function returns the disconnect property.
    javafx.beans.property.BooleanProperty
     
    javafx.beans.property.BooleanProperty
    The getGameStartedProperty function returns the gameStarted property.
     
    javafx.beans.property.ListProperty<String>
    The getScores function is a getter function that returns the scores list property.
    javafx.beans.property.ListProperty<Character>
    The getTiles function returns the tiles property of the Board class.
    void
    The skipTurn function is used to skip the current player's turn.
    void
    The startGame function is used to start the game.
    boolean
    The submitWord function is used to submit a word that the player has created.
    void
     

    Methods inherited from class java.lang.Object

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

    • myTurn

      public final javafx.beans.property.BooleanProperty myTurn
    • gameOver

      public final javafx.beans.property.BooleanProperty gameOver
  • Constructor Details

    • ScrabbleViewModel

      public ScrabbleViewModel(ScrabbleModelFacade m) throws IOException
      The ScrabbleViewModel function is the constructor for the ScrabbleViewModel class. It takes in a ScrabbleModelFacade object and sets it to be an instance variable of this class. It also adds itself as an observer to the model, initializes all of its properties, and creates a 2D array that will hold previous board states.
      Parameters:
      m - Set the model
      Throws:
      IOException
  • Method Details

    • getTiles

      public javafx.beans.property.ListProperty<Character> getTiles()
      The getTiles function returns the tiles property of the Board class.
      Returns:
      The tiles property
    • getBoard

      public javafx.beans.property.ObjectProperty<Character[][]> getBoard()
      The getBoard function returns the boardProperty object.
      Returns:
      A property of type character[][]
    • getPrevBoard

      public Character[][] getPrevBoard()
    • startGame

      public void startGame()
      The startGame function is used to start the game. It sets the boolean value of gameStarted to true, and then calls on model's startGame function. The tiles are set equal to what model returns from its startGame function.
    • getDisconnect

      public javafx.beans.property.BooleanProperty getDisconnect()
      The getDisconnect function returns the disconnect property.
      Returns:
      A booleanproperty
    • disconnect

      public void disconnect()
      The disconnect function disconnects the client from the server.
    • submitWord

      public boolean submitWord() throws IOException
      The submitWord function is used to submit a word that the player has created. It takes in no parameters and returns a boolean value of true if the word was submitted successfully, or false if it wasn't. The function first gets the answer from getWord(), which is then split into an array of strings, where each string represents one part of the answer (the word itself, its starting row position on boardProperty, its starting column position on boardProperty and whether it's horizontal or vertical). Then we call model.submitWord() with these values as parameters to check whether this move is valid according to our game rules (
      Returns:
      A boolean value
      Throws:
      IOException
    • skipTurn

      public void skipTurn() throws IOException, InterruptedException
      The skipTurn function is used to skip the current player's turn.
      Throws:
      IOException
      InterruptedException
    • getScores

      public javafx.beans.property.ListProperty<String> getScores()
      The getScores function is a getter function that returns the scores list property.
      Returns:
      An observable list of strings
    • getGameStartedProperty

      public javafx.beans.property.BooleanProperty getGameStartedProperty()
      The getGameStartedProperty function returns the gameStarted property.
      Returns:
      The gamestarted property
    • update

      public void update(Observable o, Object arg)
      Specified by:
      update in interface Observer
    • getGameOver

      public javafx.beans.property.BooleanProperty getGameOver()