Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Memory Game

New Here ,
Apr 26, 2006 Apr 26, 2006
Hello,

I am trying to do a simple Memory Game in Flash 8. The examples I have found are much more complicated than what this game needs to be so I was trying to create my own from scratch. There is no random needed just 8 cards on the screen so 4 matches total. When they get a match the pair visibility turns off and when they are all matched it goes to a finished screen. I have all of that working great but I am having 2 problems.

Problem 1:
When the user selects the wrong card that isn’t a match I need it to flip back over and set the variables back to 0. I can’t figure out how to do this without writing a conditional statement for each possible order the user could select them in.

Problem 2:
When they select the second card and it is a match the match disappears which is good but it goes so quickly that the user doesn’t even have time to see that they got the match. I would like it to delay so it doesn’t disappear so fast.

I would really appreciate any help here.
Thanks so much!!!


Movie Clips On Stage
card1a
card1b
card2a
card2b
card3a
card3b
card4a
card4b


card1a matches with card1b
card2a matches with card2b
card3a matches with card3b
card4a matches with card4b

Actions on Root Level
On Frame 1:
_global.match1=0
_global.match2=0
_global.match3=0
_global.match4=0

On Frame 5:
card1a.onRelease = function() {
_root.card1a.play();
};

card1b.onRelease = function() {
_root.card1b.play();
};

card2a.onRelease = function() {
_root.card2a.play();
};

card2b.onRelease = function() {
_root.card2b.play();
};

card3a.onRelease = function() {
_root.card3a.play();
};

card3b.onRelease = function() {
_root.card3b.play();
};

card4a.onRelease = function() {
_root.card4a.play();
};

card4b.onRelease = function() {
_root.card4b.play();
};

On Frame 6:
if ((_global.match1 == 2) && (_global.match2 == 2) && (_global.match3 == 2) && (_global.match4 == 2)) {
_root.gotoAndPlay(10);
} else {
_root.gotoAndPlay(_currentframe-1);
}


if (_global.match1 == 2) {
card1a._visible = false;
card1b._visible = false;
}

if (_global.match2 == 2) {
card2a._visible = false;
card2b._visible = false;
}

if (_global.match3 == 2) {
card3a._visible = false;
card3b._visible = false;
}

if (_global.match4 == 2) {
card4a._visible = false;
card4b._visible = false;
}


Actions within Movie Clips
card1a
Frame 1:
stop();

Frame 5:
_global.match1 = (_global.match1) + 1
trace(_global.match1);
stop();

Frame 10:
_global.match1 = (_global.match1) - 1
trace(_global.match1);

card1b
Frame 1:
stop();

Frame 5:
_global.match1 = (_global.match1) + 1
trace(_global.match1);
stop();

Frame 10:
_global.match1 = (_global.match1) - 1
trace(_global.match1);


card2a
Frame 1:
stop();

Frame 5:
_global.match2 = (_global.match2) + 1
trace(_global.match2);
stop();

Frame 10:
_global.match2 = (_global.match2) - 1
trace(_global.match2);


card2b
Frame 1:
stop();

Frame 5:
_global.match2 = (_global.match2) + 1
trace(_global.match2);
stop();

Frame 10:
_global.match1 = (_global.match2) - 1
trace(_global.match2);

card3a
Frame 1:
stop();

Frame 5:
_global.match3 = (_global.match3) + 1
trace(_global.match3);
stop();

Frame 10:
_global.match3 = (_global.match3) - 1
trace(_global.match3);

card3b
Frame 1:
stop();

Frame 5:
_global.match3 = (_global.match3) + 1
trace(_global.match3);
stop();

Frame 10:
_global.match3 = (_global.match3) - 1
trace(_global.match3);

card4a
Frame 1:
stop();

Frame 5:
_global.match4 = (_global.match4) + 1
trace(_global.match4);
stop();

Frame 10:
_global.match4 = (_global.match4) - 1
trace(_global.match4);

card4a
Frame 1:
stop();

Frame 5:
_global.match4 = (_global.match4) + 1
trace(_global.match4);
stop();

Frame 10:
_global.match4 = (_global.match4) - 1
trace(_global.match4);

TOPICS
ActionScript
370
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 26, 2006 Apr 26, 2006
NS5,

> I am trying to do a simple Memory Game in Flash 8.

99% of games are not simple, even if they're supposed to be.

> The examples I have found are much more complicated
> than what this game needs to be so I was trying to create
> my own from scratch.

I applaud that! You will learn and appreciate to much more if you build
your own. Just don't think it'll necessarily be easy.

> Problem 1:
> When the user selects the wrong card that isn?t a match
> I need it to flip back over and set the variables back to 0.
> I can?t figure out how to do this without writing a
> conditional statement for each possible order the user
> could select them in.

Can you explain these variables? The ones you have to set back to zero,
I mean. Off the top of my head, I wouldn't use variables so much as
properties of my movie clip "cards." Give each card an instance name, then
add a property ... something like this:

cardA.face = "apple";
cardB.face = "apple";
cardC.face = "pear";
cardD.face = "pear";
cardE.face = "orange";
cardF.face = "orange";
cardG.face = "peach";
cardH.face = "peach";

And then when it's time to compare them, simply check this property of
each movie clip ...

if (clipReference1.face == clipReference2.face) { ... }

... where clipReference1 and clipReference2 refer to whatever movie clips
were selected. Does that make sense?

Show us how you're currently comparing two cards.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Apr 26, 2006 Apr 26, 2006
Hi,

Thank you for getting back to me. I dont know how to explain my functionality better than what I did so I have uploaded the FLA file to my personal site so you can download it. It is the link below

http://nmsproductions.com/Downloads/MemoryGame.zip

Basically I am using the variable _global.match1 and setting it to zero. When the user clicks on one card it sets the variable for that match to its current number plus 1 and if they click it again to turn the card back over it subtracks 1. Then if that variable is equal to 2 the match is made and it is removed from the stage.

Thanks for the help!!!
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Apr 27, 2006 Apr 27, 2006
LATEST
NS5,

> Thank you for getting back to me.

Sure.

> I dont know how to explain my functionality better than
> what I did so I have uploaded the FLA file to my
> personal site so you can download it. It is the link below

As a rule, I prefer not to download files -- mainly because it forces
the developer to really think through what he/she has done, in order to
formulate a good question -- but I took a look in this case. Honestly,
I'm a bit confused by your approach.

Here are a few quick observations.

You don't need those _global variables. It's fine to have them, but
they just aren't necessary, here. If you want variables that are available
to any ActionScript in the main timeline (where all your code is), then a
normal declaration will work just fine.

e.g.
var myString:String = "some string:
var myNumber:Number = 5;

You can use the following in your MovieClip.onRelease handlers ...

card1a.onRelease = function() {
this.play();
};

... which is functionally identical to what you have, but easier to read, I
think.

Rather than keep so many variables (four of them), all you really need
is a single variable that keeps track of what other card, if any, was the
last one flipped. At the beginning, of course, no cards will have been
flipped, so you might do this ...

var lastCardFlipped:MovieClip = null;

Then the MovieClip.onRelease handler for each card should do the
following: a) cause the card to play through its animation; b) check if
another card has been flipped; c) if so, check if the current card's custom
property (discussed last time) matches the custom property of the last card
flipped; d) if not (meaning, if no other card has been flipped), note itself
as the "last card flipped" for next time.

First, you'll have to give each card an identity via a custom property.

cardA.id = "card 1";
cardB.id = "card 1";
cardC.id = "card 2";
cardD.id = "card 2";
cardE.id = "card 3";
cardF.id = "card 3";
// etc.

Then your event handler might be ...

carA.onRelease = function() {
this.play();
if (lastCardFlipped == null) {
lastCardFlipped = this;
} else {
if (this.id == lastCardFlipped.id) {
// this is a match
} else {
// this is not a match, so set lastCardFlipped
// back to null and start again
lastCardFlipped = null;
}
}
}

NOTE: These are off-the-cuff suggestions of mine; I'm not trying to
dictate how your game should work. Obviously, you may want to add
features, move/change features, etc. I'm just hoping this at least gives
you something different to chew on.


David
stiller (at) quip (dot) net
Dev essays: http://www.quip.net/blog/
"Luck is the residue of good design."


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines