-
Notifications
You must be signed in to change notification settings - Fork 117
/
Copy pathgeo_quiz.py
460 lines (409 loc) · 15.2 KB
/
geo_quiz.py
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
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
__author__ = 'Mays D'
# Ref:
# http://stackoverflow.com/questions/29767777/gui-quiz-using-easygui-and-pygame-issue-with-quieting-the-game-and-playing-sound
#We start by importing a few libraries.
#Easygui provides our GUI for the game.
import sys
sys.path.append('..') ;# This is only needed in Robert Lugg's development environment
from easygui import *
#Time is a library that introduces the concept of time to the game.
import time
#Pygame is a series of multimedia tools that can create games using Python.
import pygame
#To start pygame we need to initialise it.
pygame.init()
#To use the audio facilities of Pygame we need to tell Pygame that we wish to use them.
pygame.mixer.init()
#Now we create three functions, these functions contain the code to play each audio track.
#The audio for each of these functions should be in the same folder as this code.
def intro():
# pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=4096)
# pygame.mixer.music.load("audio/intro.ogg")
# pygame.mixer.music.play()
intro = pygame.mixer.Sound('audio/intro.ogg')
intro.play(1)
def win():
win = pygame.mixer.Sound('audio/correct.mp3')
win.play(1)
def lose():
lose = pygame.mixer.Sound('audio/wrong.mp3')
lose.play(1)
#To keep our score, we create a variable called score and set it to zero.
score = 0
#The next variable contains the location of the KS2 geography project logo.
logo = "./images/globe.jpg"
#This is a list, sometimes called an array. In here I store two items.
play = ["Yes","No"]
#I start the game by calling the intro() function, and this plays the quiz theme.
intro()
#Here we create a variable called game_start and it will store the answer to the question "Would you like to play the quiz?"
#To capture the answer I use the buttonbox function from easygui. This function has many options, for this I use.
#title = The text at the top of the dialog box.
#image = logo, the variable I earlier created.
#msg = This is the question that I ask the player.
#choices = play. I use this to reference the earlier created list and use the values contained as the choices for the player.
start_title = "Welcome to KS2 Geography Game Quiz"
start_msg = "Would you like to play the Quiz?"
game_start = buttonbox(title=start_title,image=logo,msg=start_msg,choices=play)
#For debugging purposes I have the answer given by the player printed to the Python shell.
print(game_start)#Here we see some conditional logic that tests to see if the answer was "Yes" If the answer is not equal to No, it proceeds.
if game_start != "No":
#Here is another easygui dialog box, a message box. It has the same syntax as the previous box we created.
#You can see str(score) in the line below. In order to join a string of text, our message, with the value
#of the score we need to wrap the score, which is an integer, in a helper function that converts integers
#and floats into strings
msgbox(title="Let us begin",msg="Your score is "+str(score))
count = 0
#Question 1
for i in range(0,4):
msg = "Where is capital of the Netherlands?"
hint1 = "It's not Tehran"
hint2 = "It's not London"
title = "Question 1"
q1choices = ["Tehran","London","Amsterdam","Abu Dhabi"]
if count==0:
q1 = choicebox(msg,title,q1choices)
elif count ==1:
msg += hint1
q1 = choicebox(msg,title,q1choices)
else:
msg += hint2
q1 = choicebox(msg,title,q1choices)
if q1 is None:
print("ok, end of game")
exit()
if q1 == "Amsterdam":
win()
if count == 0:
score += 1
elif count ==1:
score +=0.8
else:
score +=0.6
correct = ("Well done you got it right. Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count = 0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count +=1
#Question 2
for i in range(0,4):
msg = "Which Continent is Britian part of?"
hint1 = " You should know this one!"
hint2 = " It is the smallest of them all..."
title = "Question 2"
q2choices = ["Europe","America", "Asia","Africa"]
if count == 0:
q2 = choicebox(msg,title,q2choices)
elif count ==1:
msg += hint1
q2 = choicebox(msg,title,q2choices)
else:
msg += hint2
q2 = choicebox(msg,title,q2choices)
if q2 == "Europe":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Well done you got it right. Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count =0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count += 1
#Question 3
for i in range(0,4):
msg = "Which of these countries are not in European Union?"
hint1 = " located next to Greece!"
hint2 = " Capital city of this country called Tirana!"
title = "Question 3"
q3choices = ["Latvia","Albania","Estonia","France"]
if count == 0:
q3 = choicebox(msg,title,q3choices)
elif count ==1:
msg += hint1
q3 = choicebox(msg,title,q3choices)
else:
msg += hint2
q3 = choicebox(msg,title,q3choices)
if q3 == "Albania":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Well done you got Albania! hard wasnt it? Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count = 0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer only 3rd Question!"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count += 1
#Question 4
for i in range(0,4):
msg = "How many continents are in the world?"
hint1 = " count all of them! "
hint2 = " Really? "
title = "Question 4"
q4choices = ["7","3","5","4"]
if count == 0:
q4 = choicebox(msg,title,q4choices)
elif count ==1:
msg += hint1
q4 = choicebox(msg,title,q4choices)
else:
msg += hint2
q4 = choicebox(msg,title,q4choices)
if q4 == "7":
win()
if count ==0:
score +=1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Was easy right? Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count =0
break
else:
lose()
wrong = "nice try! Think again and dont forget to add them all up..."
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
#Question 5
for i in range(0,4):
msg = "Where is the largest country in Europe?"
hint1 = " It is outside EU!"
hint2 = " It is also the Largest country in the world!"
title = "Question 5"
q5choices = ["France","Germany","Russia","UK"]
if count ==0:
q5 = choicebox(msg,title,q5choices)
elif count ==1:
msg+=hint1
q5 = choicebox(msg,title,q5choices)
else:
msg+=hint2
q5 = choicebox(msg,title,q5choices)
if q5 == "Russia":
win()
if count==0:
score += 1
elif count ==1:
score+=0.8
else:
score+=0.6
correct = ("Well done you got it right. Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count=0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
#Question 6
for i in range(0,4):
msg = "What is a book of maps called?"
hint1 = " I Think you pressed the wrong choice by mistake!"
hint2 = " Really?"
title = "Question 6"
q6choices = ["Dictionary","Book","Atlas","Atlantic"]
if count ==0:
q6 = choicebox(msg,title,q6choices)
elif count ==1:
msg+=hint1
q6 = choicebox(msg,title,q6choices)
else:
msg+=hint2
q6 = choicebox(msg,title,q6choices)
if q6 == "Atlas":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Din not need to think about it right? Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count=0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer! but keep thinking"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
#Question 7
for i in range(0,4):
msg = "Which is the largest desert in the world?"
hint1 = " The area of this desert is 9 400 000 SQ KM"
hint2 = " it is located in Africa"
title = "Question 7"
q7choices = ["Malavi","Sahara","Gobi","Arabia"]
if count == 0:
q7 = choicebox(msg,title,q7choices)
elif count ==1:
msg+= hint1
q7 = choicebox(msg,title,q7choices)
else:
msg+=hint2
q7 = choicebox(msg,title,q7choices)
if q7 == "Sahara":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("GOOD job mate! hard ones are comimg... Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count=0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
#Question 8
for i in range(0,4):
msg = "Which is the highest mountain in Britain?"
hint1 = " i did not know it myslef so cant help :)"
hint2 = " It is located in Scotland somewhere!"
title = "Question 8"
q8choices = ["Everest","Mont Blanc","Ben Nevis","Ben Mac"]
if count==0:
q8 = choicebox(msg,title,q8choices)
elif count ==1:
msg+=hint1
q8 = choicebox(msg,title,q8choices)
else:
msg+=hint2
q8 = choicebox(msg,title,q8choices)
if q8 == "Ben Nevis":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Well done you got it right. Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count=0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count += 1
#Question 9
for i in range(0,4):
msg = "When do you see rainbow?"
hint1 = " water must be available in air to form a rainbow!"
hint2 = " vright light in air plus water will cause this beautiful phenonema!"
title = "Question 9"
q9choices = ["When Rainy & Sunny","When Windy & Sunny","When Cloudy & Rainy","When Foggy & Rainy"]
if count ==0:
q9 = choicebox(msg,title,q9choices)
elif count ==1:
msg+=hint1
q9 = choicebox(msg,title,q9choices)
else:
msg+=hint2
q9 = choicebox(msg,title,q9choices)
if q9 == "When Rainy & Sunny":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
correct = ("Well done you got it right again... Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count =0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
#Question 10
for i in range(0,4):
msg = "Which is not a precipitation?"
hint1 = " Google it!"
hint2 = " it doesnt come from sky!"
title = "Question 10"
q10choices = ["Rain","Snow","Hail","Frost"]
if count ==0:
q10 = choicebox(msg,title,q10choices)
elif count ==1:
msg+=hint1
else:
msg+=hint2
q10 = choicebox(msg,title,q10choices)
if q10 == "Frost":
win()
if count ==0:
score += 1
elif count ==1:
score += 0.8
else:
score += 0.6
score += 1
correct = ("Well done you got it right. Your score is "+str(score))
image = "./images/tick.gif"
msgbox(title="CORRECT",image=image,msg=correct)
count =0
break
else:
lose()
wrong = "I'm sorry that's the wrong answer your score is lowering"
image = "./images/cross.gif"
msgbox(title="Wrong Answer",image=image,msg=wrong)
count+=1
gameover_good = "./images/well_done.gif"
gameover_bad = "./images/trymore.jpg"
intro()
game_over_title = "KS2 Geography Quiz"
msg_bad = ("Oh dear you scored "+str(score))
msg_good = ("Well done you scored "+str(score))
if score < 5:
game_over = msgbox(title = game_over_title,image = gameover_bad,msg = msg_bad)
else:
game_over = msgbox(title = game_over_title,image = gameover_good,msg = msg_good)