-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMissionRunner.java
More file actions
52 lines (42 loc) · 1.44 KB
/
MissionRunner.java
File metadata and controls
52 lines (42 loc) · 1.44 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
package battlehub;
import battleship.core.*;
import battleship.ships.*;
import battleship.games.*;
public class MissionRunner {
public static Class<? extends Ship> PLAYER_CLASS = battleship.ships.DummyShip.class;
public static void main(String[] args) {
try {
int n = Integer.parseInt(args[0]);
Game mission = null;
if (args.length >= 2) {
String className = args[1];
Class<?> c = Class.forName(className);
@SuppressWarnings("unchecked")
Class<? extends Ship> playerClass = (Class<? extends Ship>) c;
mission = getMission(n, playerClass);
} else {
mission = getMission(n, PLAYER_CLASS);
}
if (mission != null) {
mission.setSeed(42);
mission.run();
} else {
System.out.println("Could not find Mission #" + n);
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static Game getMission(int n, Class<? extends Ship> pc) {
switch (n) {
case 1:
return new Mission01(pc);
case 2:
return new Mission02(pc);
case 3:
return new Mission03(pc);
default:
return null;
}
}
}