-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemory.py
74 lines (64 loc) · 2.4 KB
/
Memory.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
import simplegui
import random
def new_game():
global cards, exposed, state, counter
counter = 0
label.set_text('Turn = ' + str(counter))
cards = ((range(0,8))*2)
exposed = [False, False, False, False, False, False, False, False,
False, False, False, False, False, False, False, False]
trues = []
random.shuffle(cards)
state = 0
def mouseclick(pos):
global state, fcard, scard, pos1, pos2, pos3, counter
position = (list(pos)[0]) / 50
if state == 0:
for index in range(len(exposed)):
pos1 = position
if pos1 == index:
counter += 1
label.set_text('Turn = ' + str(counter))
pos1 = position
exposed[pos1] = True
fcard = cards[pos1]
state = 1
elif state == 1:
for index in range(len(exposed)):
pos2 = position
if pos2 == index and exposed[pos2] != True:
pos2 = position
exposed[pos2] = True
scard = cards[pos2]
state = 2
else:
if fcard == scard and exposed[pos1] != True and exposed[pos2] != True:
exposed[pos1] = True #exposed[pos1]
exposed[pos2] = True #exposed[pos2]
if fcard != scard:
exposed[pos1] = False
exposed[pos2] = False
for index in range(len(exposed)):
pos1 = position
if pos1 == index and exposed[pos1] != True:
counter += 1
label.set_text('Turn = ' + str(counter))
pos1 = position
exposed[pos1] = True
fcard = cards[pos1]
state = 1
def draw(canvas):
for card_index in range(len(cards)):
card_pos = 50 * card_index
text_pos = 50 * card_index + 15
if exposed[card_index] == True:
canvas.draw_text(str(cards[card_index]), (text_pos, 50), 30, 'White')
if exposed[card_index] == False:
canvas.draw_line((card_pos, 50), (card_pos + 49, 50), 100, 'Green')
frame = simplegui.create_frame("Memory", 800, 100)
frame.add_button("Reset", new_game)
label = frame.add_label('Turn = 0')
frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw)
new_game()
frame.start()