java.lang.Object
test.Board
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanboardLegal(Word word) The boardLegal function checks if the word is legal to be placed on the board.checkBonus(int row, int col) The checkBonus function checks the board for any bonus squares and returns a string that represents the type of bonus square.booleandictionaryLegal(Word word) The dictionaryLegal function checks if the word is a valid English word.static BoardgetBoard()The getBoard function is a static function that returns the Singleton board object.intgetFirstLetterRow(int row, int col) The getFirstLetterRow function takes in a row and column number and returns the first letter that is connected from there in that column.intThe getScore function takes a Word object as an argument and returns the score of that word.Tile[][]getTiles()The getTiles function returns a copy of the tiles array.The getWords function returns an ArrayList of Word objects that are formed by the tiles in the given word.booleanThe isEqual function checks if two words are equal.booleanisWordThere(Word word, int row, int col, boolean isVertical) The isWordThere function checks if the word is there in the board.intnonVerticalLength(int row, int col) The nonVerticalLength function is used to find the length of a non-vertical line.nonVerticalTileWord(int row, int col) The nonVerticalTileWord function takes in a row and column number as parameters.voidThe printBoard function prints the board to the console.sendToDictionaryLegal(Word submittedWord, Word wordToFinish) The sendToDictionaryLegal function takes in a submitted word and a word to finish.tileVerticalWord(int row, int col) The tileVerticalWord function takes in a row and column number, and returns the word that is formed by the tiles vertically above or below it.inttryPlaceWord(Word word) The tryPlaceWord function takes in a word and checks if it is legal to place on the board.intverticalLength(int row, int col) The verticalLength function returns the length of a vertical line of tiles starting at (row,col) and extending in the positive row direction.
-
Field Details
-
board
-
-
Method Details
-
getTiles
The getTiles function returns a copy of the tiles array.- Returns:
- A copy of the tiles array
-
isWordThere
The isWordThere function checks if the word is there in the board.- Parameters:
word- Word -Get the length of the wordrow- int -Check if the word is in the same row as the lettercol- int -Check if the column of the word is equal to the col parameterisVertical- boolean -Determine whether the word is vertical or horizontal- Returns:
- True if the word is in the board
-
boardLegal
The boardLegal function checks if the word is legal to be placed on the board. It checks if it's connected to other words, and that it doesn't overlap with any letters already on the board.- Parameters:
word- Word -Get the row, column, and tiles of the word- Returns:
- True if the word is legal on the board and false otherwise
-
dictionaryLegal
The dictionaryLegal function checks if the word is a valid English word.- Parameters:
word- Word -Get the tiles from the word, and to see if it is vertical or horizontal- Returns:
- True if the word is in the dictionary, false otherwise
-
getBoard
The getBoard function is a static function that returns the Singleton board object.- Returns:
- The board object
-
getFirstLetterRow
public int getFirstLetterRow(int row, int col) The getFirstLetterRow function takes in a row and column number and returns the first letter that is connected from there in that column.- Parameters:
row- int -Get the row of the first letter in a wordcol- int -Determine the column of the first letter in a word- Returns:
- An int
-
tileVerticalWord
The tileVerticalWord function takes in a row and column number, and returns the word that is formed by the tiles vertically above or below it. If there are no tiles above or below it, then null is returned.- Parameters:
row- int-Determine the row of the first letter in a wordcol- int-Determine the column of the first letter in a word- Returns:
- A word object that represents the word formed by
-
verticalLength
public int verticalLength(int row, int col) The verticalLength function returns the length of a vertical line of tiles starting at (row,col) and extending in the positive row direction. If there is no tile at (row,col), then 0 is returned.- Parameters:
row- int -Determine the row of the tile that is being checkedcol- int -Determine the column of the tile- Returns:
- The number of tiles in a vertical line starting at the given row and column
-
nonVerticalLength
public int nonVerticalLength(int row, int col) The nonVerticalLength function is used to find the length of a non-vertical line.- Parameters:
row- int -Determine the row that the tile is incol- int -Determine the column of the tile- Returns:
- The length of the non-vertical line
-
nonVerticalTileWord
The nonVerticalTileWord function takes in a row and column number as parameters. It then checks if the tile at that position is null, if it is not null, it will check to see how many tiles are connected to the right of this tile. If there are no tiles connected to the right of this tile, then we return null because there is no word formed by just one letter. Otherwise we create an array of Tiles with length equal to the number of letters in our non-vertical word (including our starting letter). We also keep track of which column contains our first letter so that when we add- Parameters:
row- int -Specify the row of the tile that is being checkedcol- int -Determine the column of the first letter in a word- Returns:
- A word that is not vertical
-
getWords
The getWords function returns an ArrayList of Word objects that are formed by the tiles in the given word.- Parameters:
word- Word -Get the tiles of the word- Returns:
- An arraylist of words
-
sendToDictionaryLegal
The sendToDictionaryLegal function takes in a submitted word and a word to finish. It then creates an array of tiles that is the same length as the word to finish, and fills it with tiles from both words. If there is no tile at that position in the WordToFinish, it will take one from submittedWord instead. The function returns this new Word object.- Parameters:
submittedWord- WordwordToFinish- Word- Returns:
- A new word that is the combination of the submittedword and wordtofinish
-
isEqual
The isEqual function checks if two words are equal.- Parameters:
w1- Wordw2- Word- Returns:
- A boolean
-
checkBonus
The checkBonus function checks the board for any bonus squares and returns a string that represents the type of bonus square. The function takes in two parameters, row and col, which are used to determine what kind of bonus square is at that location on the board.- Parameters:
row- intcol- int- Returns:
- A string
-
getScore
The getScore function takes a Word object as an argument and returns the score of that word. The function first gets all the words in the board by calling getWords(Word) function. Then it iterates over each word, calculates its score and adds it to total score.- Parameters:
word- Word- Returns:
- The score of the word that is placed on the board
-
tryPlaceWord
The tryPlaceWord function takes in a word and checks if it is legal to place on the board. If it is, then the function will try to place the word on the board with all the new words that been created as well checks if they are all valid.- Parameters:
word- Word- Returns:
- An int - returns the score of the given word, if the word wasn't placed returns 0.
-
printBoard
public void printBoard()The printBoard function prints the board to the console.
-