#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    1
    Rep Power
    0

    Help with Memory game please!!!


    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()
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2009
    Posts
    474
    Rep Power
    33
    Quoted with code tags intact. You would call the function repeatedly until the two choices are the same as below. I will leave it to you to return the two choices. Note that the numbers change each time you run the function, which you want to fix, i.e. num_list is generated and shuffled on each pass. Also the name of the function has been changed to "choose_two". Main() is not descriptive and is considered unprofessional/newbie because teachers tell their beginners to name all functions main() so as not to confuse them in the beginning with different function names.
    Code:
    #Date:
    #Name of Program: 
    #Purpose:
    #Precondition:
    #Postconditions:
    
    from graphics import *
    import time
    import random, time
    
    def choose_two():
        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()
    
    choice1 = ""
    choice1 = 0
    while choice1 != choice2:
        choice1, choice2 = choose_two()
    Last edited by dwblas; July 13th, 2013 at 01:21 PM.

IMN logo majestic logo threadwatch logo seochat tools logo