-
Notifications
You must be signed in to change notification settings - Fork 0
/
Verbs.java
204 lines (184 loc) · 4.78 KB
/
Verbs.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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
import java.util.Scanner;
import java.util.Vector;
public class Verbs{
static final String EOL = System.getProperty("line.separator");
/**
* Prints whitespace, finds the verb.
*/
public static void parse(String input)
{
if (!input.equals("")) {
Scanner scan = new Scanner(input.toLowerCase());
String i = scan.next(); //first word
Vector<String> words = new Vector<String>(); //remaining words
if(!scan.hasNext()){words.add("");}
else{while(scan.hasNext()){words.add(scan.next());}}
scan.close();
System.out.println(EOL);
//The following act on the verb, passing arguments if necessary
//The string 'words' contains any arguments,
if (i.equals("north") || i.equals("n")) {north();}
else if (i.equals("east") || i.equals("e")) {east();}
else if (i.equals("south") || i.equals("s")) {south();}
else if (i.equals("west") || i.equals("w")) {west();}
else if (i.equals("up") || i.equals("u")) {up();}
else if (i.equals("down") || i.equals("d")) {down();}
else if (i.equals("use")) {use(words);}
else if (i.equals("talk")) {talk(words);}
else if (i.equals("examine") || i.equals("x")) {examine(words);}
else if (i.equals("look") || i.equals("l")) {look();}
else if (i.equals("inventory") || i.equals("i")) {inventory();}
else if (i.equals("exit") || i.equals("quit")) {System.exit(0);}
else if (i.equals("help") || i.equals("?")) {help();}
else if (i.equals("save") || i.equals("save game")){save();}
else if (i.equals("load") || i.equals("load game")){load();}
else {nope();}
}
}
private static void north()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(0)){
int z = Exe.getZ();
Exe.setZ(z+1);
look();
}
else{
nope();
}
}
private static void east()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(2)){
int x = Exe.getX();
Exe.setX(x+1);
look();
}
else{
nope();
}
}
private static void south()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(1)){
int z = Exe.getZ();
Exe.setZ(z-1);
look();
}
else{
nope();
}
}
private static void west()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(3)){
int x = Exe.getX();
Exe.setX(x-1);
look();
}
else{
nope();
}
}
private static void up()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(4)){
int y = Exe.getY();
Exe.setY(y+1);
look();
}
else{
nope();
}
}
private static void down()
{
if(World.getRoom(Exe.getX(), Exe.getY(), Exe.getZ()).checkExit(5)){
int y = Exe.getY();
Exe.setY(y-1);
look();
}
else{
nope();
}
}
private static void use(Vector<String> i)
{
try
{
System.out.println(Player.getInv().getItem(i.firstElement()).getUseEffect());
}
catch (IllegalArgumentException ex) {}
try
{
System.out.println(World.getRoom(Exe.getX(),Exe.getY(),Exe.getZ()).getItems().getItem(i.firstElement()).getUseEffect());
}
catch (IllegalArgumentException ex)
{
nope();
}
}
private static void talk(Vector<String> i)
{
try {
if(Player.getInv().getItem(i.firstElement()).getCanTalk()) {
Player.getInv().getItem(i.firstElement()).talk();
}
else {
System.out.println("No response...");
}
}
catch (IllegalArgumentException ex) {}
try {
if(World.getRoom(Exe.getX(),Exe.getY(),Exe.getZ()).getItems().getItem(i.firstElement()).getCanTalk()) {
World.getRoom(Exe.getX(),Exe.getY(),Exe.getZ()).getItems().getItem(i.firstElement()).talk();
}
else {
System.out.println("No response...");
}
}
catch (IllegalArgumentException ex)
{
nope();
}
}
private static void examine(Vector<String> i)
{
try
{
System.out.println(Player.getInv().getItem(i.firstElement()).getDescription());
}
catch (IllegalArgumentException ex) {}
try
{
System.out.println(World.getRoom(Exe.getX(),Exe.getY(),Exe.getZ()).getItems().getItem(i.firstElement()).getDescription());
}
catch (IllegalArgumentException ex)
{
nope();
}
}
private static void look(){
World.getRoom(Exe.getX(),Exe.getY(),Exe.getZ()).printRoom();
}
private static void inventory(){
Player.getInv().printItems();
}
private static void help(){
System.out.println(
"Here's what you can do: (type indicated letter or full word)" + EOL +
"You can go (n)orth, (s)outh, (e)ast, or (w)est." + EOL +
"Sometimes, you can even go (u)p or (d)own." + EOL +
"You can (use) an item, or e(x)amine one in your (i)nventory." + EOL +
"You can always take a (l)ook around, and if all else fails," + EOL +
"you can always (quit) and never, ever, ever come back.");
}
private static void save(){
Exe.saveFile();
}
private static void load(){
Exe.readSaveFile("adventure_save.txt");
}
public static void nope(){
System.out.println("I can't do that, Dave.");
}
}