-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandList.java
More file actions
249 lines (219 loc) · 4.87 KB
/
CommandList.java
File metadata and controls
249 lines (219 loc) · 4.87 KB
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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
package TextAdventure;
import java.util.ArrayList;
/*
* Peter J.
* D. 25 Nov. 2014
*/
public class CommandList
{
private boolean test = true; //Bare til at teste stuff.
String[] commandList = new String[]
{ "USE", "SEARCH", "NORTH", "SOUTH", "WEST", "EAST", "EXIT", "HELP",
"INVENTORY", "SAVE", "LOAD", "MAP", "COMBINE" };
Presist pr = new Presist(); //Til presist for at gemme.
public CommandList()
{
System.out.println(commandList);
}
public void useCommand(String command) // What command is used and give work
// out.
{
boolean fail = true;
for (String tmp : commandList)
{
if (tmp.equalsIgnoreCase(command.substring(0, 3)))
{
fail = false;
}
}
if (fail = true)
{
if (test) System.out.println("You can't do that.");
return; // Break method if the command input is false
}
if (command.equalsIgnoreCase(Commands.EAST.toString())
|| command.equalsIgnoreCase(Commands.SOUTH.toString())
|| command.equalsIgnoreCase(Commands.NORTH.toString())
|| command.equalsIgnoreCase(Commands.WEST.toString()))
{
walk(command.toUpperCase().charAt(0));
}
else if (command.substring(0, 3).equalsIgnoreCase(
Commands.USE.toString()))
{
use(command.toUpperCase().replace("USE ", ""));
}
else if (command.substring(0, 5).equalsIgnoreCase(
Commands.SEARCH.toString()))
{
search(command.toUpperCase().replace("SEARCH ", ""));
}
else if (command.substring(0, 4).equalsIgnoreCase(
Commands.EXIT.toString()))
{
exit();
}
else if (command.substring(0, 4).equalsIgnoreCase(
Commands.HELP.toString()))
{
help();
}
else if (command.substring(0, 9).equalsIgnoreCase(
Commands.INVENTORY.toString()))
{
inventory();
}
else if (command.substring(0, 4).equalsIgnoreCase(
Commands.SAVE.toString()))
{
if(test);
// save(inv, map);
}
else if (command.substring(0, 4).equalsIgnoreCase(
Commands.LOAD.toString()))
{
load();
}
else if (command.substring(0, 3).equalsIgnoreCase(
Commands.MAP.toString()))
{
map();
}
else if (command.substring(0, 7).equalsIgnoreCase(
Commands.COMBINE.toString()))
{
combine(command.toUpperCase().replace("COMBINE ", ""));
}
else
{
if (test) System.out.println("Something is wrong...");
}
fail = false;
}
private void combine(String stuff)
{
short ID1 = 0;
short ID2 = 0;
if(test);
// for (Inventory temp : Inventory.getList())
// {
// if(temp.getItem().getName().equalsIgnoreCase(stuff.substring(0, temp.getItem().getName().lenght))){
// ID1 = temp.getItem().getID();
// break;
// }
// }
//
// for (Inventory temp : Inventory.getList())
// {
// if(temp.getItem().getName().equalsIgnoreCase(stuff.substring(0, temp.getItem().getName().lenght))){
// ID2 = temp.getItem().getID();
// break;
// }
// }
}
public void use(String stuff)
{
}
public void search(String object)
{
ArrayList<Object> objectList = new ArrayList<Object>();
// objectList = map.getAllObjectsInRoom();
if(objectList.toString().toUpperCase().contains(object.toUpperCase()))
{
for(Object tmp : objectList)
{
if(test);
// if (tmp.getName().equalsIgnoreCase(object))
// {
// tmp.search();
// }
}
}
else if(test) System.out.println("Responds på fejl...");
}
public void walk(char direction)
{
if(test);
Player p = new Player();
switch (direction) //flytter spilleren
{
case 'N':
p.changePlayerY((byte)1);
break;
case 'E':
p.changePlayerY((byte)1);
break;
case 'W':
p.changePlayerY((byte)-1);
break;
case 'S':
p.changePlayerY((byte)-1);
break;
default:
break;
}
// if(AmnesiaMap.getRoom(Player.getPlayerX(), Player.getPlayerY())) //Is the room accesible
// {
if(test);
// }
else
{
if(test) System.out.println("You can't do that.");
switch (direction) //Move player beck if the room ain't accesible
{
case 'N':
p.changePlayerY((byte)-1);
break;
case 'E':
p.changePlayerY((byte)-1);
break;
case 'W':
p.changePlayerY((byte)1);
break;
case 'S':
p.changePlayerY((byte)1);
break;
default:
break;
}
}
}
public void fight(String monster) //Not sure if this should be here, but starts a fight with a monster.
{
if(test);
}
public void exit() //Flat out exit the game.
{
System.exit(1);
}
public void help() //Send the help info back depending on where the player is.
{
String help = null;
// help = Player.helpcase;
switch (help)
{
case "defualt":
break;
case "combat":
break;
default:
break;
}
}
public void save(Inventory inventory, Player p, AmnesiaMap map) //Save game.
{
pr.save(inventory, p, map);
}
public void load() //load game.
{
SaveWrapper sw = pr.load();
}
public void inventory() //Opens inventory (calls something in inventory)
{
if(test);
}
public void map() //shows the map.
{
if(test);
}
}