-
Notifications
You must be signed in to change notification settings - Fork 0
/
ItemSpecificCommand.java
40 lines (31 loc) · 1.04 KB
/
ItemSpecificCommand.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
/**
*
*/
/** ItemSpecificCommand deals with any Command relating to interacting with an Object. This does not including attacking
* with an object.
* @author Team Red
*
*/
import java.util.ArrayList;
class ItemSpecificCommand extends Command {
private String verb;
private String noun;
ItemSpecificCommand(String verb, String noun) {
this.verb = verb;
this.noun = noun;
}
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);
ArrayList<String> events = itemReferredTo.getEventForVerb(verb);
if(msg == null)
return ("Sorry, you can't " + verb + " the " + noun + "." + "\n");
EventFactory.execute(itemReferredTo, events);
return msg;
}
}