[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 215
  • Last Modified:

Memory Game Source Code Needed

I want to make a small program in visual basic 5.0 This will be my first program ever. What I want to do is have my daughter click on pictures. If she clicks two pictures that match they will disappear. I would like a working example that I could run and study how it works. I'm not much for the technical areas right now, but I think that I would be able to figure the example out by observing how it runs. All I have is 66 Points. You are welcome to them for an example. Thank You Very Much !
0
moejoes
Asked:
moejoes
  • 2
1 Solution
 
hddp666Commented:
Put an image (not a picture box) control on a form, copy it, and then paste it 5 times to create a control array: Image(i), i = 0 to 5. Change the Picture property of each image separately, such that Image(0) = Image(2), Image(1) = Image(5) and Image(3) = Image(4). You can also resize the images separately. Put a button on the form, and make RESET its caption. Paste the following code into the form's declarations section.


Option Explicit
' A CHILD'S GAME THAT HAS SIX IMAGES AND A RESET BUTTON.
' CLICKING TWO IDENTICAL IMAGES MAKES THEM DISAPPEAR.

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Dim PicClicked(6) As Boolean    ' A Yes/No array, indexed 0 to 5
Dim ClickNum As Integer         ' Keeps track of clicks

Private Sub Command1_Click()    'reset button
Dim i As Integer
Dim rvalue As Double

For i = 0 To 5
    PicClicked(i) = False
    Image1(i).Visible = True
    Image1(i).BorderStyle = 0
Next i
ClickNum = 0
Me.Refresh
rvalue = PlaySound("c:\windows\media\office97\chimes.wav", 0, 0)
   
End Sub

Private Sub Form_Load()
Dim i As Integer
Dim rvalue As Double
For i = 0 To 5
    PicClicked(i) = False
Next i
rvalue = PlaySound("c:\windows\media\office97\chimes.wav", 0, 0)

End Sub

Private Sub Image1_Click(Index As Integer)
Dim i As Integer
Dim rvalue As Double
' When an image is clicked, this subroutine is called

ClickNum = ClickNum + 1 ' increment the click counter

If ClickNum = 1 Then    ' No clicks before the present one
    PicClicked(Index) = True    ' Image(Index) has been clicked
    Image1(Index).BorderStyle = 1
    ClickNum = 1    ' increment click counter
   
ElseIf ClickNum = 2 Then    ' The present click is the second one
    PicClicked(Index) = True ' A second image has been clicked
    Image1(Index).BorderStyle = 1
    Me.Refresh
    ClickNum = 0    ' reset click counter

    ' image(0) is the same as image (2), etc.
    ' see if they have both been clicked
    If PicClicked(0) = True And PicClicked(2) = True Then
        Success 0, 2
        Exit Sub
   
    ElseIf PicClicked(1) = True And PicClicked(5) = True Then
        Success 1, 5
        Exit Sub
   
    ElseIf PicClicked(3) = True And PicClicked(4) = True Then
        Success 3, 4
        Exit Sub
    Else
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
        For i = 0 To 5
            Image1(i).BorderStyle = 1
        Next i
        Me.Refresh
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
        For i = 0 To 5
            Image1(i).BorderStyle = 0
        Next i
        Me.Refresh
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
        For i = 0 To 5
            Image1(i).BorderStyle = 1
        Next i
        Me.Refresh
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
        For i = 0 To 5
            Image1(i).BorderStyle = 0
        Next i
        Me.Refresh

    End If
   
    For i = 0 To 5
        PicClicked(i) = False   ' reset the game after two clicks
        Image1(i).BorderStyle = 0
    Next i
End If

End Sub

Private Sub Success(img1 As Integer, img2 As Integer)
Dim i As Integer
Dim rvalue As Long
    ' Values for img1 and img2 are passed to the subroutine
    ' when it is called, e.g. Success 0, 2 calls this sub, and
    ' sets img1 to 0 and img2 to 2.
    ' The two images are then "turned off"
   
    Image1(img1).Visible = False
    Image1(img2).Visible = False
    Me.Refresh
    For i = 0 To 5
        PicClicked(i) = False   ' reset values
    Next i
   
    ' Play the whoosh sound
    rvalue = PlaySound("c:\windows\media\office97\whoosh.wav", 0, 0)

    ' If any images left, go back and continue play
    For i = 0 To 5
        If Image1(i).Visible = True Then Exit Sub
    Next i
           
    ' Otherwise, play the applause sound and reset the game
    rvalue = PlaySound("c:\windows\media\office97\applause.wav", 0, 0)
    For i = 0 To 5
        PicClicked(i) = False
        Image1(i).Visible = True
        Image1(i).BorderStyle = 0
    Next i
    ClickNum = 0
    Me.Refresh

End Sub

0
 
hddp666Commented:
You might have to change the paths and/or names of the .WAV files to match what is on your computer.
0
 
moejoesAuthor Commented:
Thanks hddp666. You did a very good job as far as I'm concerned. It works for me ! I will single you out from now on !!!
Thanks Again.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now