sonicamps
asked on
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.
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.
ASKER
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(ByVa l sender As Object, ByVal e As System.Windows.Forms.Mouse EventArgs) 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???
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(ByVa
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???
Use a variable that gets increased when you click on the picture..
:-)
:-)
ASKER
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 :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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.
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.
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..
:-)
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..
:-)
ASKER
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.
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.
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
:-)
-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
:-)
ASKER
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...
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..
:-)
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..
:-)
May I assume that you got that working? Glad if I helped..
:-)
:-)
:-)