-
Notifications
You must be signed in to change notification settings - Fork 0
/
Simulation.java
79 lines (67 loc) · 2.28 KB
/
Simulation.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* Base class for all simulation worlds
*
* @author Austin
* @version 0
*/
public class Simulation extends World {
protected Button startButton;
protected Button backButton;
protected Button resetButton;
protected Button helpButton;
protected Button exitButton;
protected boolean started = false;
/**
* Constructor for objects of class Simulation.
*
*/
public Simulation() {
// Create an unbounded new world with 1200x800 cells with a cell size of 1x1 pixels.
super(1200, 800, 1, false);
prepare();
}
/**
* Listen for start and top bar button presses
*/
public void act() {
if (startButton.mouseDown()) {
begin();
}
if (backButton.mouseDown()) {
Greenfoot.setWorld(new Menu());
}
if (exitButton.mouseDown()) {
Greenfoot.stop();
}
}
/**
* Create the start and top bar buttons and add them to the world
*/
protected void prepare() {
startButton = new Button(948, 329, 187, 187, new Color(0, 148, 68, 0));
startButton.addToWorld(this);
startButton.setHoverColour(new Color(0, 148, 68, 120));
startButton.setBorderRadius(94);
// Top bar buttons
backButton = new Button(33, 10, 80, 80, new Color(57, 181, 74, 0));
backButton.addToWorld(this);
backButton.setHoverColour(new Color(57, 181, 74, 140));
resetButton = new Button(875, 10, 80, 80, new Color(57, 181, 74, 0));
resetButton.addToWorld(this);
resetButton.setHoverColour(new Color(57, 181, 74, 140));
helpButton = new Button(988, 10, 80, 80, new Color(57, 181, 74, 0));
helpButton.addToWorld(this);
helpButton.setHoverColour(new Color(57, 181, 74, 140));
exitButton = new Button(1102, 10, 80, 80, new Color(57, 181, 74, 0));
exitButton.addToWorld(this);
exitButton.setHoverColour(new Color(57, 181, 74, 140));
}
/**
* Begin the simulation and disable the start button
*/
protected void begin() {
started = true;
startButton.disable();
}
}