-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMultipleChoice
291 lines (205 loc) · 9.81 KB
/
MultipleChoice
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
package Window;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
import javax.sound.sampled.Clip;
import javax.sound.sampled.UnsupportedAudioFileException;
import Window.Game.STATE;
public class MultipleChoice extends MouseAdapter {
int score = 0;
int counter = 0;
Game game;
Handler handler;
public BufferedImage level = null;
public MultipleChoice(Game game, Handler handler) {
this.game = game;
this.handler = handler;
}
public void mousePressed(MouseEvent e) {
int mouseX = e.getX(); // it finds the position of x when clicking the mouse
int mouseY = e.getY(); // it finds the position of y when clicking the mouse
if (game.state == STATE.MULTIPLECHOICE) {// when answered correctly and the correct answers for counter +1
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 170, 300, 82)) && (counter == 2)) { // when clicking
// "A"
// 3rd question is A
game.state = STATE.CORRECT;
score++;
}
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 300, 300, 82)) && ((counter == 3) || (counter == 4))) { // When
// B
// 4rd and 5th questions are B
game.state = STATE.CORRECT;
score++;
}
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 430, 300, 82)) && ((counter == 0) || (counter == 1))) { // When
// C
// 1st and 2nd questions are C
game.state = STATE.CORRECT;
score++;
}
}
if (game.state == STATE.MULTIPLECHOICE) { // when it is answered wrong and wrong answers
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 170, 300, 82))
&& ((counter == 0) || (counter == 1) || (counter == 3) || (counter == 4))) { // when clicking "A"
game.state = STATE.FALSE;
}
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 300, 300, 82))
&& ((counter == 0) || (counter == 1) || (counter == 2))) { // When clicking "B",
game.state = STATE.FALSE;
}
if ((mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 150, 430, 300, 82))
&& ((counter == 2) || (counter == 3) || (counter == 4))) { // When clicking "C"
game.state = STATE.FALSE;
}
}
if (game.state == STATE.CORRECT) { // location of pressing for the next question after each question
if (mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 10, 500, 300, 82)) {
game.state = STATE.MULTIPLECHOICE;
counter++;
}
}
if (game.state == STATE.FALSE) {
if (mouseOver(mouseX, mouseY, Game.WIDTH / 2 - 10, 500, 300, 82)) {
game.state = STATE.MULTIPLECHOICE;
counter++;
}
}
}
private boolean mouseOver(int mouseX, int mouseY, int x, int y, int width, int height) { // checks whether our mouse
// coordinates is in the
// same area as the
// buttons
if (mouseX > x && mouseX < x + width) {
if (mouseY > y && mouseY < y + height) {
return true; // when clicking the mouse, the x and y value are both within the button's
// boundaries, and you will open up the button that you click on
} else
return false; // when clicking the mouse, the x value is inside the button's left and right
// boundaries. However the y value is not - and nothing will happen
} else
return false; // when clicking the mouse, if the x value is not within the button's left and
// right boundaries, nothing will happen
}
public void mouseReleased(MouseEvent e) {
}
public void tick() {
}
public Rectangle AButton = new Rectangle(Game.WIDTH / 2 - 150, 170, 300, 82); // placement and size of button A
// (without text)
public Rectangle BButton = new Rectangle(Game.WIDTH / 2 - 150, 300, 300, 82); // placement and size of
// button B (without text)
public Rectangle CButton = new Rectangle(Game.WIDTH / 2 - 150, 430, 300, 82); // placement and size of button C
// (without text)
public Rectangle NextButton = new Rectangle(Game.WIDTH / 2 - 10, 500, 300, 82); // placement and size of button Next
// Question
// (without text)
public void render(Graphics g) {
Graphics2D g2d = (Graphics2D) g;
Font hudMenu1 = new Font("gtubh", Font.ITALIC, 18); // title font
Font hudMenu2 = new Font("gtubh", Font.ITALIC, 25); // subtitle/menu font
if (game.state == STATE.MULTIPLECHOICE && counter == 0) {
g.setFont(hudMenu1); // we use this font
g.setColor(Color.WHITE); // color of text
String q1line1 = ("How long has the paty “Venstre” existed?");
g.drawString(q1line1, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(AButton); // draws the button A
g2d.draw(BButton); // draws the button B
g2d.draw(CButton); // draws the button C
g.setFont(hudMenu2); // we use this font
g.drawString("A: 50 years", Game.WIDTH / 2 - 140, 220); // drawing the A text
g.drawString("B: 100 years", Game.WIDTH / 2 - 140, 350); // drawing the B text
g.drawString("C: above 100 years", Game.WIDTH / 2 - 140, 480); // drawing the C text
}
if (game.state == STATE.MULTIPLECHOICE && counter == 1) {
g.setFont(hudMenu1); // we use this font
g.setColor(Color.WHITE); // color of text
String q2line1 = ("Which ideology is “Venstres” based on?");
// String q1line2 = "question continued";
g.drawString(q2line1, Game.WIDTH / 2 - 350, 30); // drawing the title
// g.drawString(q1line2, Game.WIDTH / 2 - 350, 60); // drawing the title
g2d.draw(AButton); // draws the button A
g2d.draw(BButton); // draws the button B
g2d.draw(CButton); // draws the button C
g.setFont(hudMenu2); // we use this font
g.drawString("A: Socialism", Game.WIDTH / 2 - 140, 220); // drawing the A text
g.drawString("B: Conservatism", Game.WIDTH / 2 - 140, 350); // drawing the B text
g.drawString("C: Liberalism", Game.WIDTH / 2 - 140, 480); // drawing the C text
}
if (game.state == STATE.MULTIPLECHOICE && counter == 2) {
g.setFont(hudMenu1); // we use this font
g.setColor(Color.WHITE); // color of text
String q3line1 = (" What is liberalism?");
g.drawString(q3line1, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(AButton); // draws the button A
g2d.draw(BButton); // draws the button B
g2d.draw(CButton); // draws the button C
g.setFont(hudMenu2); // we use this font
g.drawString("A: Human freedom in relation to the state", Game.WIDTH / 2 - 140, 220); // drawing the A text
g.drawString("B: The state plays a central role for the human", Game.WIDTH / 2 - 140, 350); // drawing the B
// // text
g.drawString("C: The state must take care of the weakest", Game.WIDTH / 2 - 140, 480); // drawing the C text
}
if (game.state == STATE.MULTIPLECHOICE && counter == 3) {
g.setFont(hudMenu1); // we use this font
g.setColor(Color.WHITE); // color of text
String q4line1 = (" Which year will “Venstre” abolish new diesel cars?");
// String q1line2 = "question";
g.drawString(q4line1, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(AButton); // draws the button A
g2d.draw(BButton); // draws the button B
g2d.draw(CButton); // draws the button C
g.setFont(hudMenu2); // we use this font
g.drawString("A: 2025", Game.WIDTH / 2 - 140, 220); // drawing the A text
g.drawString("B: 2030", Game.WIDTH / 2 - 140, 350); // drawing the B text
g.drawString("C: 2035", Game.WIDTH / 2 - 140, 480); // drawing the C text
}
if (game.state == STATE.MULTIPLECHOICE && counter == 4) {
g.setFont(hudMenu1); // we use this font
g.setColor(Color.WHITE); // color of text
String q5line1 = ("What is “Venstres” slogan?");
g.drawString(q5line1, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(AButton); // draws the button A
g2d.draw(BButton); // draws the button B
g2d.draw(CButton); // draws the button C
g.setFont(hudMenu2); // we use this font
g.drawString("A: less work hours", Game.WIDTH / 2 - 140, 220); // drawing the A text
g.drawString("B: it has to pay off to work", Game.WIDTH / 2 - 140, 350); // drawing the B text
g.drawString("C: higher salary is the key to welfare", Game.WIDTH / 2 - 140, 480); // drawing the C text
}
else if (game.state == STATE.CORRECT) { // when it is answered correct
g.setColor(Color.GREEN); // color of text
String correct = "HOOORAY, your score is " + score + " now next question:";
g.drawString(correct, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(NextButton); // draws the next button
g.drawString("Next Question", Game.WIDTH / 2 - 0, 550); // drawing the next question text
//audio part, if it is correct it will play the audio, only type wav
try {
AudioInputStream ais = AudioSystem.getAudioInputStream(new File("/Users/ilaydabuyukdogan/eclipse-workspace/marioP1/src/Music/correct.wav"));
Clip clip = AudioSystem.getClip();
clip.open(ais);
clip.start();
for (int i=0; i<300000; i++) //plays the sound for this amount of time
System.out.println("");
}
catch (UnsupportedAudioFileException e1) { }
catch(Exception e) {e.printStackTrace();
}
} else if (game.state == STATE.FALSE) { // when it is answered false
Font hudMenu3 = new Font("gtubh", Font.ITALIC, 18); // title font
g.setFont(hudMenu3); // we use this font
g.setColor(Color.RED); // color of text
String notCorrect = "OH NO your score is " + score + " try the next question:";
g.drawString(notCorrect, Game.WIDTH / 2 - 350, 30); // drawing the title
g2d.draw(NextButton); // draws the next button
g.drawString("Next Question", Game.WIDTH / 2 - 0, 550); // drawing the next question text
}
}
}