|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectbecker.xtras.jotto.Hint
public abstract class Hint
A Hint object is used to specify one kind of hint to a Jotto player.
Hint must be extended to provide a method named isOK(Word w)
and
another named getHintWords(int maxDesired, IHintData hintData)
.
The getHintWords
method is called to generate the words for
the hint. It likely gets the list of known words from hintData and passes
itself to the IWordList.getWords(IWordPredicate p)
method. Passing
itself to getWords
works because Hint
implements
IWordPredicate
via the isOK
method.
This method is used to determine
whether or not a given Word
is appropriate
to include in the answer.
For example, the following subclass of Hint could be used to show the user words that contain a specified letter.
public class HintContainsLetter extends Hint { private char letter; public HintContainsLetter() { super("containing the letter", Hint.LETTER); } public Word[] getHintWords(int maxDesired, IHintData hintData) { this.letter = hintData.getLetter(); return hintData.getKnownWords().getWords(maxDesired, this); } public boolean isOK(Word w) { return w.getWord().indexOf(this.letter) >= 0; } }
Note that Hint
implements IWordPredicate
, implying
that all subclasses will also implement that interface whether or not they
include the phrase "implements IWordPredicate".
Hint
objects are added to the program using the
JottoModel.addHint(Hint)
method in JottoModel
. This
method adds the hint to a list of hints which will be displayed in
the user interface.
When the user requests a hint, the program:
Hint
object from the list.IHintData
from which
the hint can retrieve the data it needs.getHintWords
, passing the IHintData
object as a parameter.
getHintWords
to the user.
Field Summary | |
---|---|
static int |
DIFFICULTY
The hint requires a word difficulty level to determine if a word should be included. |
static int |
GUESSES
The hint requires an array the user's previous guesses to determine if a word should be included. |
static int |
LETTER
The hint requires a single letter to determine if a word should be included. |
static int |
LETTERS
The hint requires an array of letters to determine if a word should be included. |
static int |
NONE
The hint requires no extra information to determine if a word should be included. |
Constructor Summary | |
---|---|
Hint(String aDescription,
int argType)
Construct a hint object. |
Method Summary | |
---|---|
int |
getArgumentType()
Get the argument type for this hint, as given to the constructor. |
String |
getDescription()
Get the description for this hint as given to the constructor. |
abstract Word[] |
getHintWords(int maxDesired,
IHintData hintData)
Get the words to display as the hint. |
abstract boolean |
isOK(Word w)
Override this method to specify whether or not the Word w is an acceptable answer for this hint. |
static void |
main(String[] args)
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int LETTER
public static final int LETTERS
public static final int GUESSES
public static final int NONE
public static final int DIFFICULTY
Constructor Detail |
---|
public Hint(String aDescription, int argType)
aDescription
- The description of the hint that will be displayed
in the user interface. This string is returned by getDescription()
.
The user interface will append it to the end of "A word " or "All words ".argType
- The type of argument required by this hint. Must be
one of {LETTER, LETTERS, GUESSES, DIFFICULTY, NONE}. The value is returned by
getArgumentType()
and determines which version of setArgument
is called.Method Detail |
---|
public final String getDescription()
public final int getArgumentType()
public abstract boolean isOK(Word w)
isOK
in interface IWordPredicate
w
- The word to test.
public abstract Word[] getHintWords(int maxDesired, IHintData hintData)
public static void main(String[] args)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |