Archived

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

Caxen

Random placement in Memory Game - C++

Recommended Posts

I have a problem making random placement of cards in my memory game made i visual studio .net in a Windows application. The cards positions are BUTTONS and the IMAGES on the cards are BACKGROUND IMAGES on the buttons. How do I randomize the IMAGES on the BUTTONS? I would appriciate the help...

Share this post


Link to post
Share on other sites
You can order the images numerically, such that the card #s comprise a portion of the image name -- just randomize within the bounds and strcat.

At least that''s one way to do it in c... The idea should be largely the same though.

Share this post


Link to post
Share on other sites
This can be done many ways, I merely described one possibility.

Use an array to hold the positions of the cards. Depending on your layout you may be inclined to use a multidimensional array, though there are advantages to using single dimensional arrays (which is largely beyond the scope of this thread).

If you have an cards and an equall number of spots. just randomize the positions of the cards in the array. If you have fewer spots than cards, you may need additional arrays. This can be done in several ways.

Supposing that you have 10 cards and 3 spots...

[0,1,2,3,4,5,6,7,8,9]

randomize

[3,6,1,0,4,5,9,2,8,7]

If necessary, create an additional array to map the cards to the spots.

As to your question about the spots themselves, your layout is probably condusive to using array indexes to represent the various postions/spots. No need to make more work for yourself than necessary.

Share this post


Link to post
Share on other sites
I''m giving up soon...
I cant make this stupid "memory game".
Random placement of a limited collection of images that can be used only twice is IMPOSSIBLE!!!

Help me!

Share this post


Link to post
Share on other sites
I think I understand and I appriciate your help greatly...
But think about that it is a memory game, same image will be used twice... How can I limit this?

Share this post


Link to post
Share on other sites
One way would be to include each number in the array twice. Thus:

[0,0,1,1,2,2,3,3,4,4,5,5,6,6]

Given that you''re creating a "memory" game, all you''d need to do is randomize:

[3,5,1,4,0,6,2,4,1,5,3,6,2,0]

Shouldn''t be anything beyond that, save the graphics.

Share this post


Link to post
Share on other sites
Now I understand... Thank you.
Skip the graphics is nothing I can do... =/
It''s a school project, and the dead line is coming up fast.
It''s supposed to be a game made in "windows interface application" =/

Just hit me, how do I compare filenames? (IMAGE01.jpg) ??? Ops...

Share this post


Link to post
Share on other sites