Shop OBEX P1 Docs P2 Docs Learn Events
Memory Game — Parallax Forums

Memory Game

watty09watty09 Posts: 2
edited 2011-05-17 19:56 in BASIC Stamp
Can somebody give me a hand with solving this memory game. The idea of the game is like simon. User duplicates the sequence provided by the BS2 using pushbutton inputs. My code as posted, works for the first two LED's, Red and Green. I have no idea how to configure the other 2 led's in. I Can play the game using the red and green led's but as soon as the random generator, generates an led that is orange or yellow, i have to reset because i can't configure them in.

All help is appreciated!!!


Thanks

Ryan

Comments

  • vaclav_salvaclav_sal Posts: 451
    edited 2011-05-17 14:34
    In your Check_Response: subroutine you evaluate only green and red colors.
    Also add some DEBUG so you can see the program flow. You may find out that RED is "generated" more often that others due to the if ... than evaluation of single bits. Take a look at SELECT and evaluating ranges of numbers instead.
    I think you could replace some of the repetitious code with subroutines.
    A minor suggestion - I did not see how "deep" your Simon sequence goes, but you may be able to "replace" the eeprom writes with just variable array.
    Just a thought.
    Your coding style is good, plenty of comments makes it easier to follow.
    Vaclav
  • watty09watty09 Posts: 2
    edited 2011-05-17 14:43
    The reason i programmed it to only check for red and green is because in the random sequence part, if the random color is red it writes to; eepromAddress, 1 and eepromAddress, 0 if its green. Where would i write orange and yellow? i can't write it to 1 or 0 because it would overwrite the current memory.. this is where i get confused lol.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-05-17 17:25
    First, I didn't look at you code.... second, if it helps, I would make an array of nibbles. You have four colors, so a nibble will work well.

    When you initialize the program, decide how many sequences "WIN" will be.... say 12 sequences and you've won.... so you dedicate twelve nibbles of data space to keep track of sequences. You'll need a pointer, to keep track of which sequence you're on and that's it!


    so your data table will look something like this:
    Sequence 0 / Data table position 0 = GREEN
    Sequence 1 / Data table position 1 = RED
    Sequence 2 / Data table position 2 = YELLOW
    Sequence 3 / Data table position 3 = YELLOW
    Sequence 4 / Data table position 4 = BLUE
    Sequence 5 / Data table position 5 = GREEN
    Sequence 6 / Data table position 6 = RED
    ......
    If you dissect the code available in my signature, I used this exact thing in my project for Parallax. The code is well (I think) commented, so it should be easy to pick apart :)
  • vaclav_salvaclav_sal Posts: 451
    edited 2011-05-17 19:56
    You write 0,1,3.4 to eepromAddress corresponding to red,green, orange and yellow in Begin_Game:
    Actually the green is not saved - you write 0 to eepromAddress.

    In your Check_Response: subroutine you looking only for green and red colors in savedColor.
    Orange and yellow are never checked for.

    This is the logic

    IF savedColor <> Green THEN ' If the values of savedColor
    PbGreen = 0 ' and Green are different,
    PAUSE 100 ' keep looping
    ELSEIF savedColor <> Red THEN ' If the values of savedColor
    youLose = 1 ' and Red are different, the

    the savedColor here is either orange or yellow
    RETURN

    and you never get here !
    this code does not get executed from here!
    DEBUG "Here",cr
    STOP

    ' player lost, return to main
    ELSEIF savedColor = Red THEN ' If the values of savedColor
    PbRed = 0 ' and Red are equal, keep
    PAUSE 100 ' looping
    ELSEIF savedColor = Green THEN ' If the values of savedColor
    youLose = 1 ' and Red are equal, the
    RETURN ' player lost, return to main
    ENDIF

    .
Sign In or Register to comment.