View Full Version : Creating a simple memory game in c++

12-11-2013, 08:26 PM
Hello there, I've been studying programming in school for a while now and we recentley got into using the Forms Application option in Visual Studio c++. We have so for only created little programs and now it's time to make something bigger. I decided to create a memory game but the problem is that I do not really know how or what to begin with. Our teacher is not the best one either, she barely knows what we're doing right now and always have to look up things in the book or on the internet to find how to fix the problem.

To the point now, I would like to create a memory game which has 12 pictureboxes and 6 pictures in total. The 6 pictures are going to get randomly placed twice in the 12 pictureboxes so the game doesen't have a picture under the same picturebox everytime. If the player clicks on 2 picture boxes and they are the same, those pictureboxes get deleted however, if the player clicks on 2 different pictures then they turn back again. You're not supposed to see the pictures until you click on the pictureboxes btw. When the player has found all of the pictures the game ends and announces a message. There should also be a label which counts the amount of clicks you've made.

If that explanation confused you here's a link to a game which looks almost the same. http://www.gamesforthebrain.com/swedish/mastercards/

If there is any kind soul out there who would like to help me out and not just write the code out but help me out by chatting or on skype I would really appriciate that. I really want to learn this and not just copy a bunch of code.

Thanks in advance, kemkoi.

12-11-2013, 09:34 PM
I was in progress of making you an example, but it seems like VS is corrupted so I can't do that. I mainly work on C# applications, but I guess I could write a few things here on how to handle it.

Mainly, all you need is to make some kind of structure to randomize the pictures when the application has loaded, so all of the pictures will be ready to click. For the pictureboxes to know what you clicked, I guess you could create an integer, string or whatever to hold that pictureboxes number (name). Basically, you will let the program remember what you clicked. Then, you could create an if statement to see if the string or integer matches the same picture, if so remove both of the images from the game, else you can change it to the default color or image and reset your integer/string.

I could be going about this wrong, but that's what I'd do. I'd obviously have it randomizing every time program starts up so they won't be the same. I guess you could create an array with the picturebox names (or integer), whatever you prefer and randomize it in the event Form_Load. Eat picturebox has a Click event, so it is quite easy to handle such things. Like I said, I don't mess with C++ Form Applications or any C++ code outside of emulation.