-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
81 lines (63 loc) · 2.36 KB
/
app.py
File metadata and controls
81 lines (63 loc) · 2.36 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
import pygame
import game_config as gc
from animal import Animal
import pyttsx3 as py
from pygame import display, event, image
from time import sleep
# this fun initializes all the pygame import that we need
# caption of game bar
def main():
display.set_caption("My Rhyme Game")
# mode of the game display
screen = display.set_mode((512, 512))
matched = image.load("other_assets/matched.png")
running = True
tiles = [Animal(i) for i in range (0, gc.NUM_TILES_TOTAL)]
current_images = []
def find_index(x, y):
row = y // gc.IMAGE_SIZE
col = x // gc.IMAGE_SIZE
index = row * gc.NUM_TILES_SIDE + col
return index
while running:
current_events = event.get()
for e in current_events:
# if we QUIT the game display
if e.type == pygame.QUIT:
running = False
if e.type == pygame.KEYDOWN:
if e.key == pygame.K_ESCAPE:
running = False
if e.type == pygame.MOUSEBUTTONDOWN:
mouse_x, mouse_y = pygame.mouse.get_pos()
index = find_index(mouse_x, mouse_y)
if index not in current_images:
current_images.append(index)
if len(current_images) > 2:
current_images = current_images[1:]
screen.fill((255, 255, 255))
total_skipped = 0
for _, tile in enumerate(tiles):
image_i = tile.image if tile.index in current_images else tile.box
if not tile.skip:
screen.blit(image_i, (tile.col * gc.IMAGE_SIZE, tile.row * gc.IMAGE_SIZE))
else:
total_skipped +=1
display.flip()
if len(current_images) == 2:
idx1, idx2 = current_images
if tiles[idx1].name == tiles[idx2].name:
tiles[idx1].skip = True
tiles[idx2].skip = True
sleep(0.4)
screen.blit(matched, (0, 0))
display.flip()
sleep(0.4)
current_images = []
if total_skipped == len(tiles):
running = False
py.speak("You Win The Game Well Played ")
display.flip()
print("Good Bye!!!")
if __name__ == '__main__':
main()