-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMillionare.java
More file actions
326 lines (240 loc) · 8.86 KB
/
Copy pathMillionare.java
File metadata and controls
326 lines (240 loc) · 8.86 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
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
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
// By Jacob Schnettler
// Mr. L Advanced Java
// Who Wants to be a Millionare 12/1/22
import java.awt.*;
import java.awt.event.*;
import java.applet.Applet;
import java.util.Random;
public class Millionare extends Applet implements ActionListener
{
String questions[] = new String[8];
String aAnswers[] = new String[8];
String bAnswers[] = new String[8];
String cAnswers[] = new String[8];
String dAnswers[] = new String[8];
Button optionA = new Button();
Button optionB = new Button();
Button optionC = new Button();
Button optionD = new Button();
Button phoneFriendBTN = new Button();
Button audienceHelpBTN = new Button();
Button fiftyFiftyBTN = new Button();
Button walkawayBTN = new Button();
Button visibleButtons[] = {
optionA,
optionB,
optionC,
optionD,
phoneFriendBTN,
audienceHelpBTN,
fiftyFiftyBTN,
walkawayBTN
};
char answers[] = {'C', 'C', 'D', 'C', 'B', 'D', 'B', 'D'};
char charArray[] = {'A', 'B', 'C', 'D'};
int moneyIncrements[] = new int[8];
int questionCt = 0;
char choice = 'Z';
Font title = new Font("Ariel", 1, 25);
Font paragraph = new Font("Ariel", 1, 15);
Random rand = new Random();
String output = "";
Boolean walkedAway = false;
Boolean usedLifeline = false;
public void setData()
{
moneyIncrements[0] = 100;
moneyIncrements[1] = 500;
moneyIncrements[2] = 1000;
moneyIncrements[3] = 10000;
moneyIncrements[4] = 100000;
moneyIncrements[5] = 500000;
moneyIncrements[6] = 800000;
moneyIncrements[7] = 1000000;
questions[0] = "In the UK, the abbreviation NHS stands for National what Service?";
aAnswers[0] = "Honour";
bAnswers[0] = "Humanity";
cAnswers[0] = "Health";
dAnswers[0] = "Household";
questions[1] = "Which Disney character famously leaves a glass slipper behind at a royal ball?";
aAnswers[1] = "Pocahontas";
bAnswers[1] = "Sleeping Beauty";
cAnswers[1] = "Cinderella";
dAnswers[1] = "Elsa";
questions[2] = "What name is given to the revolving belt machinery in an airport that delivers checked luggage from the plane to baggage reclaim?";
aAnswers[2] = "Hangar";
bAnswers[2] = "Terminal";
cAnswers[2] = "Concourse";
dAnswers[2] = "Carousel";
questions[3] = "Which of these brands was chiefly associated with the manufacture of household locks?";
aAnswers[3] = "Phillips";
bAnswers[3] = "Flymo";
cAnswers[3] = "Chubb";
dAnswers[3] = "Ronseal";
questions[4] = "The hammer and sickle is one of the most recognisable symbols of which political ideology?";
aAnswers[4] = "Republicanism";
bAnswers[4] = "Communism";
cAnswers[4] = "Conservatism";
dAnswers[4] = "Liberalism";
questions[5] = "Which toys have been marketed with the phrase “robots in disguise”?";
aAnswers[5] = "Bratz Dolls";
bAnswers[5] = "Sylvanian Families";
cAnswers[5] = "Hatchimals";
dAnswers[5] = "Transformers";
questions[6] = "What does the word loquacious mean?";
aAnswers[6] = "Angry";
bAnswers[6] = "Chatty";
cAnswers[6] = "Beautiful";
dAnswers[6] = "Shy";
questions[7] = "Obstetrics is a branch of medicine particularly concerned with what?";
aAnswers[7] = "Childbirth";
bAnswers[7] = "Broken bones";
cAnswers[7] = "Heart conditions";
dAnswers[7] = "Old age";
}
public void toggleBTNS(Boolean bool)
{
for (int num = 0; num <= visibleButtons.length; num++)
visibleButtons[num].setVisible(bool);
}
public void drawAnswer(Graphics g, String question, int x, int y, String option)
{
g.drawString("" + option + ": " + question, x, y);
}
public void drawOptionBTN(Button btn, String option, int x, int y)
{
btn.addActionListener(this);
btn.setLabel("Choose " + option);
btn.setBounds(x, y + 15, 120, 40);
this.add(btn);
}
public void drawLifeline(Button btn, String label, int x, int y)
{
btn.addActionListener(this);
btn.setLabel(label);
btn.setBounds(x, y + 15, 120, 40);
this.add(btn);
}
public void phoneFriend() {
if (usedLifeline) return;
usedLifeline = true;
if (rand.nextInt(100) > 75) {
output = "Your friend definately thinks its " + answers[questionCt];
} else {
output = "Your friend is not sure but thinks its " + charArray[rand.nextInt(4)];
}
phoneFriendBTN.setVisible(false);
}
public void audienceHelp()
{
if (usedLifeline) return;
usedLifeline = true;
output = "";
char currentAnswer = answers[questionCt];
for (int index = 0; index <= 3; index++) {
char currentCharacter = charArray[index];
if (currentAnswer == currentCharacter) {
output = output + (rand.nextInt(45) + 30) + "% chance its " + currentCharacter + ", ";
} else {
output = output + rand.nextInt(25) + "% chance its " + currentCharacter + ", ";
}
}
audienceHelpBTN.setVisible(false);
}
public void fiftyFifty() {
if (usedLifeline) return;
usedLifeline = true;
if (answers[questionCt] == 'A' || answers[questionCt] == 'B')
{
optionC.setVisible(false);
optionD.setVisible(false);
} else {
optionA.setVisible(false);
optionB.setVisible(false);
}
fiftyFiftyBTN.setVisible(false);
}
public void walkaway() {
if (usedLifeline) return;
usedLifeline = true;
output = "You walked away with " + moneyIncrements[questionCt] + "$";
walkedAway = true;
toggleBTNS(false);
}
public void init()
{
this.setLayout(null);
drawOptionBTN(optionA, "Option A", 100, 150);
drawOptionBTN(optionB, "Option B", 100, 350);
drawOptionBTN(optionC, "Option C", 700, 150);
drawOptionBTN(optionD, "Option D", 700, 350);
drawLifeline(phoneFriendBTN, "Phone a Friend", 400, 550);
drawLifeline(audienceHelpBTN, "Call on Audience", 250, 550);
drawLifeline(fiftyFiftyBTN, "50/50 Question", 100, 550);
drawLifeline(walkawayBTN, "Walkaway", 550, 550);
setData();
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == optionA)
choice = 'A';
else if (e.getSource() == optionB)
choice = 'B';
else if (e.getSource() == optionC)
choice = 'C';
else if (e.getSource() == optionD)
choice = 'D';
if (e.getSource() == phoneFriendBTN)
phoneFriend();
else if (e.getSource() == audienceHelpBTN)
audienceHelp();
else if (e.getSource() == fiftyFiftyBTN)
fiftyFifty();
else if (e.getSource() == walkawayBTN)
walkaway();
else if (answers[questionCt] == choice) {
optionA.setVisible(true);
optionB.setVisible(true);
optionC.setVisible(true);
optionD.setVisible(true);
output = "";
usedLifeline = false;
questionCt++;
} else {
toggleBTNS(false);
output = "Yo u lost man, feelsbadman :(";
}
repaint();
}
public void paint(Graphics g)
{
if (walkedAway) {
g.setFont(title);
g.drawString(output, 250, 250);
} else {
g.setFont(title);
g.drawString(questions[questionCt], 100, 100);
g.setFont(paragraph);
drawAnswer(g, aAnswers[questionCt], 100, 150, "A");
drawAnswer(g, bAnswers[questionCt], 100, 350, "B");
drawAnswer(g, cAnswers[questionCt], 700, 150, "C");
drawAnswer(g, dAnswers[questionCt], 700, 350, "D");
g.drawString(output, 700, 500);
for (int num = 0; num <= 7; num++)
{
Boolean onCurrent = false;
if (num == questionCt) {
onCurrent = true;
g.setColor(Color.red);
}else if (num < questionCt)
g.setColor(Color.green);
else
g.setColor(Color.blue);
if (onCurrent)
g.drawString("$" + moneyIncrements[num] + " - Current", 950, 150 + num * 25);
else
g.drawString("$" + moneyIncrements[num], 950, 150 + num * 25);
}
}
}
}