-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHumanPlayer.java
49 lines (42 loc) · 1.13 KB
/
HumanPlayer.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/**
* Boggle player that interacts with a human player.
* Duplicate words generate an error, words not
* in lexicon generate an error. The errors are shown via
* an associated view.
* @author Owen Astrachan
*
*/
import java.util.List;
public class HumanPlayer extends AbstractPlayer {
private String myName;
public HumanPlayer(String name){
myName = name;
}
/**
* Add word if the word is in the lexicon and isn't
* a duplicate. Update score appropriately via
* call to AbstractPlayer (super). Show word found
* on the associated View of this player.
*/
public boolean add(String word) {
if (word.length() == 0){
myView.showError("","empty word, ignored");
return false;
}
else if (myWords.contains(word)){
myView.showError(word,"already guessed");
return false;
}
else {
super.add(word);
return true;
}
}
/**
* Returns name of this player.
* @return name of this human player
*/
public String getName() {
return myName;
}
}