Random placement in Memory Game - C++

Started by
7 comments, last by Caxen 19 years, 10 months ago
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...
Advertisement
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.
I''m not so good at english and not so good at programming either... So what you saying is that I give each IMAGE and BUTTON a number? How?
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.
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!
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?
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.
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...
For the graphics, use the "cards.dll" that comes with Windows. Do a google search and you''ll find lots of specific,detailed coding examples on how to use it.

This topic is closed to new replies.

Advertisement