Tech or Treat! Write an article about your scariest tech disaster to win gadgets!Learn more

x
?
Solved

Memory Game Source Code Needed

Posted on 1999-01-20
3
Medium Priority
?
212 Views
Last Modified: 2006-11-17
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
Comment
Question by:moejoes
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 240 total points
ID: 1469776
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
 
LVL 1

Expert Comment

by:hddp666
ID: 1469777
You might have to change the paths and/or names of the .WAV files to match what is on your computer.
0
 

Author Comment

by:moejoes
ID: 1469778
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

647 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question