import java.util.Set; import java.util.TreeSet; import java.util.Scanner; import java.io.File; /** * Class that provides the basic functionality of a Boggle game. * @author Dave Reed * @version 11/3/07 */ public class BoggleGame { private final static String DICT_FILE = "dictionary.txt"; private BoggleBoard board; private Set guessedWords; private Set unguessedWords; /** * Creates a new instance of BoggleGame. */ public BoggleGame() { board = new BoggleBoard(); guessedWords = new TreeSet(); unguessedWords = new TreeSet(); try { Scanner dictFile = new Scanner(new File(DICT_FILE)); while (dictFile.hasNext()) { String nextWord = dictFile.next(); if (this.board.findWord(nextWord)) { this.unguessedWords.add(nextWord); } } } catch (java.io.FileNotFoundException e) { System.out.println("DICTIONARY FILE NOT FOUND"); } } /** * Determines whether a word is stored in the board and has not yet * been guessed. * @param word the word to be searched for * @return true if word is on the board and has not been previously * guessed; else false */ public boolean makeGuess(String word) { if (this.unguessedWords.contains(word)) { this.unguessedWords.remove(word); this.guessedWords.add(word); return true; } return false; } /** * Returns the set of words from the board that have been guessed so far. */ public Set getGuessedWords() { return guessedWords; } /** * Returns the set of words from the board that have not yet been guessed. */ public Set getUnguessedWords() { return unguessedWords; } /** * Returns a string representation of the boggle board. */ public String getBoard() { return board.toString(); } }