Skip to content

Commit 6f54156

Browse files
authored
Create Memory_game
1 parent 4249d28 commit 6f54156

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed

Memory_game

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Memory_game in codeskulpter
2+
3+
import simplegui
4+
import random
5+
6+
def create(card):
7+
while len(card) != 8:
8+
num = random.randrange(0 ,8)
9+
if num not in card:
10+
card.append(num)
11+
return card
12+
card3 = []
13+
card1 = []
14+
card2 = []
15+
po = []
16+
card1 = create(card1)
17+
card2 = create(card2)
18+
card1.extend(card2)
19+
random.shuffle(card1)
20+
print card1
21+
state = 0
22+
exposed = []
23+
for i in range(0,16,1):
24+
exposed.insert(i, False)
25+
26+
def mouseclick(pos):
27+
global state, card3, po
28+
state += 1
29+
ind = pos[0]//50
30+
card3.append(card1[ind])
31+
po.append(ind)
32+
if exposed[ind] == False and state < 2:
33+
exposed[ind] = True
34+
elif exposed[ind] == False and state == 2:
35+
exposed[ind] = True
36+
if state == 3 and card3[0] == card3[1]:
37+
card3 = []
38+
po = []
39+
state = 0
40+
elif state == 3:
41+
state = 0
42+
for i in po:
43+
exposed[i] = False
44+
card3 = []
45+
po = []
46+
47+
def draw(canvas):
48+
global card1
49+
gap = 0
50+
for i in range(0,16,1):
51+
if exposed[i] == False:
52+
canvas.draw_polygon( [ [0 + gap,0], [0 + gap,100] ,[50 + gap,100],[50 + gap,0]],1 ,"Black","Green")
53+
elif exposed[i] == True:
54+
canvas.draw_text( str(card1[i]), [ 15 + gap, 65], 50, 'White')
55+
gap += 50
56+
57+
frame = simplegui.create_frame("Memory", 800, 100)
58+
59+
frame.set_mouseclick_handler(mouseclick)
60+
frame.set_draw_handler(draw)
61+
62+
frame.start()

0 commit comments

Comments
 (0)