public class Boggle extends Object
Modifier and Type | Field and Description |
---|---|
private List<BoggleDie> |
dice
The 16 boggle dice.
|
private Set<String> |
dictionary
The dictionary of lower case English words.
|
private static Boggle |
INSTANCE
The singleton instance.
|
private static String[] |
LETTERS
The letters on the 16 boggle dice.
|
Modifier | Constructor and Description |
---|---|
private |
Boggle()
Constructs the instance by creating a collection of of the 16 standard
boggle dice and initializing an English word dictionary.
|
Modifier and Type | Method and Description |
---|---|
List<BoggleDie> |
getDice()
Returns a list of the 16 dice in their current state.
|
static Boggle |
getInstance()
Returns the single
Boggle instance. |
boolean |
lookUp(String word)
Looks up a word to confirm that it is an actual English word at least 3
letters in length.
|
private void |
readDictionary()
Reads the dictionary file and stores the words from the file
in the Set this.dictionary.
|
void |
shuffleAndRoll()
Randomly shuffles the order of the dice and rolls all of dice.
|
private static final String[] LETTERS
private static final Boggle INSTANCE
private Boggle()
NullPointerException
- if the dictionary cannot be initializedprivate final void readDictionary()
The dictionary file is named dictionary.txt and needs to be located in the cse.games.boggle directory.
public static Boggle getInstance()
Boggle
instance.Boggle
instancepublic List<BoggleDie> getDice()
shuffleAndRoll
.
Clients are unable to modify the game dice using the returned list; i.e., modifying the returned list has no effect on the dice held by the singleton.
public void shuffleAndRoll()
public boolean lookUp(String word)
word
- the word to look uptrue
if the word is an English word that is at least 3
letters long, false
otherwise