-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMemory_game.py
94 lines (75 loc) · 1.98 KB
/
Memory_game.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#http://www.codeskulptor.org/#examples-memory_template.py
# implementation of card game - Memory
import simpleguitk
import random
# helper function to initialize globals
def new_game():
global state,cards
state = 0
cards_list=[0,1,2,3,4,5]
random.shuffle(cards_list)
cards_list1=[0,1,2,3,4,5]
random.shuffle(cards_list1)
cards = []
for i in cards_list+cards_list1:
cards.append(i)
print cards
def quit():
exit()
# define event handlers
def mouseclick(pos):
# add game state logic here
global state
if state == 0:
state = 1
elif state == 1:
state = 2
else:
state = 1
# cards are logically 50x100 pixels in size
def draw(canvas):
global cards
pos_x = 50
pos_y = 100
for card in cards:
canvas.draw_text(str(card), [pos_x,pos_y], 50, "White")
pos_x += 70
# create frame and add a button and labels
frame = simpleguitk.create_frame("Memory", 800, 100)
frame.add_button("Reset", new_game)
frame.add_button(" Exit ", quit)
label = frame.add_label("Turns = 0")
# register event handlers
frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw)
# get things rolling
new_game()
frame.start()
# Always remember to review the grading rubri
'''
# simple state example for Memory
import simplegui
# define event handlers
def new_game():
global state
state = 0
def buttonclick():
global state
if state == 0:
state = 1
elif state == 1:
state = 2
else:
state = 1
def draw(canvas):
canvas.draw_text(str(state) + " card exposed", [30, 62], 24, "White")
# create frame and add a button and labels
frame = simplegui.create_frame("Memory states", 200, 100)
frame.add_button("Restart", new_game, 200)
frame.add_button("Simulate mouse click", buttonclick, 200)
# register event handlers
frame.set_draw_handler(draw)
# get things rolling
new_game()
frame.start()
'''