Class Board

java.lang.Object
model.logic.host.data.Board
All Implemented Interfaces:
Serializable

public class Board extends Object implements Serializable
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    The boardLegal function checks if a word is legal to be placed on the board.
    boolean
    The dictionaryLegal function checks if the word is in the dictionary.
    static Board
    The getBoard function is a static function that returns the single instance of the Board class.
    Tile[][]
    The getTiles function returns a copy of the board.
    void
    The printBoard function prints the board to the console.
    int
    tryPlaceWord(Word newWord)
    The tryPlaceWord function takes a Word object as an argument and returns an integer.

    Methods inherited from class java.lang.Object

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

    • getBoard

      public static Board getBoard()
      The getBoard function is a static function that returns the single instance of the Board class. This is used to ensure that there are no multiple instances of the board, and thus no confusion about which board we are referring to when we call functions on it.
      Returns:
      A singleton instance of the board class
    • getTiles

      public Tile[][] getTiles()
      The getTiles function returns a copy of the board.
      Returns:
      A copy of the board
    • boardLegal

      public boolean boardLegal(Word word)
      The boardLegal function checks if a word is legal to be placed on the board. If the board is empty, then it must go on the star square and stay in bounds. If not, then it must be in bounds and have an adjacent or overlapping tile.
      Parameters:
      word - word Check if the word is in bounds
      Returns:
      True if the board is empty and the word is on the star square
    • dictionaryLegal

      public boolean dictionaryLegal(Word word)
      The dictionaryLegal function checks if the word is in the dictionary.
      Parameters:
      word - word Pass in the word that is being checked
      Returns:
      True if the word is in the dictionary and false otherwise
    • tryPlaceWord

      public int tryPlaceWord(Word newWord)
      The tryPlaceWord function takes a Word object as an argument and returns an integer. The function checks if the word can be placed on the board, and if it can, adds it to the board. If not, then - 1 is returned. If there are words created by placing this new word on the board that are not in our dictionary, 0 is returned. Otherwise, we return a score for how many points were earned by placing this new word on our game-board (the sum of all scores of all words created).
      Parameters:
      newWord - newWord Pass the word that is being placed on the board
      Returns:
      - 1 if the word cannot be placed on the board
    • printBoard

      public void printBoard()
      The printBoard function prints the board to the console.