100% found this document useful (1 vote)
847 views

Tips For Memory Game

This document provides tips for creating a memory game using variables and procedures in Visual Basic. It includes: 1) Declaring variables such as picturebox variables to store card images, integer variables to track clicks and score. 2) Initializing variables in the form load event, such as setting integer variables to zero. 3) Creating a "Check for Matches" procedure that uses IF statements to check if it's the first or second card click, compare card tags, and increment the score if they match or reset cards if not. 4) Adding a timer to delay resetting the cards if they don't match, starting the timer when cards don't match and stopping it in the timer tick

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
847 views

Tips For Memory Game

This document provides tips for creating a memory game using variables and procedures in Visual Basic. It includes: 1) Declaring variables such as picturebox variables to store card images, integer variables to track clicks and score. 2) Initializing variables in the form load event, such as setting integer variables to zero. 3) Creating a "Check for Matches" procedure that uses IF statements to check if it's the first or second card click, compare card tags, and increment the score if they match or reset cards if not. 4) Adding a timer to delay resetting the cards if they don't match, starting the timer when cards don't match and stopping it in the timer tick

Uploaded by

sedmondsbrown
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 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.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy