-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameController.java
More file actions
106 lines (79 loc) · 2.42 KB
/
GameController.java
File metadata and controls
106 lines (79 loc) · 2.42 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
import java.util.ArrayList;
import common.Game;
import common.Location;
import common.Machine;
import demo.Game_demo;
import demo.Machine_0100;
public class GameController {
public static void main(String[] args) {
GameController controller = new GameController();
controller.init();
}
void init() {
// set up and initialize machines
machines = new ArrayList<>();
game = new Game_demo();
// add a bunch of different machines. For now, all demo machines
// These will be replaced by machines of different students
// Add as many as you would like, and change numFaults accordingly (but less than 1/3 of total machines)
machines.add(new Machine_0100());
machines.add(new Machine_0100());
machines.add(new Machine_0100());
machines.add(new Machine_0100());
machines.add(new Machine_0100());
machines.add(new Machine_0100());
machines.add(new Machine_0100());
// change the following as needed
int numFaults = 2;
int stepSize = 4;
int dispTime = 200;
Machine.setMoveStep(500);
// Try not to change anything beyond this
for(Machine machine: machines) {
machine.setStepSize(stepSize); // pixels to move in each step
machine.start(); // starts the machine running in its own thread
}
game.addMachines(machines, numFaults);
// set up GUI
gameDisp = new GameDisplay(this,machines.size());
gameDisp.init();
for (int i = 0; i < 2000; i++) {
gameDisp.clear();
gameDisp.update();
try {
Thread.sleep(dispTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
public void startPhase(int leaderId, ArrayList<Boolean> correctMachines) {
game.startPhase(leaderId, correctMachines);
}
public void updateView() {
gameDisp.clear();
for(Machine machine: machines) {
Location pos = machine.getPosition();
gameDisp.drawCircle(pos, 10);
gameDisp.drawText(pos, machine.name());
//System.out.println(pos + machine.name());
}
}
private Game game;
private GameDisplay gameDisp;
ArrayList<Machine> machines;
}
/*
for(int i=0;i<100;i++) {
for(Machine machine: machines) {
Location pos = machine.getPosition();
System.out.println(machine.name() + ":" + pos.getX() + "," + pos.getY() );
}
game.startPhase();
try {
Thread.sleep(sleepTime);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
*/