Solved

"POINTS TO hddp666 FOR 200 Points"

Posted on 1999-01-27
5
173 Views
Last Modified: 2010-05-03
Hello hddp666 person: My associate at work showed me your code for the match game. I would like to have an example of how one could make "sets" of pictures for this situation. This way the child would not get bored with the same pictures even though they are generated randomly. I hope this is something that could be done by you. Ben says you are "The Man or Woman" so Thanks for trying if you do !
0
Comment
Question by:mavis012799
  • 3
  • 2
5 Comments
 
LVL 1

Accepted Solution

by:
hddp666 earned 200 total points
Comment Utility
Put a pull-down menu on the form CHANGE GAME >> GAME ONE, or GAME TWO, or GAME THREE. The menu editor in VB is under TOOLS, and the form must be visible and selected to activate the MENU EDITOR. The names of the menu commands are mnuSelectOne, mnuSelectTwo and mnuSelectThree. Their subs are at the bottom of the code below.





' PUT THIS CODE IN A FORM WITH 20 IMAGES. PUT THREE SETS OF
' PICTURES, 10 EACH, IN THE IMGPATH DIRECTORY.

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
Dim ImgSet As Integer           ' Which set of pictures to use

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" & ImgSet & "_" & 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\"
    ImgSet = 1
    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 mnuReset_Click()
Shuffle
End Sub

Private Sub mnuSelectOne_Click()
ImgSet = 1
Shuffle
End Sub

Private Sub mnuSelectTwo_Click()
ImgSet = 2
Shuffle
End Sub

Private Sub mnuSelectThree_Click()
ImgSet = 3
Shuffle
End Sub
0
 
LVL 1

Expert Comment

by:hddp666
Comment Utility
The three sets of images need to be named

Img1_1.bmp, Img1_2.bmp, Img1_3.bmp . . . Img1_1.bmp

Img2_1.bmp, Img2_2.bmp, Img2_3.bmp . . . Img2_1.bmp

Img3_1.bmp, Img3_2.bmp, Img3_3.bmp . . . Img3_1.bmp

0
 

Author Comment

by:mavis012799
Comment Utility
Thank You Very Much. I Did It another way, but like your way much better !!!
0
 
LVL 1

Expert Comment

by:hddp666
Comment Utility
1. Herr Doktor Doktor Professor is not a person, but a THING.
2. There are more efficient ways to handle the images, and their names. The code provided was done onnafly (an Italian term, I believe).
3. If you are planning to use the code as part of a commercial product, you should hide the images in a .DLL so that the customer can't access them directly. This is to perpetuate the myth of Merlin 8-)

0
 

Author Comment

by:mavis012799
Comment Utility
  I'm still laughing. You seem to have a very sharp sense of humor! I am hardly ready for a commercial venture. I am interested in how to place images in a .Dll however, I would not know where to begin. My next question to you was going to be in reference to how you could merge the images into the program itself. You may have answered this question as per .Dll above.
   How many points do I need to aquire the .Dll information ? Is it something that can be done in Visual Basic ? Anyway, Thank You For The Code. You went out of your way to teach, I admire this !
Bye
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…

728 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

11 Experts available now in Live!

Get 1:1 Help Now