Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

Basic VB Program involving moving picture

I need to design a basic VB program game that involves a moving picture, it must meet the following requirements:

1. The user should track a fixed dimension picture that moves in a random manner on the computer screen and click it three times in order in order to "win".

2. The user is to be given a 10 second time limit to perform the task.

3. The project should print a greeting message when the user wins the game.

4. If this does not happen, the game should be terminated with a game over message on the screen informing the player that he has lost the game.

Immediate help is greatly appreciated.
0
sonicamps
Asked:
sonicamps
  • 7
  • 5
1 Solution
 
andrebaCommented:
We are not allowed to do homework here.. Could you show us what you have done and tell us where can we assist?

:-)
0
 
sonicampsAuthor Commented:
Ok, Here is what I have so far:

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click



    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        PictureBox1.Location = New Point(250, 80)
        Timer1.Enabled = True

    End Sub

    Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick

        MsgBox("GAME OVER - YOU HAVE LOST THE GAME - Click ok to play again!")


    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        Timer1.Enabled = False
        MsgBox("CONGRATULATIONS, YOU HAVE WON THE GAME!!!")


    End Sub
End Class

I used the mouse down event to display the message box when I click on the picture, but I am having trouble figuring out how set it so that I have to click 3 times.  Any thoughts???
0
 
andrebaCommented:
Use a variable that gets increased when you click on the picture..

:-)
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
sonicampsAuthor Commented:
Any way to give a little more direction without actually typing the code??  I can create a variable, but am a little fuzzy on how to increase it.  I appreciate your help by the way :)
0
 
andrebaCommented:
no probs, I'll give you the logic:

if the picture gets clicked then
variable = variable + 1
end if

Let's do this step by step, you should have it working in no time.. Please post your feedback as soon as you have any..

:-)
0
 
sonicampsAuthor Commented:
I thought an if then statement would work.   I have created a variable called clickVar, the code is below:

        Dim clickVar As Integer
        Dim clickVar2 As Integer
        If PictureBox1.(how do specify that it is being clicked?) Then  
            clickVar2 = clickVar + 1
        End If

And do I put this code in the PictureBox1_MouseDown sub procedure??

Hmmm...still searching.
0
 
andrebaCommented:
Good good..
Sry if I misled you: your clickVar= clickVar + 1 should be in the MouseDown procedure, there's no need for an IF (i was just showing the logic..)

Also note that you do not need two variables, one will do. Make sure you initialize the variable to 0 upon beginning of the game..

Try and let me know..

:-)

0
 
sonicampsAuthor Commented:
This the code under the MouseDown procedure:
 
        Dim clickVar As Integer
        clickVar = 0
        clickVar = clickVar + 1
        clickVar = clickVar + 2


        Timer1.Enabled = False
        MsgBox("CONGRATULATIONS, YOU HAVE WON THE GAME!!!")

The message box is still coming up after only 1 click.  I am trying am trying a few more things here.
0
 
andrebaCommented:
Good.. Keep trying, errors foster knowledge..

-The variable should be declared and initialized OUTSIDE the MouseDown procedure
-Only one line is needed in the MouseDown procedure at this stage
clickVar = clickVar + 1

:-)
0
 
sonicampsAuthor Commented:
I am having some trouble figuring out where to declare and initialize the variable so that it can be passed to the mousedown procedure.  Reading reading reading...
0
 
andrebaCommented:
Perseverance, that's one of the keys.. Good going!

A global variable is declared outside procedures.. Give it a shot..

Note that I'll be in the office for another hour+ only, so please expedite any questions that I might be able to assist you with.. Otherwise, it'll have to wait until tomorrow..

:-)
0
 
andrebaCommented:
May I assume that you got that working? Glad if I helped..

:-)
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

  • 7
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now