-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulationController.java
More file actions
94 lines (84 loc) · 2.47 KB
/
Copy pathSimulationController.java
File metadata and controls
94 lines (84 loc) · 2.47 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
import ecs100.*;
import java.awt.*;
/**
* This class manages and operates the simulation
*
* @author Siôn Grabham-Madden
* @version 1
*/
public class SimulationController {
public ActiveArea area;
public boolean firstSim;
public boolean simRunning;
/**
* Constructor
*/
public SimulationController() {
area = new ActiveArea();
firstSim = true;
simRunning = false;
}
/**
* This method sets up the UI and other important details.
*/
public static void main(String[] arg) {
SimulationController controller = new SimulationController();
controller.initialise();
}
/**
* This method initialises the UI of the simulation.
*/
public void initialise() {
UI.initialise();
UI.setImmediateRepaint(false);
UI.addButton("Initialise Predator-Prey simulation", this::predatorPrey);
UI.println("Welcome to a cellular automata simulation program.");
UI.println("This program simulates a Predator-Prey environment.");
UI.println("Please initialise the simulation.");
UI.println("You may then begin.");
}
/**
* This method prepares the Predator-Prey simulation model.
*/
public void predatorPrey() {
if (firstSim) {
UI.addButton("Start simulation",this::simulate);
UI.addButton("Stop simulation",this::end);
firstSim = false;
}
area.instantiate();
UI.clearPanes();
this.draw();
UI.println("Simulation initialised.");
}
/**
* This method loops through the simulation.
*/
public void simulate() {
UI.clearText();
UI.println("Simulation is now running.");
simRunning = true;
while(simRunning) {
area.step();
draw();
//UI.sleep(10);
}
}
/**
* This method ends the loop, stopping the simulation.
*/
public void end() {
simRunning = false;
UI.clearText();
UI.println("Simulation has stopped.");
UI.println("To continue current simulation, press start again.");
UI.println("To run a new simulation, please initialise.");
}
/**
* This method will render the simulation.
*/
public void draw() {
area.draw();
UI.repaintGraphics();
}
}