Solved

TWO QUESTIONS = 100 Points

Posted on 1999-01-26
7
166 Views
Last Modified: 2010-05-03
First: I would like to be able to put a "blank" picture over each of the Match Game pictures below. (like the back of a deck of cards). When someone clicks the card, the picture behind the card would be visible until they clicked another card to try and match the picture.
Second: I would like a way to make the pictures position move at random each time a new game is started. In brevity:
"A simple match game where you click on a picture and try and match it to another picture and each new game would put the pictures into another position at random". Here is the code that I have now...
Thanks



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(12) As Boolean    ' A Yes/No array, indexed 0 to 11
   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 11
       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 Command2_Click()
End
End Sub

   Private Sub Form_Load()
   Dim i As Integer
   Dim rvalue As Double
   For i = 0 To 11
       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(9) = True Then
           Success 1, 9
           Exit Sub
       
       ElseIf PicClicked(3) = True And PicClicked(4) = True Then
           Success 3, 4
           Exit Sub
        ElseIf PicClicked(5) = True And PicClicked(8) = True Then
           Success 5, 8
           Exit Sub
        ElseIf PicClicked(6) = True And PicClicked(7) = True Then
           Success 6, 7
           Exit Sub
        ElseIf PicClicked(10) = True And PicClicked(11) = True Then
           Success 10, 11
           Exit Sub
       Else
           rvalue = PlaySound("c:\Match\tryagain.wav", 0, 0)
           For i = 0 To 11
               Image1(i).BorderStyle = 1
           Next i
           Me.Refresh
           rvalue = PlaySound("c:\Match\laser.wav", 0, 0)
           For i = 0 To 11
               Image1(i).BorderStyle = 0
           Next i
           Me.Refresh
           rvalue = PlaySound("c:\Match\laser.wav", 0, 0)
           For i = 0 To 11
               Image1(i).BorderStyle = 1
           Next i
           Me.Refresh
           rvalue = PlaySound("c:\Match\laser.wav", 0, 0)
           For i = 0 To 11
               Image1(i).BorderStyle = 0
           Next i
           Me.Refresh

       End If
       
       For i = 0 To 11
           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 11
           PicClicked(i) = False   ' reset values
       Next i
       
       ' Play the goodjob sound
       rvalue = PlaySound("c:\Match\goodjob.wav", 0, 0)

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

   End Sub
0
Comment
Question by:bendown
  • 4
  • 3
7 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 100 total points
ID: 1470801
I'll change the code and post it here.
0
 

Author Comment

by:bendown
ID: 1470802
Thank You hddp666. Looking forward to the change !!!
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1470803
Cut the old code from your form, and save it. Paste this replacement code into your form. As before, some of the .WAV files might need to be changed, or the ImgPath value that is set when the form loads.


Option Explicit
' A CHILD'S GAME THAT HAS SIX IMAGES AND A BUTTON ON A FORM.
' PUT ONE IMAGE ON A FORM, COPY IT AND THEN PASTE IT REPEATEDLY
' TO CREATE A CONTROL ARRAY.
' CHANGE THE PICTURE PROPERTY, SIZE, ETC. OF EACH ONE SEPARATELY.

' 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 ClickNum As Integer         ' Keeps track of clicks
Dim Pic(6) As String           ' Picture names
Dim Clicked(2) As Integer       ' Which 2 images are clicked
Dim ImgPath As String           ' Where the pictures are

Sub Shuffle()
Dim i, j As Integer
Dim ImgName As String
Dim upperbound As Single
Dim lowerbound As Single
Dim rvalue As Double

upperbound = 5      ' upperbound + 1 = number of images on form
lowerbound = 0

For i = 0 To 5      ' No picture names yet
    Pic(i) = ""
Next i

For i = 1 To 3
            ' Get the first image's name
    ImgName = "Img" & i & ".bmp"
   
            ' Put the image in one spot
    Do
            ' Generate a random number between 0 and 5
        j = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        If Pic(j) = "" Then
            Pic(j) = ImgPath & ImgName
            Exit Do
        End If
    Loop
            ' Put the same image in another spot
    Do
        j = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        If Pic(j) = "" Then
            Pic(j) = ImgPath & ImgName
            Exit Do
        End If
    Loop
Next i
   
For i = 0 To 5
    Image1(i).Picture = LoadPicture(ImgPath & "CardBack.bmp")
    Image1(i).BorderStyle = 0
    Image1(i).Visible = True
Next i

ClickNum = 0
Me.Refresh
rvalue = PlaySound("c:\windows\media\office97\chimes.wav", 0, 0)

End Sub

Private Sub Command1_Click()    'reset button

Shuffle     ' Call the shuffle routine
   
End Sub

Private Sub Form_Load()

ImgPath = "C:\Program Files\DevStudio\Memory Game\"

Shuffle

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
    Clicked(1) = Index
    Image1(Index).Picture = LoadPicture(Pic(Index))
    Image1(Index).BorderStyle = 1
   
ElseIf ClickNum = 2 Then
   
    If Index = Clicked(1) Then  ' Same image clicked twice
        ClickNum = 1
        Exit Sub
    End If
   
    Clicked(2) = Index
    Image1(Index).Picture = LoadPicture(Pic(Index))
    Image1(Index).BorderStyle = 1
    Me.Refresh

    If Pic(Clicked(1)) = Pic(Clicked(2)) Then
        rvalue = PlaySound("c:\windows\media\tada.wav", 0, 0)
        Success Clicked(1), Clicked(2)
    Else
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
        For i = 0 To 5
            Image1(i).Picture = LoadPicture(ImgPath & "CardBack.bmp")
            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
    ClickNum = 0    ' reset click counter
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
    ' The two images are then "turned off"
   
    Image1(img1).Visible = False
    Image1(img2).Visible = False
    Me.Refresh
   
    ' 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)
    Shuffle
   
End Sub
0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

 
LVL 1

Expert Comment

by:hddp666
ID: 1470804
In the ImgPath directory, put the following graphic files: Img1.bmp, Img2.bmp, Img3.bmp, and CardBack.bmp.
0
 

Author Comment

by:bendown
ID: 1470805
Thank You. When I get some more points, I will Point Another Question to you. It will concern the same code as per above.
Thanks
0
 
LVL 1

Expert Comment

by:hddp666
ID: 1470806
THIS CODE WILL SUPPORT 20 IMAGES ON A FORM, AND TEN DIFFERENT PICTURES (Img1.bmp - Img10.bmp). PASTE IT INTO A FORM TO REPLACE THE EARLIER CODES.


Option Explicit

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

Dim ClickNum As Integer         ' Keeps track of clicks
Dim Pic(20) As String           ' Picture names
Dim Clicked(2) As Integer       ' Which 2 images are clicked
Dim ImgPath As String           ' Where the pictures are

Sub Shuffle()
Dim i, j As Integer
Dim ImgName As String
Dim upperbound As Single
Dim lowerbound As Single
Dim rvalue As Double

upperbound = 19      ' upperbound + 1 = number of images on form
lowerbound = 0

For i = 0 To 19     ' No picture names yet
    Pic(i) = ""
Next i

For i = 1 To 10
            ' Get the first image's name
    ImgName = "Img" & i & ".bmp"
   
            ' Put the image in one spot
    Do
            ' Generate a random number between 0 and 19
        j = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        If Pic(j) = "" Then
            Pic(j) = ImgPath & ImgName
            Exit Do
        End If
    Loop
            ' Put the same image in another spot
    Do
        j = Int((upperbound - lowerbound + 1) * Rnd + lowerbound)
        If Pic(j) = "" Then
            Pic(j) = ImgPath & ImgName
            Exit Do
        End If
    Loop
Next i
   
For i = 0 To 19
    Image1(i).Picture = LoadPicture(ImgPath & "CardBack.bmp")
    Image1(i).BorderStyle = 0
    Image1(i).Visible = True
Next i

ClickNum = 0
Me.Refresh
rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)

End Sub


Private Sub Form_Load()
    ImgPath = "C:\Program Files\DevStudio\Memory Game\"
    Shuffle
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
    Clicked(1) = Index
    Image1(Index).Picture = LoadPicture(Pic(Index))
    Image1(Index).BorderStyle = 1
   
ElseIf ClickNum = 2 Then
   
    If Index = Clicked(1) Then  ' Same image clicked twice
        ClickNum = 1
        Exit Sub
    End If
   
    Clicked(2) = Index
    Image1(Index).Picture = LoadPicture(Pic(Index))
    Image1(Index).BorderStyle = 1
    Me.Refresh

    If Pic(Clicked(1)) = Pic(Clicked(2)) Then
        rvalue = PlaySound("c:\windows\media\tada.wav", 0, 0)
        Success Clicked(1), Clicked(2)
    Else
        rvalue = PlaySound("c:\windows\media\office97\laser.wav", 0, 0)
       
        For i = 0 To 19
            Image1(i).Picture = LoadPicture(ImgPath & "CardBack.bmp")
            Image1(i).BorderStyle = 0
        Next i
        Me.Refresh

    End If
    ClickNum = 0    ' reset click counter
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
    ' The two images are then "turned off"
   
    Image1(img1).Visible = False
    Image1(img2).Visible = False
    Me.Refresh
   
    ' 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 19
        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)
    Shuffle
   
End Sub

Private Sub Command1_Click()     ' Reset button
Shuffle
End Sub

0
 

Author Comment

by:bendown
ID: 1470807
You are too much hddp666 ! I really appreciate the extra code above. I have a friend who works with me and he will be coming to this area of cyber space real soon. He will be Pointing a Question to you if its O.K. He likes the Match Code and will be asking you How To Change The Pictures so that there will be Sets of Pictures instead of just the 20. Like if you wanted Three Sets Of Pictures. It will be worth 200 points.
Thank You Again...
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone 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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
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…

839 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