Advertisement
Guest User

Untitled

a guest
Dec 5th, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. Public Class frmWhack
  2.  
  3. Const ADDITIONAL_MOLES As Integer = 3
  4. Const MAX_MISSED As Integer = 20
  5. Const NUM_ROUNDS_ADD_MOLES As Integer = 3
  6.  
  7. Public moleList As New List(Of PictureBox)
  8. Public currentRound As Integer
  9. Public numMissed As Integer
  10. Public generator As New Random
  11. Public score As Integer
  12.  
  13. Private Sub PictureBox1_Click(sender As Object, e As EventArgs) Handles PictureBox1.Click
  14. Dim p As PictureBox
  15. p = DirectCast(sender, PictureBox)
  16. p.Visible = False
  17.  
  18. score = score + 1
  19. lblScore.text = score
  20. End Sub
  21.  
  22. Public Sub addMoles()
  23. Dim p As PictureBox
  24.  
  25. For x = 1 To ADDITIONAL_MOLES
  26.  
  27. p = New PictureBox
  28.  
  29. p.Height = 50
  30. p.Width = 50
  31. p.SizeMode = PictureBoxSizeMode.StretchImage
  32. p.Image = My.Resources.download
  33. p.Visible = False
  34. p.Left = generator.Next(0, Me.Width)
  35. p.Top = generator.Next(0, Me.Height)
  36. AddHandler p.Click, AddressOf PictureBox1_Click
  37.  
  38. Me.Controls.Add(p)
  39.  
  40. moleList.Add(p)
  41. Next
  42. End Sub
  43.  
  44. Private Sub TmrRoundOver_Tick(sender As Object, e As EventArgs) Handles tmrRoundOver.Tick
  45. For Each p In moleList
  46. If p.Visible = True Then
  47. numMissed = numMissed + 1
  48. p.Visible = False
  49. End If
  50.  
  51. Next
  52.  
  53. If numMissed > MAX_MISSED Then
  54. Call resetgame()
  55. End If
  56.  
  57. lblMissed.Text = numMissed
  58.  
  59. currentRound = currentRound + 1
  60. lblRounds.Text = currentRound
  61. If currentRound Mod NUM_ROUNDS_ADD_MOLES = 0 Then
  62. Call addMoles()
  63. End If
  64.  
  65. For Each p In moleList
  66. p.Visible = True
  67. p.Left = generator.Next(0, Me.Width - PictureBox1.Width)
  68. p.Top = generator.Next(0, Me.Height - PictureBox1.Height)
  69. Next
  70. End Sub
  71.  
  72. Public Sub resetgame()
  73. For Each p In moleList
  74. Me.Controls.Remove(p)
  75. Next
  76.  
  77. MsgBox("You Lose ")
  78. score = 0
  79. numMissed = 0
  80. currentRound = 0
  81. lblMissed.Text = "0"
  82. lblRounds.Text = "0"
  83. lblScore.Text = "0"
  84. moleList.Clear()
  85. Call addMoles()
  86. tmrRoundOver.Enabled = True
  87. End Sub
  88. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement