VB2022 VB2019 VB6 VB Sample Code About Us

Memory Game



This is a memory game for children. The user has  to click the rectangles to uncover the hidden pictures and if two of the pictures match they will disappear. He or she wins the game when all the pictures are uncovered and a background image is displayed.In this program, you need to create an array of twelve image controls and twelve picture boxes. Next,insert 6 pairs of images and cover them with the picture boxes. In order to match the images, you can use tags to identify them, same images are given the same tags.. The tags are being set at the images' properties windows. When two picture boxes covering the images are being clicked, the program check for the tags of the images and if found that they are identical, they become invisible.

The Interface

The Video Demo




The Code

Sub check()
'check whether the pictures are the same or not
For i = 0 To 11
If Picture1(i).Visible = False Then
For j = 0 To 11
If Picture1(j).Visible = False Then
If i <> j And Image1(i).Tag = Image1(j).Tag Then
Image1(j).Visible = False
Image1(i).Visible = False
Picture1(j).Visible = False
Picture1(i).Visible = False
End If
If i <> j And Image1(i).Tag <> Image1(j).Tag And Image1(i).Visible = True And Image1(j).Visible = True Then
Picture1(j).Visible = True
Picture1(i).Visible = True
End If
End If

Next j

End If

Next i
 

End Sub


Private Sub picture1_Click(Index As Integer)
Picture1(Index).Visible = False
Timer1.Enabled = True
End Sub

Private Sub Timer1_Timer()
check
End Sub

 



Copyright©2008 Dr.Liew Voon Kiong. All rights reserved |Contact|Privacy Policy