VB2019 VB2017 VB2015 VB2013 VB2012 VB2010 VB2008 VB6 VB Sample Codes 中文VB About Us

Memory Game



This is a typical memory game for children. The user has  to click the rectangles to uncover the hidden pictures and if two of the pictures are matching they will disappear. He or she wins the game when all the pictures are uncovered and a background image is displayed.In this program, we use an array of twelve image controls and twelve picture boxes. We insert 6 pairs of images and cover them with the picture boxes. In order to match the images, we 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 the same, then 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