Game

clare
01-04-2005, 04:43 AM
hey

im clare and i am new at vb.net

i have written a shooting game where u hit a black and yellow bee (its for a uni course for children) as u can see from the coding below i have got the bees flying round but do not know how get a final score.

Please help.... thanks

'back to the main page'

Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
Dim startInstance As New start
startInstance.Show()
Me.Hide()
End Sub
'start button'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer2.Enabled = True
hits = 0
display = 0
End Sub
'timer 1 bee'
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim objRand As New Random
Dim iRandom1 As Integer
Dim iRandom2 As Integer
iRandom1 = objRand.Next(8, 414)
iRandom2 = objRand.Next(16, 176)
PictureBox1.Left = iRandom1
PictureBox1.Top = iRandom2
display = display + 1
TextBox1.Text = display
End Sub
'Bee'
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
hits = hits + 1
TextBox2.Text = hits
End Sub
'timer 2 evil bee'
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim objRand As New Random
Dim iRandom3 As Integer
Dim iRandom4 As Integer
iRandom3 = objRand.Next(28, 380)
iRandom4 = objRand.Next(28, 180)
PictureBox2.Left = iRandom3
PictureBox2.Top = iRandom4
End Sub
'evil bee'
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
hits = hits + 1
TextBox2.Text = hits
End Sub
'easy level'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim shootInstance As New shoot
shootInstance.Show()
Me.Hide()
End Sub
'medium level'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim shoot1Instance As New shoot1
shoot1Instance.Show()
Me.Hide()
End Sub
'hard level'
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim shoot2Instance As New shoot2
shoot2Instance.Show()
Me.Hide()
End Sub
'end'
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
End
End Sub
End Class

Faith
01-04-2005, 05:15 AM
Clare, Could you edit your post for a bit to and wrap your code with the vb/vb tags, so it looks more like vb code. :)

Faith
01-04-2005, 05:19 AM
I see you have:

Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
hits = hits + 1
TextBox2.Text = hits
End Sub

I guess the amount of hits would be a sufficient score, don't you think? Like your hitcount = score...

clare
01-04-2005, 05:31 AM
'back to the main page'
Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
Dim startInstance As New start
startInstance.Show()
Me.Hide()
End Sub
'start button'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer2.Enabled = True
hits = 0
display = 0
End Sub
'timer 1 bee'
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim objRand As New Random
Dim iRandom1 As Integer
Dim iRandom2 As Integer
iRandom1 = objRand.Next(8, 414)
iRandom2 = objRand.Next(16, 176)
PictureBox1.Left = iRandom1
PictureBox1.Top = iRandom2
display = display + 1
TextBox1.Text = display
End Sub
'Bee'
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
hits = hits + 1
TextBox2.Text = hits
End Sub
'timer 2 evil bee'
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim objRand As New Random
Dim iRandom3 As Integer
Dim iRandom4 As Integer
iRandom3 = objRand.Next(28, 380)
iRandom4 = objRand.Next(28, 180)
PictureBox2.Left = iRandom3
PictureBox2.Top = iRandom4
End Sub
'evil bee'
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
hits = hits + 1
TextBox2.Text = hits
End Sub
'easy level'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim shootInstance As New shoot
shootInstance.Show()
Me.Hide()
End Sub
'medium level'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim shoot1Instance As New shoot1
shoot1Instance.Show()
Me.Hide()
End Sub
'hard level'
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim shoot2Instance As New shoot2
shoot2Instance.Show()
Me.Hide()
End Sub
'end'
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
End
End Sub
End Class


Where woudl i put that within the start button?

clare
01-04-2005, 05:40 AM
which button do u press on here 2 get it 2 show vb coding?

clare
01-04-2005, 05:42 AM
Also do u have to make hitcounter into a 'As Integer'

clare
01-04-2005, 05:47 AM
'back to the main page'
Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel3.LinkClicked
Dim startInstance As New start
startInstance.Show()
Me.Hide()
End Sub
'start button'
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Timer1.Enabled = True
Timer2.Enabled = True
hits = 0
display = 0
End Sub
'timer 1 bee'
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Dim objRand As New Random
Dim iRandom1 As Integer
Dim iRandom2 As Integer
iRandom1 = objRand.Next(8, 414)
iRandom2 = objRand.Next(16, 176)
PictureBox1.Left = iRandom1
PictureBox1.Top = iRandom2
display = display + 1
TextBox1.Text = display
End Sub
'Bee'
Private Sub PictureBox1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.Click
hits = hits + 1
TextBox2.Text = hits
End Sub
'timer 2 evil bee'
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim objRand As New Random
Dim iRandom3 As Integer
Dim iRandom4 As Integer
iRandom3 = objRand.Next(28, 380)
iRandom4 = objRand.Next(28, 180)
PictureBox2.Left = iRandom3
PictureBox2.Top = iRandom4
End Sub
'evil bee'
Private Sub PictureBox2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
hits = hits + 1
TextBox2.Text = hits
End Sub
'easy level'
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim shootInstance As New shoot
shootInstance.Show()
Me.Hide()
End Sub
'medium level'
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim shoot1Instance As New shoot1
shoot1Instance.Show()
Me.Hide()
End Sub
'hard level'
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
Dim shoot2Instance As New shoot2
shoot2Instance.Show()
Me.Hide()
End Sub
'end'
Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabel2.LinkClicked
End
End Sub
End Class

Iceplug
01-04-2005, 08:47 AM
Now, what's the problem?
Where do you have hits declared?
I would assume that the code in the picturebox click would belong in the picturebox click.

Faith
01-05-2005, 02:14 AM
There was actually nothing wrong with the code at all, all that had to be done is add a small line to extract the score out of the "hits" variable, and show it in a small msgbox. The hits was a public variable in a module. :)

clare
01-05-2005, 03:21 AM
in the end i find it out on my own, sorry for any trouble. it was quite easy actually. stupid me

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum