Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 34 additions & 37 deletions Memory_game
Original file line number Diff line number Diff line change
@@ -1,49 +1,43 @@
# 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 new_game():
global card3, po, state, exposed, card1
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)
state = 0
exposed = []
for i in range(0,16,1):
exposed.insert(i, False)

def mouseclick(pos):
global state, card3, po
state += 1
global card3, po, state, exposed, card1
if state == 2:
if card3[0] != card3[1]:
exposed[po[0]] = False
exposed[po[1]] = False
card3 = []
state = 0
po = []
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 = []

state += 1

def draw(canvas):
global card1
gap = 0
Expand All @@ -55,8 +49,11 @@ def draw(canvas):
gap += 50

frame = simplegui.create_frame("Memory", 800, 100)
frame.add_button("Reset", new_game)
label = frame.add_label("Turns = 0")

frame.set_mouseclick_handler(mouseclick)
frame.set_draw_handler(draw)

new_game()
frame.start()