-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSettings.java
executable file
·205 lines (188 loc) · 5.53 KB
/
Settings.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
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The settings world for the simulator. Users can adjust values here.
*
* @author Jimmy, Adrian, Daniel
* @version April 24, 2024
*/
public class Settings extends World {
Label indexTitle = new Label("Index", 45);
Label sustainable = new Label("Sustainability Index: 0", 36);
Label economic = new Label("Economic Prosperity Rating: 0", 36);
Label community = new Label("Community Well-being Index: 0", 36);
Label industryTitle = new Label("Industry (Select 3-6)", 45);
Label next = new Label("Next", 45);
Label eventLabel = new Label("ON", 36);
Label round = new Label("", 24);
Button nextBtn = new NextButton();
private EventButton eventButton = new EventButton();
private RoundButton roundButton = new RoundButton();
private CycleButton cycleButton = new CycleButton();
private MoneyButton moneyButton = new MoneyButton();
private Button[] indexButton;
private IndustryButton[] industryButton;
private boolean[] selectedIndustry = new boolean[9];
private int[] btnY = {180, 240, 300};
private int dir;
private int buttonCount = 6;
private int selectCount = 0;
private int coinStep = 1000;
private int numOfCycles = 6; // 5, 10, 15
private boolean event = false;
private int SI, EPR, CWI, cycle;
// test text
Label test = new Label("true", 45);
/**
* Constructor for objects of class Settings.
*
* @param width The width for the world
* @param height The height for the world
*/
public Settings(int width, int height) {
// Create a new world with 600x400 cells with a cell size of 1x1 pixels.
super(width, height, 1);
SI = 0;
EPR = 0;
CWI = 0;
spawnText();
spawnIndexButtons();
spawnIndustryGrid();
}
/** Act method */
public void act() {
checkPressedButton();
}
/** Spawns the Labels for each Index and Industry */
public void spawnText() {
addObject(indexTitle, getWidth() / 10, 60);
addObject(sustainable, getWidth() / 4, 180);
addObject(economic, getWidth() / 4, 240);
addObject(community, getWidth() / 4, 300);
addObject(industryTitle, getWidth() / 10 * 6, 60);
addObject(next, getWidth() - 175, 650);
addObject(eventButton, getWidth() / 4, 400);
addObject(moneyButton, getWidth() / 4, 560);
addObject(cycleButton, getWidth() / 4 * 3, 580);
}
/** Spawns the Buttons */
public void spawnIndexButtons() {
indexButton = new Button[6];
for (int i = 0; i < 6; i++) {
if (i % 2 == 0) {
indexButton[i] = new AddButton();
dir = 1;
} else {
indexButton[i] = new SubtractButton();
dir = -1;
}
addObject(indexButton[i], getWidth() / 4 + (245 * dir), btnY[i / 2]);
}
addObject(nextBtn, getWidth() - 110, 650);
}
/** Spawns the Industry grid */
public void spawnIndustryGrid() {
industryButton = new IndustryButton[9];
for (int i = 0; i < 9; i++) {
industryButton[i] = new IndustryButton(i);
int upDown = 0;
if (i == 1 | i == 4 | i == 7) {
dir = 0;
} else if (i == 2 | i == 5 | i == 8) {
dir = 1;
} else {
dir = -1;
}
if (i < 3) {
upDown = -1;
} else if (i > 2 && i < 6) {
upDown = 0;
} else {
upDown = 1;
}
addObject(
industryButton[i],
getWidth() / 4 * 3 + (135 * dir),
getHeight() / 7 * 3 + (135 * upDown));
}
}
public void checkPressedButton() {
for (int i = 0; i < indexButton.length; i++) {
if (indexButton[i].checkClicked()) {
switch (i) {
case 0:
if (SI < 5) {
SI++;
}
break;
case 1:
if (SI > -5) {
SI--;
}
break;
case 2:
if (EPR < 5) {
EPR++;
}
break;
case 3:
if (EPR > -5) {
EPR--;
}
break;
case 4:
if (CWI < 5) {
CWI++;
}
break;
case 5:
if (CWI > -5) {
CWI--;
}
break;
}
sustainable.setValue("Sustainability Index: " + SI);
economic.setValue("Economic Prosperity Rating: " + EPR);
community.setValue("Community Well-being Index: " + CWI);
}
}
for (int i = 0; i < industryButton.length; i++) {
IndustryButton button = industryButton[i];
if (button != null && industryButton[i].checkClicked()) {
if (!button.toggleState && selectCount < 6) {
button.toggle();
selectedIndustry[i] = true;
selectCount++;
} else if (button.toggleState) {
button.toggle();
selectedIndustry[i] = false;
selectCount--;
}
}
}
if (eventButton.checkClicked()) {
event = !event;
} else if (eventButton.openDis(eventButton.cheakDis())) {
addObject(test, getWidth() / 2, getHeight() / 2);
}
if (nextBtn != null && nextBtn.checkClicked() && selectCount >= 3) {
MainWorld main =
new MainWorld(
getWidth(),
getHeight(),
SI,
CWI,
EPR,
selectedIndustry,
eventButton.getState(),
cycleButton.getCycle(),
moneyButton.getInitialMoney());
Greenfoot.setWorld(main);
}
}
public void stopped() {
TitleScreen.stopBGM();
}
public void started() {
TitleScreen.playBGM();
}
}