This repository has been archived by the owner on Aug 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCovidCounter.java
191 lines (161 loc) · 4.98 KB
/
CovidCounter.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
/**
* The COVID Counter Station in the Restaurant. Used for both the training and actual level
*
* Last edit: 6/17/2020
* @author Celeste
* @version 1.0
* @since 1.1
*/
import java.awt.*;
import javax.swing.*;
public class CovidCounter extends TrainingLevel {
/**
* Whether the user is in a training level
*/
private boolean inTraining;
/**
* Interactive hand sanitizer
*/
private ImageButton sanitizer;
/**
* Interactive box of gloves
*/
private ImageButton gloveBox;
/**
* Interactive box of masks
*/
private ImageButton maskBox;
/**
* ImageButton to exit the station
*/
private ImageButton returnButton;
/**
* Whether the instruction regarding how to interact with PPE is to be shown
*/
private boolean showInstruction;
/**
* The last millisecond that the change message showed up
*/
private long lastUpdate;
/**
* The PPE that was last changed by the user
*/
private String lastChanged;
/**
* Constructs a station
* @param inTraining whether the user is in a training level or not
*/
public CovidCounter(boolean inTraining) {
super("COVID Counter", false);
showInstruction = !inTraining;
lastUpdate = 0;
sanitizer = new ImageButton("sanitizer", 560, 175, Utility.TEXT_FONT, Utility.loadImage("Sanitizer.png", 100, 180), -21);
maskBox = new ImageButton("masks", 320, 253, Utility.TEXT_FONT, Utility.loadImage("MaskBox.png", 160, 80));
gloveBox = new ImageButton("gloves", 100, 250, Utility.TEXT_FONT, Utility.loadImage("GloveBox.png", 160, 84), -1);
returnButton = new ReturnButton(50, Utility.FRAME_HEIGHT - 75);
training = new CounterDrawing();
Utility.changeDrawing(training);
bgm = new BGM("station");
bgm.play();
}
/**
* Activate the listeners of any components of the level
* @param component whether the info placard or the dialogue should be activated
*/
public void activate(boolean components) {
if (!components) super.activate();
else {
returnButton.activate();
gloveBox.activate();
maskBox.activate();
sanitizer.activate();
}
}
/**
* Deactivate the listeners of any components of the level
*/
public void halt() {
super.deactivate();
returnButton.deactivate();
gloveBox.deactivate();
maskBox.deactivate();
sanitizer.deactivate();
}
/**
* The drawing of a COVID Counter level screen
*/
private class CounterDrawing extends JComponent {
public CounterDrawing() {
activate(showInstruction);
}
/**
* Updates the last changed PPE
* @param btn the ImageButton of the selected PPE
*/
private void updatePPE(ImageButton btn) {
lastUpdate = System.currentTimeMillis();
lastChanged = btn.getName();
btn.resetClicked();
}
/**
* Paint method of JComponent
* @param g the Graphics object to draw on
*/
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
g.drawImage(background,0,0,null);
sanitizer.draw(g);
maskBox.draw(g);
gloveBox.draw(g);
returnButton.draw(g);
if (!showInstruction) {
if (infoCard != null && !infoCard.canProceed()) {
infoCard.draw(g);
} else {
infoCard.deactivate();
activate(true);
showInstruction = true;
}
}
if (showInstruction) {
String instruction = "Click on a PPE to put it on";
g.setColor(Color.black);
g.setFont(Utility.TEXT_FONT);
g.drawString(instruction, (Utility.FRAME_WIDTH - Utility.getStringWidth(instruction, g))/2, 100);
String message = "Your current PPE: ";
if (CovidCashier.getPastRestaurant().getUser().getPPE().startsWith("M")) message += "mask";
if (CovidCashier.getPastRestaurant().getUser().getPPE().endsWith("G")) message += (CovidCashier.getPastRestaurant().getUser().getPPE().length() == 2 ? ", " : "") + "gloves";
if (message.endsWith(" ")) message += "none";
g.drawString(message, (Utility.FRAME_WIDTH - Utility.getStringWidth(message, g))/2, 130);
}
if (maskBox.isClicked()) {
CovidCashier.getPastRestaurant().getUser().putOnMask();
SoundFX.play("glovebox",300);
updatePPE(maskBox);
} else if (gloveBox.isClicked()) {
CovidCashier.getPastRestaurant().getUser().putOnGloves();
SoundFX.play("glovebox",300);
updatePPE(gloveBox);
} else if (sanitizer.isClicked()) {
CovidCashier.getPastRestaurant().getUser().cleanHands();
SoundFX.play("sanitizer",300);
updatePPE(sanitizer);
} else if (returnButton.isClicked()) {
halt();
bgm.stop();
Utility.backToRestaurant();
return;
}
if (lastUpdate >= System.currentTimeMillis() - 5000) {
String message = "";
if (lastChanged.equals("sanitizer")) message = "You cleaned your hands";
else if (lastChanged.equals("gloves")) message = "You put on gloves";
else if (lastChanged.equals("masks")) message = "You put on a mask";
g.setColor(Color.black);
g.setFont(Utility.TEXT_FONT_SMALL);
g.drawString(message, (Utility.FRAME_WIDTH - Utility.getStringWidth(message, g))/2, Utility.FRAME_HEIGHT - 50);
}
}
}
}