Solved

Memory Game Source Code Needed

Posted on 1999-01-20
3
199 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
  • 2
3 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 60 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now