Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class frmWhack
- Const ADDITIONAL_MOLES As Integer = 3
- Const MAX_MISSED As Integer = 20
- Const NUM_ROUNDS_ADD_MOLES As Integer = 3
- Public moleList As New List(Of PictureBox)
- Public currentRound As Integer
- Public numMissed As Integer
- Public generator As New Random
- Public score As Integer
- Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
- Dim p As PictureBox
- p = DirectCast(sender, PictureBox)
- p.Visible = False
- score = score + 1
- lblScore.text = score
- End Sub
- Public Sub addMoles()
- Dim p As PictureBox
- For x = 1 To ADDITIONAL_MOLES
- p = New PictureBox
- p.Height = 50
- p.Width = 50
- p.SizeMode = PictureBoxSizeMode.StretchImage
- p.Image = My.Resources.download
- p.Visible = False
- p.Left = generator.Next(0, Me.Width)
- p.Top = generator.Next(0, Me.Height)
- AddHandler p.Click, AddressOf PictureBox1_Click
- Me.Controls.Add(p)
- moleList.Add(p)
- Next
- End Sub
- Private Sub TmrRoundOver_Tick(sender As Object, e As EventArgs) Handles tmrRoundOver.Tick
- For Each p In moleList
- If p.Visible = True Then
- numMissed = numMissed + 1
- p.Visible = False
- End If
- Next
- If numMissed > MAX_MISSED Then
- Call resetgame()
- End If
- lblMissed.Text = numMissed
- currentRound = currentRound + 1
- lblRounds.Text = currentRound
- If currentRound Mod NUM_ROUNDS_ADD_MOLES = 0 Then
- Call addMoles()
- End If
- For Each p In moleList
- p.Visible = True
- p.Left = generator.Next(0, Me.Width - PictureBox1.Width)
- p.Top = generator.Next(0, Me.Height - PictureBox1.Height)
- Next
- End Sub
- Public Sub resetgame()
- For Each p In moleList
- Me.Controls.Remove(p)
- Next
- MsgBox("You Lose ")
- score = 0
- numMissed = 0
- currentRound = 0
- lblMissed.Text = "0"
- lblRounds.Text = "0"
- lblScore.Text = "0"
- moleList.Clear()
- Call addMoles()
- tmrRoundOver.Enabled = True
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement