## Plz help with memory game :)

### Plz help with memory game :)

I have a homework assignment due tonight and i am really stuck. I have to make a memory game that where you click on two cards and if they are the same then they will remain turned over but if not then they become invisible again until you select two that are similiar.(i'm sure many of you are familiar with this game). So far i can get the numbers to pop up but i dont know what else to do. I dont know how to go about finishing this program. if you have any suggestions at all they would greatly greatly be appreciated!! thanks and have a great weekend!!
Here is the code as of yet:

#
#Date:
#Name of Program:
#Purpose:
#Precondition:
#Postconditions:

from graphics import *
import time
import random, time

def main():
win = GraphWin('Game', 800, 200)

num_list = [i%8 for i in range(16)]
random.shuffle(num_list)
exposed = [False for i in range(16)]

rect1 = Rectangle(Point(5,5), Point(45,125))
rect1.setFill("yellow")
rect1.draw(win)

rect2 = Rectangle(Point(50,5), Point(95,125))
rect2.setFill("yellow")
rect2.draw(win)

rect3 = Rectangle(Point(100,5), Point(145,125))
rect3.setFill("yellow")
rect3.draw(win)

rect4 = Rectangle(Point(150,5), Point(195,125))
rect4.setFill("yellow")
rect4.draw(win)

rect5 = Rectangle(Point(200,5), Point(245,125))
rect5.setFill("yellow")
rect5.draw(win)

rect6 = Rectangle(Point(250,5), Point(295,125))
rect6.setFill("yellow")
rect6.draw(win)

rect7 = Rectangle(Point(300,5), Point(345,125))
rect7.setFill("yellow")
rect7.draw(win)

rect8 = Rectangle(Point(350,5), Point(395,125))
rect8.setFill("yellow")
rect8.draw(win)

rect9 = Rectangle(Point(400,5), Point(445,125))
rect9.setFill("yellow")
rect9.draw(win)

rect10 = Rectangle(Point(450,5), Point(495,125))
rect10.setFill("yellow")
rect10.draw(win)

rect11 = Rectangle(Point(500,5), Point(545,125))
rect11.setFill("yellow")
rect11.draw(win)

rect12 = Rectangle(Point(550,5), Point(595,125))
rect12.setFill("yellow")
rect12.draw(win)

rect13 = Rectangle(Point(600,5), Point(645,125))
rect13.setFill("yellow")
rect13.draw(win)

rect14 = Rectangle(Point(650,5), Point(695,125))
rect14.setFill("yellow")
rect14.draw(win)

rect15 = Rectangle(Point(700,5), Point(745,125))
rect15.setFill("yellow")
rect15.draw(win)

rect16 = Rectangle(Point(750,5), Point(795,125))
rect16.setFill("yellow")
rect16.draw(win)

a=win.getMouse()
ax=a.getX()
h1=ax//50
exposed[h1] = True
center = Point(((h1*50)+25),100)
label = Text(center, num_list[h1])
label.draw(win)

b=win.getMouse()
bx=b.getX()
h2=bx//50
exposed[h2] = True
center2 = Point(((h2*50)+25),100)
label = Text(center2, num_list[h2])
label.draw(win)

#if exposed[h1] != exposed[h2]:

#user clicks, flip card
#user clicks, flip other card
#compare corresponding numbers
#if equal -> keep face up
#if not equal -> flip back over
#repeat until all cards are revealed(infinite for loop)

win.getMouse()
win.close()
main()
Last edited by Yoriz on Fri Jul 12, 2013 9:37 pm, edited 1 time in total.
Reason: Post locked due to forum homework rule.
wolffenstein

Posts: 2
Joined: Fri Jul 12, 2013 8:35 pm

### Re: Plz help with memory game :)

Hi welcome to the forum.

Please read this and then repost your code in codetags as described in the link to re-establish the indentation of your code
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!

Yoriz

Posts: 1346
Joined: Fri Feb 08, 2013 1:35 am
Location: UK

### Re: Plz help with memory game :)

Code: Select all
`##Date:#Name of Program: #Purpose:#Precondition:#Postconditions:from graphics import *import timeimport random, timedef main():    win = GraphWin('Game', 800, 200)    num_list = [i%8 for i in range(16)]    random.shuffle(num_list)    exposed = [False for i in range(16)]    rect1 = Rectangle(Point(5,5), Point(45,125))    rect1.setFill("yellow")    rect1.draw(win)        rect2 = Rectangle(Point(50,5), Point(95,125))    rect2.setFill("yellow")    rect2.draw(win)    rect3 = Rectangle(Point(100,5), Point(145,125))    rect3.setFill("yellow")    rect3.draw(win)    rect4 = Rectangle(Point(150,5), Point(195,125))    rect4.setFill("yellow")    rect4.draw(win)    rect5 = Rectangle(Point(200,5), Point(245,125))    rect5.setFill("yellow")    rect5.draw(win)    rect6 = Rectangle(Point(250,5), Point(295,125))    rect6.setFill("yellow")    rect6.draw(win)    rect7 = Rectangle(Point(300,5), Point(345,125))    rect7.setFill("yellow")    rect7.draw(win)    rect8 = Rectangle(Point(350,5), Point(395,125))    rect8.setFill("yellow")    rect8.draw(win)    rect9 = Rectangle(Point(400,5), Point(445,125))    rect9.setFill("yellow")    rect9.draw(win)    rect10 = Rectangle(Point(450,5), Point(495,125))    rect10.setFill("yellow")    rect10.draw(win)    rect11 = Rectangle(Point(500,5), Point(545,125))    rect11.setFill("yellow")    rect11.draw(win)    rect12 = Rectangle(Point(550,5), Point(595,125))    rect12.setFill("yellow")    rect12.draw(win)    rect13 = Rectangle(Point(600,5), Point(645,125))    rect13.setFill("yellow")    rect13.draw(win)    rect14 = Rectangle(Point(650,5), Point(695,125))    rect14.setFill("yellow")    rect14.draw(win)    rect15 = Rectangle(Point(700,5), Point(745,125))    rect15.setFill("yellow")    rect15.draw(win)    rect16 = Rectangle(Point(750,5), Point(795,125))    rect16.setFill("yellow")    rect16.draw(win)    a=win.getMouse()    ax=a.getX()    h1=ax//50    exposed[h1] = True    center = Point(((h1*50)+25),100)    label = Text(center, num_list[h1])    label.draw(win)    b=win.getMouse()    bx=b.getX()    h2=bx//50    exposed[h2] = True    center2 = Point(((h2*50)+25),100)    label = Text(center2, num_list[h2])    label.draw(win)    #if exposed[h1] != exposed[h2]:        #user clicks, flip card    #user clicks, flip other card    #compare corresponding numbers    #if equal -> keep face up    #if not equal -> flip back over    #repeat until all cards are revealed(infinite for loop)       win.getMouse()    win.close()main()`
wolffenstein

Posts: 2
Joined: Fri Jul 12, 2013 8:35 pm

### Re: Plz help with memory game :)

You have a lot of duplication when creating the cards, you would be better off creating them in a for loop and saving the cards in a list so you can acess them again, you also need to keep the state of each card, you could have three states - facedown, faceup & matched.

How much has the course taught you how to do it?, you should have been given suffient tools and ideas to enable you to complete the homework.
New Users, Read This
Join the #python-forum IRC channel on irc.freenode.net!

Yoriz

Posts: 1346
Joined: Fri Feb 08, 2013 1:35 am
Location: UK