Skip to content

Commit 3b2ffd0

Browse files
Changes for today
1 parent 4791cef commit 3b2ffd0

File tree

9 files changed

+60
-18
lines changed

9 files changed

+60
-18
lines changed

MatchGame.py

Lines changed: 47 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import os
44
import random
55
import sys
6-
import time #only for testing
76
import codecs
87
from Photo import Photo
98
#from gi.repository import Gtk
@@ -20,8 +19,7 @@ def __init__(self):
2019
self.flaghistory = []
2120

2221
def startScreen(self):
23-
# Can be added on OLPC to load other fonts
24-
#pygame.font.SysFont()
22+
#pygame.font.SysFont() #This can be used to add special fonts
2523
file = open("highscore.txt", "r")
2624
self.highscore = file.read()
2725
file.close()
@@ -49,11 +47,12 @@ def startScreen(self):
4947
self.screen.fill((255,255,255))
5048
self.screen.blit(pygame.image.load(self.backgroundimg), (0,150))
5149
self.screen.blit(self.font1.render("Level Selector", True, (0, 0, 0)),(150,50))
52-
self.screen.blit(self.font2.render("Type the level you would like (1-4)", True, (0, 0, 0)),(150,150))
53-
self.screen.blit(self.font3.render("Level 1 (Easy) - 2 flags", True, (0, 0, 0)), (150,250))
54-
self.screen.blit(self.font3.render("Level 2 (Medium) - 3 flags", True, (0, 0, 0)), (150,300))
55-
self.screen.blit(self.font3.render("Level 3 (Hard) - 4 flags", True, (0, 0, 0)), (150,350))
56-
self.screen.blit(self.font3.render("Level 4 (Very Hard) - 5 flags", True, (0, 0, 0)), (150,400))
50+
self.screen.blit(self.font2.render("Type the level you would like using number keys (1-4)", True, (0, 0, 0)),(150,150))
51+
leveltext = ["Level 1 - (Easy) - 2 flags", "Level 2 (Medium) - 3 flags", "Level 3 (Hard) - 4 flags", "Level 4 (Very Hard) - 5 flags"]
52+
textlocation = 200
53+
for i in range(len(leveltext)):
54+
textlocation += 50
55+
self.screen.blit(self.font3.render(leveltext[i], True, (0, 0, 0)), (150,textlocation))
5756
if invalid == True:
5857
self.screen.blit(self.font2.render("Invalid selection", True, (255, 0, 0)), (400,600))
5958
pygame.display.flip()
@@ -78,6 +77,27 @@ def startScreen(self):
7877
else:
7978
invalid = True
8079

80+
def instructionScreen(self):
81+
wait = True
82+
while wait:
83+
self.screen.fill((255, 255, 255))
84+
self.screen.blit(pygame.image.load(self.backgroundimg), (0,150))
85+
self.screen.blit(self.font1.render("Instructions - Level " + str(self.level), True, (0, 0, 0)),(150, 50))
86+
instructiontext = ["You will be presented with " + str(self.level + 1) + " flags to choose from", "There will be 20 rounds", "Choose the correct flag by clicking the flag image with your mouse", "There will be a map with the location highlighted", "Don't cheat and lookup the location", "At any time during the game, press the 'Q' on your keyboard to quit the game", "At any time during the game, press 'I' to see the instructions again", "Are you ready? Press any key to continue"]
87+
location = 150
88+
for i in range(len(instructiontext)):
89+
location += 50
90+
self.screen.blit(self.font3.render(instructiontext[i], True, (0, 0, 0)),(150, location))
91+
pygame.display.flip()
92+
for event in pygame.event.get():
93+
if event.type == pygame.QUIT:
94+
sys.exit()
95+
elif event.type == pygame.KEYDOWN:
96+
if event.key == pygame.K_q:
97+
sys.exit()
98+
else:
99+
wait = False
100+
81101
def getRandomHand(self):
82102
keeptrying = True
83103
while keeptrying:
@@ -144,7 +164,9 @@ def run(self):
144164
self.score = 0
145165
gmround = 0
146166
self.highscore = int(self.highscore)
147-
while gmround <= 25: #the "10" is the amount of tries you want the user to be able to guess differtnt flags
167+
soundcorrect = pygame.mixer.Sound("sounds/chime.wav")
168+
soundwrong = pygame.mixer.Sound("sounds/buzzer.wav")
169+
while gmround <= 2: #the "10" is the amount of tries you want the user to be able to guess differtnt flags
148170
gmround += 1
149171

150172
#while Gtk.events_pending():
@@ -181,7 +203,7 @@ def run(self):
181203
pygame.display.flip()
182204

183205
keepwaiting = True
184-
while (keepwaiting):
206+
while keepwaiting:
185207

186208
#while Gtk.events_pending():
187209
# Gtk.main_iteration()
@@ -193,17 +215,26 @@ def run(self):
193215
file.write(str(score))
194216
file.close()
195217
sys.exit()
196-
elif (event.type == pygame.MOUSEBUTTONDOWN):
218+
elif event.type == pygame.KEYDOWN:
219+
if event.key == pygame.K_q:
220+
sys.exit()
221+
elif event.key == pygame.K_i:
222+
self.instructionScreen()
223+
keepwaiting = False
224+
gmround -= 1
225+
elif event.type == pygame.MOUSEBUTTONDOWN:
197226
if 0 <= pygame.mouse.get_pos()[0] <= 50 or 175 <= pygame.mouse.get_pos()[0] <= 250 or 375 <= pygame.mouse.get_pos()[0] <= 450 or 575 <= pygame.mouse.get_pos()[0] <= 650 or 775 <= pygame.mouse.get_pos()[0] <= 850 or 975 <= pygame.mouse.get_pos()[0]:
198227
break
199228
elif 175 >= pygame.mouse.get_pos()[1] or 300 <= pygame.mouse.get_pos()[1]:
200229
break
201230
elif pygame.mouse.get_pos()[0] >= clickRect[0] and pygame.mouse.get_pos()[0] < clickRect[1] and 145 <= pygame.mouse.get_pos()[1] <= 245:
202231
keepwaiting = False
203232
self.screen.blit(self.font2.render("Correct", True, (0,250,0)),(300,600))
233+
soundcorrect.play()
204234
self.score += 1
205235
else:
206236
keepwaiting = False
237+
soundwrong.play()
207238
if 50 <= pygame.mouse.get_pos()[0] <= 175:
208239
selectionX = 50
209240
elif 250 <= pygame.mouse.get_pos()[0] <= 375:
@@ -271,20 +302,19 @@ def finishScreen(self):
271302
if event.key == pygame.K_q:
272303
sys.exit()
273304
else:
274-
self.restart = True
275305
keepwaiting = False
276-
elif event.type == pygame.MOUSEBUTTONDOWN:
277-
self.restart = True
278-
keepwaiting = False
306+
self.restart = True
307+
# Why does this need 2 keydowns for both variables to be set???
308+
279309

280310
def main():
281311
pygame.init()
282-
pygame.display.set_mode((0,0),pygame.RESIZABLE)
283-
pygame.display.set_caption("Flag Game")
312+
pygame.display.set_mode((0,0),pygame.FULLSCREEN)
284313
game = MatchGame()
285314
while game.restart:
286315
game.restart = False
287316
game.startScreen()
317+
game.instructionScreen()
288318
game.run()
289319
game.finishScreen()
290320

README.md

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,16 @@ __Note:__ Michael is absent
102102

103103
### Wednesday May 10 - Out of class
104104

105-
* Continue programming (Michael)
105+
* Continue programming (Michael)
106+
107+
### Friday May 12 - In class
108+
109+
* Start debugging (Michael)
110+
* Work on on Tutorial (Troy)
111+
112+
### Saturday May 13 - Out of class
113+
114+
* Minor game enhancements (Michael)
115+
- Add sound
116+
- Make a feature so no flag will appear twice
117+
- Better way to blit text through list

countryimg/Malta.png

32.1 KB
Loading

countryimg/Marshall Islands.png

42.9 KB
Loading

countryimg/Uzbekistan.png

38.3 KB
Loading

sounds/buzzer.wav

16.8 KB
Binary file not shown.

sounds/chime.wav

18.2 KB
Binary file not shown.

0 commit comments

Comments
 (0)