-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellingBeeGame.py
More file actions
269 lines (240 loc) · 8.17 KB
/
SpellingBeeGame.py
File metadata and controls
269 lines (240 loc) · 8.17 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
import pythoncom
import threading
import time
import sys
import pygame
import random
from win32com.client import Dispatch
mywords=[]
with open(file='words.txt', mode='r') as file:
# reading each line
for line in file:
for word in line.split():
mywords.append(word)
X=650
Y=490
white = (255, 255, 255)
yellow=(243,250,0)
pygame.init()
surface=pygame.display.set_mode((X, Y))
pygame.display.set_caption('SpellingBee')
surface.fill(white)
gamerun=1
images=['three.png','two.png','one.png']
pygame.mixer.init()
clock=pygame.time.Clock()
basefont=pygame.font.SysFont('bahnschrift',30)
scorefont=pygame.font.SysFont('comicsansms',33)
highscore=pygame.font.SysFont('comicsansms',23)
bg2=pygame.image.load('bg2.png')
checkbtn=pygame.image.load('check.png')
devname=pygame.font.SysFont('comicsansms',23)
def startgame(gamerun):
background = pygame.image.load('spelling.jpg')
x = 20
y = 20
global devname
for i in range(3):
surface.fill(white)
background = pygame.transform.scale(background, (350+x, 350+y))
surface.blit(background, (40, 50))
picture = pygame.image.load(images[gamerun - 1])
picture = pygame.transform.scale(picture, (80, 80))
surface.blit(picture, (280, 40))
gamerun += 1
# sound = pygame.mixer.Sound('tick.mp3')
# sound.play()
developername = devname.render(f'Developer: Hasanat Lodhi', True, (32, 57, 47))
surface.blit(developername,(180,10))
pygame.display.update()
x+=20
y+=20
pygame.time.wait(1500)
inputrect=pygame.Rect(180,400,260,38)
def maingame():
beeimg = pygame.image.load('spellingbee.jpg')
background = pygame.transform.scale(beeimg, (550, 100))
surface.blit(background, (50, 0))
def playsound():
pass
# sound=pygame.mixer.Sound('beat.mp3')
# sound.set_volume(0.05)
# sound.play()
buttonclick=False
threadingrunning=True
textchoice=random.choice(mywords)
gameisover=False
def sayword():
while threadingrunning:
global buttonclick
global gameisover
if gameisover:
continue
if buttonclick==True:
time.sleep(4)
buttonclick = False
else:
global textchoice
pythoncom.CoInitialize()
speak = Dispatch("SAPI.SpVoice")
speak.Speak(f"Please enter {textchoice}")
time.sleep(5)
start=True
t1 = threading.Thread(target=sayword)
usertext = ''
lives=4
score=0
def checkwords():
global isrruning
global threadingrunning
global textchoice
global score
pythoncom.CoInitialize()
speak = Dispatch("SAPI.SpVoice")
if (usertext == textchoice):
correct = pygame.image.load('correct.png')
correct = pygame.transform.scale(correct, (200, 200))
surface.blit(correct, (220, 135))
pygame.display.update()
clap = pygame.mixer.Sound('clap.wav')
clap.play()
speak.Speak("You entered the correct Spelling")
# time.sleep(2)
bg2 = pygame.image.load('bg2.png')
bg = pygame.transform.scale(bg2, (650, 490))
surface.blit(bg, (0, 0))
pygame.display.update()
score+=1
else:
wrongpic = pygame.image.load('no.png')
wrongpic = pygame.transform.scale(wrongpic, (150, 150))
surface.blit(wrongpic, (230, 155))
pygame.display.update()
wrong = pygame.mixer.Sound('wrongans.wav')
wrong.play()
speak.Speak("You entered the wrong spelling")
global lives
lives -= 1
bg2 = pygame.image.load('bg2.png')
bg = pygame.transform.scale(bg2, (650, 490))
surface.blit(bg, (0, 0))
pygame.display.update()
consective=0
for i in range(lives):
pygame.draw.circle(surface, (17, 43, 32), (40, 190 + consective), 13, 6)
consective += 30
pygame.display.update()
if lives==0:
return True
textchoice = random.choice(mywords)
isrruning=True
gameover=pygame.image.load('gamov.gif')
def totallives():
consective = 0
for i in range(lives):
pygame.draw.circle(surface, (17, 43, 32), (40, 190 + consective), 13, 6)
consective += 30
def endgame():
global score
global lives
global start
global usertext
global gameisover
global textchoice
global threadingrunning
quitpic=pygame.image.load('quit.png')
reply=pygame.image.load('playagain.png')
gameisover=True
while True:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
getpos=pygame.mouse.get_pos()
if getpos[0]>=355 and getpos[0]<=434:
if getpos[1] >= 374 and getpos[0] <= 437:
pygame.quit()
sys.exit()
if getpos[0] >= 201 and getpos[0] <= 268:
if getpos[1] >= 371 and getpos[0] <= 436:
score=0
lives=4
x = 65
y = 50
for i in range(10):
bg = pygame.transform.scale(bg2, (x, y))
surface.blit(bg, (0, 0))
pygame.display.update()
pygame.time.wait(10)
x += 65
y += 50
textchoice=random.choice(mywords)
threadingrunning = True
gameisover = False
spellingbee()
surface.fill((255, 255, 255))
bg = pygame.transform.scale(gameover, (X, Y))
quitpic = pygame.transform.scale(quitpic, (90, 90))
surface.blit(bg, (0, 0))
surface.blit(quitpic, (350, 360))
replypic = pygame.transform.scale(reply, (70, 70))
surface.blit(replypic, (200, 370))
clock.tick(40)
usertext=''
pygame.display.update()
def spellingbee():
global checkbtn
global start
global usertext
global isrruning
global buttonclick
while isrruning:
if start:
startgame(gamerun)
start=False
x = 65
y=50
for i in range (10):
bg=pygame.transform.scale(bg2, (x,y))
surface.blit(bg,(0,0))
pygame.display.update()
pygame.time.wait(10)
x+=65
y+=50
playsound()
t1.start()
for event in pygame.event.get():
if event.type == pygame.QUIT:
# deactivates the pygame library
pygame.quit()
sys.exit()
if event.type==pygame.KEYDOWN:
if event.key==pygame.K_BACKSPACE:
usertext=usertext[:-1]
else:
if(len(usertext)<16):
usertext+=event.unicode
print(usertext)
if event.type == pygame.MOUSEBUTTONDOWN:
getpos=pygame.mouse.get_pos()
if getpos[0]>=460 and getpos[0]<=502:
if getpos[1]>=403 and getpos[1]<=436:
buttonclick=True
returned=checkwords()
if returned:
endgame()
usertext=''
pygame.draw.rect(surface, yellow, inputrect)
text=basefont.render(usertext,True,(0, 51, 102))
textscore=scorefont.render(f'Your score is {score}',True,(255, 51, 0))
surface.blit(text,inputrect)
surface.blit(textscore, (200, 103))
checkbtn = pygame.transform.scale(checkbtn, (50, 50))
surface.blit(checkbtn, (455, 393))
totallives()
pygame.display.update()
clock.tick(40)
maingame()
pygame.display.update()
spellingbee()