-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThings.java
More file actions
116 lines (94 loc) · 2.95 KB
/
Things.java
File metadata and controls
116 lines (94 loc) · 2.95 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
import java.util.Scanner;
import java.util.TreeMap;
import java.util.Map;
public class Things {
/** Just a tag interface */
public static interface Thing {}
public static class Soldier implements Thing {
public final String name;
public final int x;
public final int y;
public final int cooldown;
public final boolean alive;
public final String flag;
public Soldier(String name, int x, int y, int cooldown, boolean alive, String flag) {
this.name = name;
this.x = x;
this.y = y;
this.cooldown = cooldown;
this.alive = alive;
this.flag = flag;
}
public Soldier(Scanner sc) {
this(sc.next(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.next()=="True", sc.next());
}
}
public static class Flag implements Thing {
public final int x;
public final int y;
public Flag(int x, int y) {
this.x = x;
this.y = y;
}
public Flag(Scanner sc) {
this(sc.nextInt(), sc.nextInt());
}
}
public static class Grenade implements Thing {
public final int x;
public final int y;
public final int countdown;
public Grenade(int x, int y, int countdown) {
this.x = x;
this.y = y;
this.countdown = countdown;
}
public Grenade(Scanner sc) {
this(sc.nextInt(), sc.nextInt(), sc.nextInt());
}
}
public static class Enemy implements Thing {
public final String name;
public final int x;
public final int y;
public final boolean alive;
public final String flag;
public Enemy(String name, int x, int y, boolean alive, String flag) {
this.name = name;
this.x = x;
this.y = y;
this.alive = alive;
this.flag = flag;
}
public Enemy(Scanner sc) {
this(sc.next(), sc.nextInt(), sc.nextInt(), sc.next()=="True", sc.next());
}
}
public static class EnemyFlag implements Thing {
public final int x;
public final int y;
public EnemyFlag(int x, int y) {
this.x = x;
this.y = y;
}
public EnemyFlag(Scanner sc) {
this(sc.nextInt(), sc.nextInt());
}
}
public static Thing parseThing(String s) {
Scanner sc = new Scanner(s);
String cl = sc.next();
if (cl.equals("Soldier"))
return new Soldier(sc);
else if (cl.equals("Flag"))
return new Flag(sc);
else if (cl.equals("Grenade"))
return new Grenade(sc);
else if (cl.equals("Enemy"))
return new Enemy(sc);
else if (cl.equals("EnemyFlag"))
return new EnemyFlag(sc);
else
throw new Error("couldn't parse: "+s);
}
}