-
Notifications
You must be signed in to change notification settings - Fork 0
/
EventFactory.java
62 lines (59 loc) · 1.69 KB
/
EventFactory.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
/**
*
*/
/** EventFactory deals with the execution of any Item induced events.
*
* @author Team Red
*
*/
import java.util.ArrayList;
public class EventFactory {
/** Executes a list of Strings representing events that are related to the parameter Item
*
* @param item Item which the parameter events are related to
* @param events Set of Strings representing events to execute, potentially on the parameter Item
*/
public static void execute(Item item, ArrayList<String> events)
{
for(String event:events)
{
String[] eventParsed = event.split("\\(");
if(eventParsed[0].equalsIgnoreCase("Score"))
{
//Argument is score amount
item.scoreEvent(Integer.parseInt(eventParsed[1].substring(0, eventParsed[1].length()-1)));
}
else if(eventParsed[0].equalsIgnoreCase("Wound"))
{
//Argument is wound amount
item.woundEvent(Integer.parseInt(eventParsed[1].substring(0, eventParsed[1].length()-1)));
}
else if(eventParsed[0].equalsIgnoreCase("Die"))
{
item.dieEvent();
}
else if(eventParsed[0].equalsIgnoreCase("Win"))
{
item.winEvent();
}
else if(eventParsed[0].equalsIgnoreCase("Disappear"))
{
item.disappearEvent();
}
else if(eventParsed[0].equalsIgnoreCase("Transform"))
{
try{
//Argument is Item to transform into
item.transformEvent(GameState.instance().getDungeon().getItem(eventParsed[1].substring(0, eventParsed[1].length()-1)));
}catch(Item.NoItemException e){
System.err.println("A transform event for "+ item.getPrimaryName() +" had a non-existent Item to"+
"into.");
}
}
else if(eventParsed[0].equalsIgnoreCase("Teleport"))
{
item.teleportEvent();
}
}
}
}