Você está na página 1de 2

Tips for Memory Game – A simple approach

Variables:
• Declare THREE picturebox variables – one for the first card clicked, one for the
second card clicked, one to identify the current card
Eg:
Dim picCard1 As Picturebox
• Declare TWO integer variables – one to store whether it is the first or second
click, the other to store the score.

Initialise your variables:


• Double-click on the form to create a form load (code that runs as soon as your
program starts)
• Set the integer variables to zero.

Each card’s click event – for each card:


• Double-click on the card to create a click event
• Set the image to the picturebox
picCard1.Image = My.Resources.Shrek
(Note: Shrek here is just an example of the image name)
• Set the tag of the picturebox to the image
picCard1.Tag = “Shrek”
• Set the current card picturebox to SENDER
picCurrent = Sender
(Note: Sender stores whichever picturebox / object has been clicked on)
• Call a procedure to check for matches
(Note: while you could put the actual code here, putting it in a procedure saves
you from having to copy and past the code throughout the program).

Create a “Check for matches” procedure:


• Use the structure below to create your own procedure. You can choose the name.
Private Sub pCheckMatches()
Code goes in here
End Sub
• Use an IF statement to test to see if it’s the first click.
• If it’s the first click:
 Increment the click variable
 Set the first card picturebox variable to the current clicked picturebox
variable
• Otherwise, (if it’s the second click):
 Reset the click variable to zero
 Set the second picturebox variable to the current clicked picturebox
variable
 Use an IF statement to test to see if the first card matches the second card;
you need to test their tags.
 If the tags match:
 Increment the score
 Hide or reset the two pictureboxes back to the cover image
 Otherwise, (if they don’t match):
 Reset the two pictureboxes back to the cover image

Delay the reset functionality:


• Put a timer on your form
• Set the Interval to the 1000 * the number of seconds you want to delay
• Double-click on the timer to create a tick event.
• Put the reset code (ie: setting the first card’s image to the cover and the second
card’s image to the cover) in the Tick event
• Where you previously had the reset code (ie: When the test indicate two images
don’t match), start the timer.
• At the end of the timer code (in the tick event) stop the timer.

Você também pode gostar