PDA

View Full Version : Memory game problem


keybasher
05-05-2013, 07:37 PM
I'm building a memory game for a class I'm in, in which the user flips over two cards to see if they match. If they do match, they stay face up. However, I can't seem to figure out how to make them flip back over automatically if they don't. Is there any way this can be done?

Here's what I have so far:

x2495iiii
05-05-2013, 10:23 PM
You'll need to use global variables if you want an event to check the value of the cards.

keybasher
05-06-2013, 01:31 AM
How do I create a global variable?

x2495iiii
05-06-2013, 03:57 AM
-click the "world" item in the item list on the left of the screen to select it

-click the properties tab in the center-left of the screen

-click the "create variable" button at the top of the properties menu

Global variables can be accessed by any method or event, so they're best to use for beginning programs.

keybasher
05-06-2013, 02:20 PM
I see. I've created some global variables now, but how does this answer my original question (from the first post)?

x2495iiii
05-06-2013, 10:21 PM
You need to replace all the references to the old memoryCard1 and memoryCard2 variables with references to the new global variables you made.

With that, you can add some logic to the end of the event (near the gong sound effect) that would turn the cards around.

The only problem is that, as it is, you'd need another huge nested if/else statement to turn the cards back around.

I'm working on an example that uses parameters and variables to eliminate the use of nested if/else statements.

x2495iiii
05-06-2013, 11:14 PM
Example's done. The comments explain most of the important stuff.

keybasher
05-07-2013, 01:38 AM
Thank you so much. I learned a lot from that. I would never have thought of that at all. You clearly have more experience with Alice than I do and I hope one day I can program as well as you.

x2495iiii
05-07-2013, 02:41 PM
Glad to help.

If you have any questions about the concepts used, let me know.

EDIT: Forgot to mention, you'll still need to add something that tells the user when they've won.