Memory

28 points

 

Resources
You will need 18 distinct images for this game. I used photos of classic cars for my version of the game. Find the images you'd like to use.

Setting up the project
This project uses 3 forms and a module. Form1 can be the game board and have most of the code that runs the game. Form2 can be the screen that shows up when you start the game and asks you how you want to customize the game. Form3 can store the 18 images.

Form3
In the Design view of Form3, create 18 PictureBoxes and add your images to them. Add 1 additional PictureBox to store the 'door' that displays when the underlying image (a car, in my case) is hidden from view. There is no code in Form3.vb.

Here is what my Form3 looks like:

 

Module
The module declares 'global' or 'public' variables that will be available to all 3 forms. To add a Module to your project, in the Solution Explorer right-click on the (bold) project name, and choose Add > Module. Click here to download Module1.vb. You can copy - paste this information into the Module in your program. It is complete.

 

Form2
Form2 is the first form that pops up when the program is run. Here is what my Form2 looks like:

Add a Label that asks for the players' names. Add TextBoxes txtName1 and txtName2 to record the names.

Add a Button to start the game, and a Button to end it.

The other controls that you see above on my Form2 are optional, and are used with the extra-credit options below.

Instructions for writing the code are in Form2.vb. Click here to download Form2.vb.

 

Form1
Rename the form 'frmGame'.

Add 4 Labels near the bottom of the form: lblTurn, lblPlayer1Score, lblPlayer2Score and lblStuff.

Most of the code you'll write for this project is in Form1. Click here to download Form1.vb. Instructions for writing the code are in Form1.

 

Extra Credit

Determine whether a user who gets a match retains his turn (2 points)
Set up RadioButtons on Form2 that allow the user to determine whether or not a user who gets a match retains his turn. In Form2.vb, use the user's response to set the variable 'stillYourTurnAfterAMatch'. If the user doesn't click one of these RadioButtons, figure out whether you want to set this variable to True or False.

In Form1.vb, after a player gets a match, you'll use 'stillYourTurnAfterAMatch' to determine whose turn it is to play next.

Set how long 2 images remain exposed, when the user hasn't gotten a match (1 point)
Set up a ComboBox to let the user choose how long this pause will be. In Form2.vb, use the user's response to set the variable 'delay', which should be in milliseconds. If the user doesn't select a number from the ComboBox, decide what value to assign to 'delay'.

Customize the size of the game (3 points)
Instead of always playing a game with 12 boxes, in Form2 set up RadioButtons that allow the user to choose between a game with 12, 24 or 36 boxes. In Form2.vb, see which RadioButton is checked in order to assign the correct value to 'numBoxes'. If the user doesn't click a RadioButton, set 'numBoxes' to 12.

In Form1, 'numRows' is the number of rows of PictureBoxes, and 'numCols' is the number of columns. Determine how many rows and columns you want to have for games with 12, 24 or 36 boxes, and assign these values to 'numRows' and 'numCols'. There is also a variable 'spacing' that determines the amount of space between boxes. In a game with 12 or 24 boxes, I set 'spacing' to 150. In a game with 36 boxes, I set 'spacing' to 120.

 

Demo
You can download my version of this program here, to get an idea of what your program will do when it is complete. Right-click on the link and choose 'Save Target As' to download MemoryZip.zip. Once the file is downloaded, double-click on it to unzip it. Then double-click on 'myMemory Game.exe' to run the program.