Skip to content

Commit 215e99f

Browse files
authored
made changes in mouseclick
1 parent 47093f4 commit 215e99f

File tree

1 file changed

+1
-75
lines changed

1 file changed

+1
-75
lines changed

Memory_game

Lines changed: 1 addition & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,6 @@
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)# implementation of card game - Memory
32-
331
import simplegui
342
import random
353

36-
# helper function to initialize globals
374
def new_game():
385
global card3, po, state, exposed, card1
396
def create(card):
@@ -55,10 +22,7 @@ def new_game():
5522
for i in range(0,16,1):
5623
exposed.insert(i, False)
5724

58-
59-
# define event handlers
6025
def mouseclick(pos):
61-
# add game state logic here
6226
global card3, po, state, exposed, card1
6327
if state == 2:
6428
if card3[0] != card3[1]:
@@ -73,8 +37,7 @@ def mouseclick(pos):
7337
if exposed[ind] == False and state < 2:
7438
exposed[ind] = True
7539
state += 1
76-
77-
# cards are logically 50x100 pixels in size
40+
7841
def draw(canvas):
7942
global card1
8043
gap = 0
@@ -85,49 +48,12 @@ def draw(canvas):
8548
canvas.draw_text( str(card1[i]), [ 15 + gap, 65], 50, 'White')
8649
gap += 50
8750

88-
# create frame and add a button and labels
8951
frame = simplegui.create_frame("Memory", 800, 100)
9052
frame.add_button("Reset", new_game)
9153
label = frame.add_label("Turns = 0")
9254

93-
# register event handlers
9455
frame.set_mouseclick_handler(mouseclick)
9556
frame.set_draw_handler(draw)
9657

97-
# get things rolling
9858
new_game()
9959
frame.start()
100-
101-
102-
# Always remember to review the grading rubric
103-
if exposed[ind] == False and state < 2:
104-
exposed[ind] = True
105-
elif exposed[ind] == False and state == 2:
106-
exposed[ind] = True
107-
if state == 3 and card3[0] == card3[1]:
108-
card3 = []
109-
po = []
110-
state = 0
111-
elif state == 3:
112-
state = 0
113-
for i in po:
114-
exposed[i] = False
115-
card3 = []
116-
po = []
117-
118-
def draw(canvas):
119-
global card1
120-
gap = 0
121-
for i in range(0,16,1):
122-
if exposed[i] == False:
123-
canvas.draw_polygon( [ [0 + gap,0], [0 + gap,100] ,[50 + gap,100],[50 + gap,0]],1 ,"Black","Green")
124-
elif exposed[i] == True:
125-
canvas.draw_text( str(card1[i]), [ 15 + gap, 65], 50, 'White')
126-
gap += 50
127-
128-
frame = simplegui.create_frame("Memory", 800, 100)
129-
130-
frame.set_mouseclick_handler(mouseclick)
131-
frame.set_draw_handler(draw)
132-
133-
frame.start()

0 commit comments

Comments
 (0)