Creating a Memory Match Game

7

Index

Stats

24,183 visits, 60,447 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 29 Mar, 2012. Last updated 19 Feb, 2019

Part 4: A Turn of Play

Video Part 4a

Subscribe to Construct videos now

(If you don't see the video, follow this link to view Part 4a.)

Video Part 4b

Subscribe to Construct videos now

(If you don't see the video, follow this link to view Part 4b.)

Cheat Sheet for Part 4a

If you don't trust your ability to type in the more complicated expressions, you can copy them from here:

Match test expression 1:

    gFirstCardFrame-(gFirstCardFrame%2)

Match test expression 2:

    gSecondCardFrame-(gSecondCardFrame%2)

How does the test for matches work?

If you'd like a little more information on how the test for matches used in this game works, read on.

Consider the cards in our game. Remember I told you that the matching cards had to be side by side in the cardface animation or it wouldn't work.

Card face frames:

The images for frames 0 and 1 match, frames 2 and 3 match, frames 4 and 5 match, etc. But the frame numbers are not equal.

However if we subtract 0 from the first card frame number of a pair and 1 from the second card frame number of a pair, then they are both equal to the first card frame number.

This is true regardless of the order in which we pick the cards.

So how do we do that?

Notice that the frame number of the first card of a match is even, and the frame number of the second card of a match is odd.

Recall that the modulus operator (%) returns the remainder of a division operation. If we divide an integer >= 0 by 2, the remainder is always 0 if the number is 0 or even, and 1 if the number is odd.

So if the cards match, then the condition:

gFirstCardFrame-(gFirstCardFrame%2)=gSecondCardFrame-(gSecondCardFrame%2)

is true. If they don't match, it is false.

  • 0 Comments

Want to leave a comment? Login or Register an account!