-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathItemSpecificCommand.java
More file actions
121 lines (95 loc) · 4.16 KB
/
ItemSpecificCommand.java
File metadata and controls
121 lines (95 loc) · 4.16 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
package bork;
/**
* Handles commands for specific items
* @author Dr. Zeitz
*/
class ItemSpecificCommand extends Command {
private String verb;
private String noun;
/**
* Constructor for the ItemSpecificCommand with the input of String verb and noun
* @param verb the verb refernced in the nouns messages
* @param noun the string name of the item being refernced
*/
ItemSpecificCommand(String verb, String noun) {
this.verb = verb;
this.noun = noun;
}
/**
* Returns the String based on the item being referenced
* @return String the message of the item, the message that the item isn't here, or the message that you can't use that verb on this item
*/
@Override
public String execute() {
Item itemReferredTo = null;
try {
itemReferredTo = GameState.instance().getItemInVicinityNamed(noun);
} catch (Item.NoItemException e) {
return "There's no " + noun + " here.";
}
String msg = itemReferredTo.getMessageForVerb(verb);
if(msg == null)
{
return "Sorry, you can't " + verb + " the " + noun + ".\n";
} else if (msg.contains("]"))
{
String[] eventMessage = msg.split(":");
if(eventMessage[0].contains(","))
{
String[] events = eventMessage[0].split(",");
for(String e : events)
{
if (e.contains("Transform"))
{
GameState.instance().transform(noun, e.substring(e.indexOf("(") + 1, e.indexOf(")")));
} else if (e.contains("Wound"))
{
GameState.instance().wound(Integer.parseInt(e.substring(e.indexOf("(") + 1, e.indexOf(")"))));
} else if (e.contains("Score"))
{
GameState.instance().addScore(Integer.parseInt(e.substring(e.indexOf("(") + 1, e.indexOf(")"))));
} else if (e.contains("Die"))
{
GameState.instance().die();
} else if (e.contains("Win"))
{
GameState.instance().win();
} else if (e.contains("Disappear"))
{
GameState.instance().disappear(noun);
} else if (e.contains("Teleport"))
{
GameState.instance().teleport();
}
}
} else {
if (eventMessage[0].contains("Transform"))
{
GameState.instance().transform(noun, eventMessage[0].substring(eventMessage[0].indexOf("(") + 1, eventMessage[0].indexOf(")")));
} else if (eventMessage[0].contains("Wound"))
{
GameState.instance().wound(Integer.parseInt(eventMessage[0].substring(eventMessage[0].indexOf("(") + 1, eventMessage[0].indexOf(")"))));
} else if (eventMessage[0].contains("Score"))
{
GameState.instance().addScore(Integer.parseInt(eventMessage[0].substring(eventMessage[0].indexOf("(") + 1, eventMessage[0].indexOf(")"))));
} else if (eventMessage[0].contains("Die"))
{
GameState.instance().die();
} else if (eventMessage[0].contains("Win"))
{
GameState.instance().win();
} else if (eventMessage[0].contains("Disappear"))
{
GameState.instance().disappear(noun);
} else if (eventMessage[0].contains("Teleport"))
{
GameState.instance().teleport();
}
}
return eventMessage[1];
} else
{
return msg;
}
}
}