Ok so i am going a whack a mole game.

What method i did was that i used a picture box (I couldn’t use the button) to display a mole on the screen. So when the timer starts the picMole.visible= true and when clicked score is changed mole becomes invisible and new position is generated for the mole.
What I want to do now is to make number of moles appearing at the same time to correspond to the level number so if level = 2 then 2 moles could appear at the same time.
How do I do this? I am incredibly stuck, i tried to use the control array and I got totally stuck :(

Please help!!

Recommended Answers

All 4 Replies

Show us what you have as there are so many different ways in which to do this, we would not want to lead you down a different road unless we had to...

Good Luck

so thats my "mole " part of the code

Private Sub tmrGame_Timer()
    Call next_level
End Sub

Private Sub imgMole_Click() 'when the picture of a mole is clicked
    imgMole.Visible = False     ' mole not visible
    score = score + 10          ' add 10 to the score
    With imgMole
        .Width = imgMole.Width * 0.9        'decrease the image size
        .Height = imgMole.Height * 0.9
    End With
    
    picOutput.Cls                       'clear the scorebox
    picOutput.Print score               'print the score in the scorebox
End Sub

Private Sub tmrHide_Timer()
    Dim z As Integer
    
        Randomize
        z = Int((3000 * Rnd) + 500) - level * 12     'create a random number
    
    imgMole.Visible = False         'hide the mole
    
End Sub

Private Sub tmrMoleAppear_Timer()
    Dim x As Integer
    Dim y As Integer

   Randomize
    x = Int((10320 * Rnd) + 3)   'creates random values for the mole to appear on the screen
    y = Int((8040 * Rnd) + 3)
    
    With imgMole            'assigns the values to the position of the mole
        .Left = x
        .Top = y
        .Visible = True     'show the mole
    End With
    
End Sub

Okay, this should be pretty simple and will not take much alteration to your code...

In design view, form view, click on the image control that holds the mole graphic, press CTRL+C, CTRL+V and when prompted if you want to create an array of controls, answer yes.

Okay, now double click on the image control and it should take you to a new Private Sub imgMole_Click(Index As Integer) sub but if it does not, then insert the Index As Integer into your old sub.

Now, you will have to modify you code so that it reflects these changes as you cannot refer to a image control like this anymore (imgMole.Left), but instead, you will have to refer to the individual image control by their index (imgMole(0).Width or imgMole(1).Width)

Then you might want to add a rnd to randomly pick an image control to make it visible.

And one last thing about the Randomize statement. You only need it once in the form load event.

Good Luck

thanks a lot for all the help !!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.