This topic is now archived and is closed to further replies.


Memory game - I really need help!

Recommended Posts

Hello, in a project in school I am supposed to make a memory game of matching pairs in visual studio .net using C++ and a Windows interface application. The cards will be buttons that change image when you click on them, but I need help with a few things... * Random placement of images on the buttons. * Lock two cards if they are a matching pair. * Time limit. Please, I really need help!

Share this post

Link to post
Share on other sites
Random placement should be pretty easy.

I imagine you'll be storing your cards in a 2D array, assuming the first index are the rows (top to bottom) and the second index are the columns (left to right).

Place all your cards in a uniform pattern in this 2D array.

So 0,0 put your Ace and 0,1 put your other Ace. Now in 0,2 put your King and your 0,3 put your other King. Do this for all the cards (no idea how many you'll have).

To randomly place them, loop through your cards 500 times. Pick one card, and swap it with another card.

Psuedo Code:
Loop 1 to 500
Randomly Pick X1, Y1
Randomly Pick X2, Y2
Store Tempoary Card Of X2, Y2
Set X2, Y2 as the card from X1, X2
Assign Tempoary Card to X1, X2
End Loop

That should help you get started.

[edited by - GroZZleR on May 25, 2004 1:41:14 AM]

Share this post

Link to post
Share on other sites