forked from geekcomputers/Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Memory_game
62 lines (55 loc) · 1.41 KB
/
Memory_game
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
# Memory_game in codeskulpter
import simplegui
import random
def create(card):
while len(card) != 8:
num = random.randrange(0 ,8)
if num not in card:
card.append(num)
return card
card3 = []
card1 = []
card2 = []
po = []
card1 = create(card1)
card2 = create(card2)
card1.extend(card2)
random.shuffle(card1)
print card1
state = 0
exposed = []
for i in range(0,16,1):
exposed.insert(i, False)
def mouseclick(pos):
global state, card3, po
state += 1
ind = pos[0]//50
card3.append(card1[ind])
po.append(ind)
if exposed[ind] == False and state < 2:
exposed[ind] = True
elif exposed[ind] == False and state == 2:
exposed[ind] = True
if state == 3 and card3[0] == card3[1]:
card3 = []
po = []
state = 0
elif state == 3:
state = 0
for i in po:
exposed[i] = False
card3 = []
po = []
def draw(canvas):
global card1
gap = 0
for i in range(0,16,1):
if exposed[i] == False:
canvas.draw_polygon( [ [0 + gap,0], [0 + gap,100] ,[50 + gap,100],[50 + gap,0]],1 ,"Black","Green")
elif exposed[i] == True:
canvas.draw_text( str(card1[i]), [ 15 + gap, 65], 50, 'White')
gap += 50
frame = simplegui.create_frame("Memory", 800, 100)
frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw)
frame.start()