-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathConversationState.java
executable file
·113 lines (99 loc) · 3.21 KB
/
ConversationState.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package textgame;
import java.util.Set;
import java.util.Map;
import java.util.HashMap;
import java.lang.IllegalArgumentException;
/**
* Represents the state of the Character.
*
* At each step in the conversation, the player may do one of several things to
* the character, and each thing they do leads to a new state.
*
* @author Colin Rothwell
* @see NPC
*/
class ConversationState {
private String reply;
public String getReply() { return reply; }
public ConversationState(String reply) {
this.reply = reply;
this.acceptableItems = new HashMap<Item, ConversationState>();
this.givableItems = new HashMap<Item, ConversationState>();
this.speeches = new HashMap<String, ConversationState>();
}
public ConversationState(String reply,
Map<Item, ConversationState> acceptableItems,
Map<Item, ConversationState> givableItems,
Map<String, ConversationState> speeches) {
this.reply = reply;
this.acceptableItems = acceptableItems;
this.givableItems = givableItems;
this.speeches = speeches;
}
private Map<Item, ConversationState> acceptableItems;
/**
* @return The set of all items the character can accept at this time.
*/
public Set<Item> getAcceptableItems() {
return acceptableItems.keySet();
}
public void putAcceptableItem(Item i, ConversationState s) {
acceptableItems.put(i, s);
}
/**
* @exception IllegalArgumentException thrown if the character cannot
* accept this item at this time.
*/
public ConversationState getItem(Item i) throws IllegalArgumentException {
ConversationState r = acceptableItems.get(i);
if (r != null) {
return r;
}
else {
throw new IllegalArgumentException("cannot accept " + i);
}
}
private Map<Item, ConversationState> givableItems;
/**
* @return The set of all items the character can give at this time.
*/
public Set<Item> getGivableItems() {
return givableItems.keySet();
}
public void putGivableItem(Item i, ConversationState s) {
givableItems.put(i, s);
}
/**
* @exception IllegalArgumentException thrown is the character cannot give
* that item at this time
*/
public ConversationState giveItem(Item i) throws IllegalArgumentException {
ConversationState r = givableItems.get(i);
if (r != null) {
return r;
}
else {
throw new IllegalArgumentException("cannot give " + i);
}
}
private Map<String, ConversationState> speeches;
public Set<String> getSpeeches() {
return speeches.keySet();
}
public void putSpeech(String s, ConversationState c) {
speeches.put(s, c);
}
/**
* @exception IllegalArgumentException thrown if you cannot say that to the
* character at this time
*/
public ConversationState talk(String s) throws IllegalArgumentException {
ConversationState r = speeches.get(s);
if (r != null) {
return r;
}
else {
throw new IllegalArgumentException("cannot speak " + s);
}
}
}