-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
107 lines (80 loc) · 3.3 KB
/
Copy pathmain.py
File metadata and controls
107 lines (80 loc) · 3.3 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
import random
import pygame
pygame.init()
class Game():
def __init__(self, root_width, num):
self.num = num
self.space = 20
self.root_width = root_width
self.width = (self.root_width - self.space*(self.num**(1/2) + 1)) / self.num**(1/2)
self.color = "light blue"
self.root = pygame.display.set_mode([self.root_width, self.root_width])
pygame.display.set_caption("Memory Game")
self.xlocations = self.ylocations = []
self.queqe = self.create_path()
self.comparison = set()
def draw_rect(self, color):
for row in range(int(self.num**(1/2))): #0
for column in range(int(self.num**(1/2))): #0
self.x =self.space*(column+1) + column*self.width
self.y = self.space*(row+1) + row*self.width
pygame.draw.rect(
self.root, color,
(self.x, self.y, self.width, self.width))
self.xlocations.append((self.x, self.x + self.width))
self.ylocations.append(
(self.space*(row+1) + row*self.width, self.space*(row+1) + row*self.width + self.width))
def mouse_loc(self):
self.li = [False, False]
for i in self.xlocations:
if pygame.mouse.get_pos()[0] in range(int(i[0]), int(i[1])):
self.li[0] = i
for j in self.ylocations:
if pygame.mouse.get_pos()[1] in range(int(j[0]), int(j[1])):
self.li[1] = j
return self.li
def pick(self):
if self.mouse_loc() and pygame.mouse.get_pressed()[0]:
try:
x = int(self.mouse_loc()[0][0])
y = int(self.mouse_loc()[1][0])
pygame.draw.rect(self.root, "pink", (x, y, self.width, self.width))
self.comparison.add((x, y))
print(self.queqe)
print(self.comparison)
self.check(self.comparison)
except:
print("pick doğru çalışmadı")
def create_path(self):
self.sett = set()
for row in range(int(self.num**(1/2))): #0
for column in range(int(self.num**(1/2))): #0
self.x =self.space*(column+1) + column*self.width
self.y = self.space*(row+1) + row*self.width
self.sett.add((int(self.x), int(self.y)))
print(self.sett)
return self.sett
def check(self, comparison):
if len(comparison) == len(self.queqe) and comparison == self.queqe:
print("Tamamdır")
self.reset_path()
self.highlight()
def highlight(self):
self.draw_rect("green")
def reset_path(self):
self.comparison.clear()
game = Game(600, 4)
clock = pygame.time.Clock()
run = True
while run:
clock.tick(15)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_SPACE:
game.reset_path()
game.highlight()
game.draw_rect(game.color)
game.pick()
pygame.display.update()