Guest User

Untitled

a guest
Jan 19th, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.41 KB | None | 0 0
  1. Public Class Form1
  2. 'Sets the Variables to Integers
  3. Dim pcard1 As Integer
  4. Dim pcard2 As Integer
  5. Dim pcard3 As Integer
  6. Dim pcard4 As Integer
  7. Dim dcard1 As Integer
  8. Dim dcard2 As Integer
  9. Dim dcard3 As Integer
  10. Dim dcard4 As Integer
  11. Dim counter As Integer
  12. Dim dcounter As Integer
  13. Dim total As Integer
  14. Dim dtotal As Integer
  15.  
  16. 'New Game Button
  17. Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
  18. 'Generates a two new cards for the Player
  19. Randomize() 'This makes it so the Randomizer isn't always 10, 7, 4
  20. pcard1 = Int(Rnd() * 13) + 1
  21. pcard2 = Int(Rnd() * 13) + 1
  22. lblpcard1.Text = pcard1
  23. lblpcard2.Text = pcard2
  24. 'Generates a two new cards for the Dealer
  25. dcard1 = Int(Rnd() * 13) + 1
  26. dcard2 = Int(Rnd() * 13) + 1
  27. lbldcard1.Text = dcard1
  28. lbldcard2.Text = dcard2
  29. 'Sets the Value of 11,12,13 to 10 and checks set's the 1 to 11
  30. If pcard1 > 10 Then
  31. pcard1 = 10
  32. End If
  33. If pcard2 > 10 Then
  34. pcard2 = 10
  35. End If
  36. If pcard1 = 1 Then
  37. pcard1 = 11
  38. End If
  39. If pcard2 = 1 Then
  40. pcard2 = 11
  41. End If
  42. 'Sets the Dealers Value of 11,12,13 to 10 and checks set's the 1 to 11
  43. If dcard1 > 10 Then
  44. dcard1 = 10
  45. End If
  46. If dcard2 > 10 Then
  47. dcard2 = 10
  48. End If
  49. If dcard1 = 1 Then
  50. dcard1 = 11
  51. End If
  52. If dcard2 = 1 Then
  53. dcard2 = 11
  54. End If
  55. 'Sets Everything But Dealer + Player Cards to Default/Blank
  56. lblpcard3.Text = "Card 3"
  57. pcard3 = 0
  58. pcard4 = 0
  59. total = 0
  60. dcard3 = 0
  61. dcard4 = 0
  62. lbldcard3.Text = "Card 3"
  63. dtotal = 0
  64. counter = 0
  65. dcounter = 0
  66. lbllog.Text = "Log:"
  67. 'Calculates the Total and Checks to see if It's a BlackJack
  68. total = pcard1 + pcard2
  69. dtotal = dcard1 + dcard2
  70. If total = 21 Then
  71. lbllog.Text = "Black Jack!" & total
  72. End If
  73. End Sub
  74. 'Hit Button
  75. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  76. If counter = 1 Then
  77. lbllog.Text = "Second Hit" & total
  78. counter = counter + 1
  79. ElseIf counter = 2 Then
  80. lbllog.Text = "Third Hit" & total
  81. counter = counter + 1
  82. ElseIf counter = 3 Then
  83. lbllog.Text = "Fourth Hit" & total
  84. Else
  85. 'On the First Hit, Generates a the Third Player Card
  86. counter = counter + 1
  87. pcard3 = Int(Rnd() * 13) + 1
  88. lblpcard3.Text = pcard3
  89. 'Checks if the card is over 11 then set it to a value of 10
  90. If pcard3 > 10 Then
  91. pcard3 = 10
  92. End If
  93. 'Calculates Current Total
  94. total = total + pcard3
  95. 'Checks the Aces then Recalculates the Total
  96. If total > 21 Then
  97. If pcard1 = 11 Then
  98. pcard1 = 1
  99. total = total - 10
  100. ElseIf pcard2 = 11 Then
  101. pcard2 = 1
  102. total = total - 10
  103. ElseIf pcard3 = 11 Then
  104. pcard3 = 1
  105. total = total - 10
  106. End If
  107. End If
  108. 'Checks to see if the Player Busted
  109. lbllog.Text = "First Hit" & total
  110. If total > 21 Then
  111. lbllog.Text = "Busted" & total
  112. End If
  113. End If
  114. End Sub
  115.  
  116. Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
  117. total = pcard1 + pcard2 + pcard3 + pcard4
  118. 'Starts Dealing the dealers cards. While the dealer is Equal to or Under 16 he will Hit
  119. While dtotal <= 16
  120. If dcounter = 0 Then
  121. dcard3 = Int(Rnd() * 13) + 1
  122. lbldcard3.Text = dcard3
  123. 'Checks to see if the card is over 10 and if it is sets its value to 10.
  124. If dcard3 > 10 Then
  125. dcard3 = 10
  126. End If
  127. dtotal = dtotal + dcard3
  128. 'Checks the Aces then Recalculates the Total
  129. If dtotal > 21 Then
  130. If dcard1 = 11 Then
  131. dcard1 = 1
  132. total = total - 10
  133. ElseIf dcard2 = 11 Then
  134. dcard2 = 1
  135. total = total - 10
  136. ElseIf dcard3 = 11 Then
  137. dcard3 = 1
  138. total = total - 10
  139. End If
  140. 'Ends te Counter and starts the next Hit.
  141. ElseIf dcounter = 1 Then
  142. dcard4 = Int(Rnd() * 13) + 1
  143. lbldcard4.Text = dcard4
  144. dtotal = dtotal + dcard4
  145. ElseIf dcounter = 2 Then
  146.  
  147. ElseIf dcounter = 3 Then
  148.  
  149. End If
  150. End If
  151. End While
  152. lbllog.Text = total & dtotal
  153. End Sub
  154.  
  155. Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
  156.  
  157. End Sub
  158. End Class
Add Comment
Please, Sign In to add comment