| 1 | '/**********************************************************************************\r |
| 2 | ' * Blackjack *\r |
| 3 | ' * Copyright 2013 Adrian Lam *\r |
| 4 | ' * Last edited 22/11/2013 *\r |
| 5 | ' * Version: beta *\r |
| 6 | ' **********************************************************************************\r |
| 7 | ' * Blackjack is free software: you can redistribute it and/or modify *\r |
| 8 | ' * it under the terms of the GNU General Public License as published by *\r |
| 9 | ' * the Free Software Foundation; either version 3 of the License, or *\r |
| 10 | ' * (at your option) any later version. *\r |
| 11 | ' * *\r |
| 12 | ' * This program is distributed in the hope that it will be useful, *\r |
| 13 | ' * but WITHOUT ANY WARRANTY; without even the implied warrranty of *\r |
| 14 | ' * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *\r |
| 15 | ' * GNU General Public License for more details. *\r |
| 16 | ' * *\r |
| 17 | ' * You should have received a copy of the GNU General Public License *\r |
| 18 | ' * along with this program. If not, see <http://www.gnu.org/licenses/> *\r |
| 19 | ' * *\r |
| 20 | ' **********************************************************************************/\r |
| 21 | \r |
| 22 | Public Class Blackjack\r |
| 23 | \r |
| 24 | Dim AllCards(52) As Boolean ' array to store whether each card has been dealt\r |
| 25 | ' 1-13 is Ace to King of spades, 14-26 is Ace to King of Hearts etc\r |
| 26 | \r |
| 27 | Dim PlayerCards(5) As Integer, PlayerCardCount As Integer, PlayerCardSum As Integer, PlayerCardSoftSum As Integer\r |
| 28 | \r |
| 29 | Dim DealerCards(5) As Integer, DealerCardCount As Integer, DealerCardSum As Integer, DealerCardSoftSum As Integer\r |
| 30 | \r |
| 31 | Dim PlayerSplitCards(5) As Integer, PlayerSplitCount As Integer, PlayerSplitSum As Integer, PlayerSplitSoftSum As Integer\r |
| 32 | \r |
| 33 | Dim SplitStatus As Integer '0 when no split, 1 when playing 1st hand split, 2 when playing 2nd hand\r |
| 34 | Dim Split1Busted As Boolean, Split2Busted As Boolean\r |
| 35 | \r |
| 36 | Private Sub Blackjack_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load\r |
| 37 | TxtBet.Focus()\r |
| 38 | CmdHit.Hide()\r |
| 39 | CmdStand.Hide()\r |
| 40 | CmdDoubleDown.Hide()\r |
| 41 | CmdSplit.Hide()\r |
| 42 | LblStatus.Text = "Enter bet amount and" & Chr(13) & Chr(10) & "click Deal to start"\r |
| 43 | Randomize() 'Seed pseudo-random number generator\r |
| 44 | End Sub\r |
| 45 | \r |
| 46 | Sub Initialise()\r |
| 47 | Dim i As Integer\r |
| 48 | LblStatus.Text = ""\r |
| 49 | CmdDeal.Hide()\r |
| 50 | CmdHit.Hide()\r |
| 51 | CmdStand.Hide()\r |
| 52 | CmdDoubleDown.Hide()\r |
| 53 | CmdSplit.Hide()\r |
| 54 | TxtBet.ReadOnly = True\r |
| 55 | For i = 1 To 52 Step 1\r |
| 56 | AllCards(i) = False\r |
| 57 | Next\r |
| 58 | For i = 1 To 5 Step 1\r |
| 59 | DealerCards(i) = 0\r |
| 60 | PlayerSplitCards(i) = 0\r |
| 61 | PlayerCards(i) = 0\r |
| 62 | Next\r |
| 63 | PlayerCardCount = 0\r |
| 64 | DealerCardCount = 0\r |
| 65 | PlayerCardSum = 0\r |
| 66 | PlayerCardSoftSum = 0\r |
| 67 | DealerCardSum = 0\r |
| 68 | DealerCardSoftSum = 0\r |
| 69 | PlayerSplitCount = 0\r |
| 70 | PlayerSplitSum = 0\r |
| 71 | PlayerSplitSoftSum = 0\r |
| 72 | SplitStatus = 0\r |
| 73 | TxtPlayerCard1.Text = ""\r |
| 74 | TxtPlayerCard1.Visible = False\r |
| 75 | TxtPlayerCard2.Text = ""\r |
| 76 | TxtPlayerCard2.Visible = False\r |
| 77 | TxtPlayerCard3.Text = ""\r |
| 78 | TxtPlayerCard3.Visible = False\r |
| 79 | TxtPlayerCard4.Text = ""\r |
| 80 | TxtPlayerCard4.Visible = False\r |
| 81 | TxtPlayerCard5.Text = ""\r |
| 82 | TxtPlayerCard5.Visible = False\r |
| 83 | TxtSplit1.Text = ""\r |
| 84 | TxtSplit1.Visible = False\r |
| 85 | TxtSplit2.Text = ""\r |
| 86 | TxtSplit2.Visible = False\r |
| 87 | TxtSplit3.Text = ""\r |
| 88 | TxtSplit3.Visible = False\r |
| 89 | TxtSplit4.Text = ""\r |
| 90 | TxtSplit4.Visible = False\r |
| 91 | TxtSplit5.Text = ""\r |
| 92 | TxtSplit5.Visible = False\r |
| 93 | TxtDealerCard1.Text = ""\r |
| 94 | TxtDealerCard1.Visible = False\r |
| 95 | TxtDealerCard2.Text = ""\r |
| 96 | TxtDealerCard2.Visible = False\r |
| 97 | TxtDealerCard3.Text = ""\r |
| 98 | TxtDealerCard3.Visible = False\r |
| 99 | TxtDealerCard4.Text = ""\r |
| 100 | TxtDealerCard4.Visible = False\r |
| 101 | TxtDealerCard5.Text = ""\r |
| 102 | TxtDealerCard5.Visible = False\r |
| 103 | Split1Busted = False\r |
| 104 | Split2Busted = False\r |
| 105 | End Sub\r |
| 106 | \r |
| 107 | Private Sub CmdDeal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDeal.Click\r |
| 108 | \r |
| 109 | '''''BEGIN VALIDATION'''''\r |
| 110 | If Val(TxtTotal.Text) <= 0 Then\r |
| 111 | MsgBox("You have no more money! Click OK to exit program...")\r |
| 112 | Me.Close()\r |
| 113 | End If\r |
| 114 | If TxtBet.Text = "" Or Not IsNumeric(TxtBet.Text) Or Int(Val(TxtBet.Text)) <= 0 Then\r |
| 115 | MsgBox("Please enter a valid bet value")\r |
| 116 | Return\r |
| 117 | End If\r |
| 118 | TxtBet.Text = CStr(Int(Val(TxtBet.Text)))\r |
| 119 | If Val(TxtBet.Text) > Val(TxtTotal.Text) Then\r |
| 120 | MsgBox("You don't have enough money for such a high bet! Please lower your bet value")\r |
| 121 | Return\r |
| 122 | End If\r |
| 123 | '''''END VALIDATION'''''\r |
| 124 | \r |
| 125 | Initialise()\r |
| 126 | TxtTotal.Text = CStr(Val(TxtTotal.Text) - Val(TxtBet.Text))\r |
| 127 | \r |
| 128 | '/**********************************************************************/\r |
| 129 | \r |
| 130 | DealToPlayer()\r |
| 131 | DealToPlayer()\r |
| 132 | 'BEGIN Deal hole card to dealer\r |
| 133 | DealOneCard(DealerCards, DealerCardCount, DealerCardSum, DealerCardSoftSum)\r |
| 134 | TxtDealerCard1.BackColor = Color.Gray\r |
| 135 | TxtDealerCard1.Visible = True\r |
| 136 | 'END Deal hole card to dealer\r |
| 137 | DealToDealer()\r |
| 138 | \r |
| 139 | '/**************************************************************************/\r |
| 140 | \r |
| 141 | '''''BEGIN INSURANCE'''''\r |
| 142 | If DealerCards(2) Mod 13 = 1 And Val(TxtTotal.Text) >= Int((Val(TxtBet.Text) + 1) / 2) Then ' If dealer's up card is Ace AND player has enough money Then\r |
| 143 | Dim OptionIns As Integer '6=yes, 7=no\r |
| 144 | OptionIns = MsgBox("Dealer may have blackjack, do you want insurance?", MsgBoxStyle.YesNo Or MsgBoxStyle.DefaultButton1 Or MsgBoxStyle.Exclamation)\r |
| 145 | If OptionIns = 6 And DealerCardSum = 21 Then\r |
| 146 | If PlayerCardSum = 21 Then\r |
| 147 | LblStatus.Text = "Dealer and you both have blackjack, push"\r |
| 148 | TxtTotal.Text = CStr(Int(Val(TxtBet.Text) * 5 / 2) + Val(TxtTotal.Text))\r |
| 149 | Else\r |
| 150 | LblStatus.Text = "Dealer has blackjack"\r |
| 151 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text))\r |
| 152 | End If\r |
| 153 | DisplayCard(TxtDealerCard1, DealerCards(1))\r |
| 154 | EnableDeal()\r |
| 155 | Return\r |
| 156 | ElseIf OptionIns = 6 And DealerCardSum <> 21 Then\r |
| 157 | LblStatus.Text = "Dealer does not have blackjack"\r |
| 158 | TxtTotal.Text = CStr(Val(TxtTotal.Text) - Int((Val(TxtBet.Text) + 1) / 2))\r |
| 159 | ElseIf OptionIns = 7 And DealerCardSum = 21 Then\r |
| 160 | LblStatus.Text = "Dealer has blackjack"\r |
| 161 | DisplayCard(TxtDealerCard1, DealerCards(1))\r |
| 162 | EnableDeal()\r |
| 163 | Return\r |
| 164 | End If\r |
| 165 | End If\r |
| 166 | '''''END INSURANCE'''''\r |
| 167 | \r |
| 168 | '''''BEGIN IF DEALER HAS BLACKJACK'''''\r |
| 169 | If DealerCardSum = 21 Then\r |
| 170 | If PlayerCardSum = 21 Then\r |
| 171 | LblStatus.Text = "Dealer and you both have blackjack, push"\r |
| 172 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text))\r |
| 173 | Else\r |
| 174 | LblStatus.Text = "Dealer has blackjack"\r |
| 175 | End If\r |
| 176 | DisplayCard(TxtDealerCard1, DealerCards(1))\r |
| 177 | EnableDeal()\r |
| 178 | Return\r |
| 179 | End If\r |
| 180 | '''''END IF DEALER HAS BLACKJACK'''''\r |
| 181 | \r |
| 182 | '''''BEGIN IF PLAYER HAS BLACKJACK'''''\r |
| 183 | If PlayerCardSum = 21 Then\r |
| 184 | LblStatus.Text = "You have blackjack!"\r |
| 185 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Int(Val(TxtBet.Text) * 5 / 2))\r |
| 186 | EnableDeal()\r |
| 187 | Return\r |
| 188 | End If\r |
| 189 | '''''END IF PLAYER HAS BLACKJACK'''''\r |
| 190 | \r |
| 191 | '/**************************************************************************/\r |
| 192 | \r |
| 193 | CmdStand.Show()\r |
| 194 | CmdHit.Show()\r |
| 195 | CmdDoubleDown.Show()\r |
| 196 | If PlayerCards(1) Mod 13 = PlayerCards(2) Mod 13 Then ' If both cards equal Then\r |
| 197 | CmdSplit.Show()\r |
| 198 | End If\r |
| 199 | End Sub\r |
| 200 | \r |
| 201 | Function RandBetween(ByVal lower As Integer, ByVal higher As Integer) ' Returns a random integer between lower and higher inclusive\r |
| 202 | Return Int((higher - lower + 1) * Rnd() + lower)\r |
| 203 | End Function\r |
| 204 | \r |
| 205 | Sub DisplayCard(ByRef card As TextBox, ByVal CardValue As Integer)\r |
| 206 | Dim face As String, suit As String = "" ' Initialised to stop the complaint of Visual Studio, syntactically and logically not required\r |
| 207 | \r |
| 208 | card.BackColor = Color.White ' Set the color of the textbox to white\r |
| 209 | If CardValue <> 0 Then\r |
| 210 | Select Case (Int((CardValue - 1) / 13))\r |
| 211 | Case 0\r |
| 212 | suit = "♠"\r |
| 213 | card.ForeColor = Color.Black ' Set the font color to black\r |
| 214 | Case 1\r |
| 215 | suit = "♥"\r |
| 216 | card.ForeColor = Color.Red\r |
| 217 | Case 2\r |
| 218 | suit = "♣"\r |
| 219 | card.ForeColor = Color.Black\r |
| 220 | Case 3\r |
| 221 | suit = "♦"\r |
| 222 | card.ForeColor = Color.Red\r |
| 223 | End Select\r |
| 224 | Select Case (CardValue Mod 13)\r |
| 225 | Case 0\r |
| 226 | face = "K"\r |
| 227 | Case 11\r |
| 228 | face = "J"\r |
| 229 | Case 12\r |
| 230 | face = "Q"\r |
| 231 | Case 1\r |
| 232 | face = "A"\r |
| 233 | Case Else\r |
| 234 | face = CStr(CardValue Mod 13)\r |
| 235 | End Select\r |
| 236 | card.Text = suit & Chr(13) & Chr(10) & face\r |
| 237 | card.Visible = True\r |
| 238 | End If\r |
| 239 | End Sub\r |
| 240 | \r |
| 241 | Sub DealOneCard(ByRef PersonCards() As Integer, ByRef PersonCardCount As Integer, ByRef PersonCardSum As Integer, ByRef PersonCardSoftSum As Integer)\r |
| 242 | Dim card As Integer\r |
| 243 | \r |
| 244 | Do ' Ensure that no cards are repeated\r |
| 245 | card = RandBetween(1, 52)\r |
| 246 | Loop Until Not AllCards(card)\r |
| 247 | AllCards(card) = True\r |
| 248 | \r |
| 249 | PersonCardCount = PersonCardCount + 1\r |
| 250 | PersonCards(PersonCardCount) = card\r |
| 251 | PersonCardSum = PersonCardSum + (card Mod 13)\r |
| 252 | ' Now this does not work if the card is A, J, Q or K, so the exceptions are handled below:\r |
| 253 | \r |
| 254 | If PersonCardSoftSum <> 0 Then ' If person has an ace Then\r |
| 255 | PersonCardSoftSum = PersonCardSoftSum + (card Mod 13)\r |
| 256 | End If\r |
| 257 | \r |
| 258 | Select Case (card Mod 13)\r |
| 259 | Case 0 ' is King\r |
| 260 | PersonCardSum = PersonCardSum + 10\r |
| 261 | If PersonCardSoftSum <> 0 Then ' If person has an ace Then\r |
| 262 | PersonCardSoftSum = PersonCardSoftSum + 10\r |
| 263 | End If\r |
| 264 | Case 11 ' is Jack\r |
| 265 | PersonCardSum = PersonCardSum - 1\r |
| 266 | If PersonCardSoftSum <> 0 Then\r |
| 267 | PersonCardSoftSum = PersonCardSoftSum - 1\r |
| 268 | End If\r |
| 269 | Case 12 ' is Queen\r |
| 270 | PersonCardSum = PersonCardSum - 2\r |
| 271 | If PersonCardSoftSum <> 0 Then\r |
| 272 | PersonCardSoftSum = PersonCardSoftSum - 2\r |
| 273 | End If\r |
| 274 | Case 1 ' is Ace\r |
| 275 | PersonCardSum = PersonCardSum + 10\r |
| 276 | If PersonCardSoftSum = 0 Then ' If person does not already have an ace Then\r |
| 277 | PersonCardSoftSum = PersonCardSum - 10\r |
| 278 | Else ' Person already has an ace\r |
| 279 | PersonCardSum = PersonCardSum - 10\r |
| 280 | End If\r |
| 281 | End Select\r |
| 282 | End Sub\r |
| 283 | \r |
| 284 | Sub DealToPlayer()\r |
| 285 | DealOneCard(PlayerCards, PlayerCardCount, PlayerCardSum, PlayerCardSoftSum)\r |
| 286 | DisplayCard(TxtPlayerCard1, PlayerCards(1))\r |
| 287 | DisplayCard(TxtPlayerCard2, PlayerCards(2))\r |
| 288 | DisplayCard(TxtPlayerCard3, PlayerCards(3))\r |
| 289 | DisplayCard(TxtPlayerCard4, PlayerCards(4))\r |
| 290 | DisplayCard(TxtPlayerCard5, PlayerCards(5))\r |
| 291 | End Sub\r |
| 292 | \r |
| 293 | Sub DealToDealer()\r |
| 294 | DealOneCard(DealerCards, DealerCardCount, DealerCardSum, DealerCardSoftSum)\r |
| 295 | ''card 1 skipped because it is hole card\r |
| 296 | DisplayCard(TxtDealerCard2, DealerCards(2))\r |
| 297 | DisplayCard(TxtDealerCard3, DealerCards(3))\r |
| 298 | DisplayCard(TxtDealerCard4, DealerCards(4))\r |
| 299 | DisplayCard(TxtDealerCard5, DealerCards(5))\r |
| 300 | End Sub\r |
| 301 | \r |
| 302 | Private Sub CmdHit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdHit.Click\r |
| 303 | CmdDoubleDown.Hide()\r |
| 304 | \r |
| 305 | If SplitStatus = 0 Then ' If player did not split Then\r |
| 306 | DealToPlayer()\r |
| 307 | If PlayerCardSoftSum > 21 Or (PlayerCardSum > 21 And PlayerCardSoftSum = 0) Then\r |
| 308 | LblStatus.Text = "You busted"\r |
| 309 | EnableDeal()\r |
| 310 | Return\r |
| 311 | ElseIf PlayerCardCount = 5 Then\r |
| 312 | LblStatus.Text = "You win"\r |
| 313 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text))\r |
| 314 | EnableDeal()\r |
| 315 | Return\r |
| 316 | ElseIf PlayerCardSum = 21 Or PlayerCardSoftSum = 21 Then ' Automatically stands if player reaches 21\r |
| 317 | CmdStand.PerformClick()\r |
| 318 | End If\r |
| 319 | \r |
| 320 | ElseIf SplitStatus = 1 Then ' ElseIf player splitted and is playing the first hand Then\r |
| 321 | DealToPlayer()\r |
| 322 | If PlayerCardSoftSum > 21 Or (PlayerCardSum > 21 And PlayerCardSoftSum = 0) Then\r |
| 323 | LblStatus.Text = "First hand busted" & Chr(13) & Chr(10) & "Second hand (top)"\r |
| 324 | Split1Busted = True\r |
| 325 | CmdHit.Show()\r |
| 326 | CmdStand.Show()\r |
| 327 | SplitStatus = 2 ' Starts player on second hand\r |
| 328 | ElseIf PlayerCardCount = 5 Then\r |
| 329 | LblStatus.Text = "First hand win" & Chr(13) & Chr(10) & "Second hand (top)"\r |
| 330 | SplitStatus = 2 ' Starts player on second hand\r |
| 331 | ElseIf PlayerCardSum = 21 Or PlayerCardSoftSum = 21 Then ' Automatically stands if player reaches 21\r |
| 332 | CmdStand.PerformClick()\r |
| 333 | End If\r |
| 334 | \r |
| 335 | Else ' ElseIf player splitted and is playing the second hand Then\r |
| 336 | DealToSplit()\r |
| 337 | If PlayerSplitSoftSum > 21 Or (PlayerSplitSum > 21 And PlayerSplitSoftSum = 0) Then\r |
| 338 | LblStatus.Text = "Second hand busted"\r |
| 339 | Split2Busted = True\r |
| 340 | EndSplitHands()\r |
| 341 | ElseIf PlayerSplitCount = 5 Then\r |
| 342 | LblStatus.Text = LblStatus.Text & "Second hand win" & Chr(13) & Chr(10)\r |
| 343 | EndSplitHands()\r |
| 344 | ElseIf PlayerSplitSoftSum = 21 Or PlayerSplitSum = 21 Then ' Automatically stands if player reaches 21\r |
| 345 | CmdStand.PerformClick()\r |
| 346 | End If\r |
| 347 | End If\r |
| 348 | End Sub\r |
| 349 | \r |
| 350 | Sub DealToSplit()\r |
| 351 | DealOneCard(PlayerSplitCards, PlayerSplitCount, PlayerSplitSum, PlayerSplitSoftSum)\r |
| 352 | DisplayCard(TxtSplit1, PlayerSplitCards(1))\r |
| 353 | DisplayCard(TxtSplit2, PlayerSplitCards(2))\r |
| 354 | DisplayCard(TxtSplit3, PlayerSplitCards(3))\r |
| 355 | DisplayCard(TxtSplit4, PlayerSplitCards(4))\r |
| 356 | DisplayCard(TxtSplit5, PlayerSplitCards(5))\r |
| 357 | End Sub\r |
| 358 | \r |
| 359 | Sub ScoreCalc(ByRef score As Integer, ByVal softsum As Integer, ByVal sum As Integer)\r |
| 360 | If softsum > 21 Or (sum > 21 And softsum = 0) Then ' If busted Then\r |
| 361 | score = 0\r |
| 362 | ElseIf sum > 21 And softsum <> 0 Then ' ElseIf sum busted but player has an ace and softsum not busted Then\r |
| 363 | score = softsum\r |
| 364 | Else\r |
| 365 | score = sum\r |
| 366 | End If\r |
| 367 | End Sub\r |
| 368 | \r |
| 369 | Sub EndSplitHands()\r |
| 370 | \r |
| 371 | If Split1Busted And Split2Busted Then\r |
| 372 | EnableDeal()\r |
| 373 | Return\r |
| 374 | End If\r |
| 375 | \r |
| 376 | DealerAlgo()\r |
| 377 | \r |
| 378 | '/***********************************************************/\r |
| 379 | \r |
| 380 | Dim score1 As Integer, score2 As Integer, dealerscore As Integer\r |
| 381 | \r |
| 382 | ScoreCalc(score1, PlayerCardSoftSum, PlayerCardSum)\r |
| 383 | ScoreCalc(score2, PlayerSplitSoftSum, PlayerSplitSum)\r |
| 384 | ScoreCalc(dealerscore, DealerCardSoftSum, DealerCardSum)\r |
| 385 | \r |
| 386 | If score1 = 0 Then\r |
| 387 | LblStatus.Text = "First hand busted" & Chr(13) & Chr(10)\r |
| 388 | ElseIf score1 > dealerscore Or (score1 <> 0 And PlayerCardCount = 5) Then\r |
| 389 | LblStatus.Text = "First hand win" & Chr(13) & Chr(10)\r |
| 390 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text))\r |
| 391 | ElseIf score1 = dealerscore Then\r |
| 392 | LblStatus.Text = "First hand push" & Chr(13) & Chr(10)\r |
| 393 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text))\r |
| 394 | Else\r |
| 395 | LblStatus.Text = "First hand lose" & Chr(13) & Chr(10)\r |
| 396 | End If\r |
| 397 | \r |
| 398 | If score2 = 0 Then\r |
| 399 | LblStatus.Text = LblStatus.Text & "Second hand busted" & Chr(13) & Chr(10)\r |
| 400 | ElseIf score2 > dealerscore Or (score2 <> 0 And PlayerSplitCount = 5) Then\r |
| 401 | LblStatus.Text = LblStatus.Text & "Second hand win" & Chr(13) & Chr(10)\r |
| 402 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text))\r |
| 403 | ElseIf score2 = dealerscore Then\r |
| 404 | LblStatus.Text = LblStatus.Text & "Second hand push" & Chr(13) & Chr(10)\r |
| 405 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text))\r |
| 406 | Else\r |
| 407 | LblStatus.Text = LblStatus.Text & "Second hand lose" & Chr(13) & Chr(10)\r |
| 408 | End If\r |
| 409 | \r |
| 410 | If dealerscore = 0 Then\r |
| 411 | LblStatus.Text = LblStatus.Text & "Dealer Busted" & Chr(13) & Chr(10)\r |
| 412 | End If\r |
| 413 | \r |
| 414 | '/*********************************************************/\r |
| 415 | \r |
| 416 | EnableDeal()\r |
| 417 | End Sub\r |
| 418 | \r |
| 419 | Sub DealerAlgo()\r |
| 420 | DisplayCard(TxtDealerCard1, DealerCards(1)) ' Show the hole card\r |
| 421 | While ((DealerCardSum < 17 And DealerCardSoftSum = 0) Or (DealerCardSoftSum < 17 And DealerCardSoftSum <> 0)) And DealerCardCount < 5 'While dealer has not reached 17\r |
| 422 | DealToDealer()\r |
| 423 | End While\r |
| 424 | End Sub\r |
| 425 | \r |
| 426 | Sub EnableDeal()\r |
| 427 | CmdDeal.Show()\r |
| 428 | TxtBet.ReadOnly = False\r |
| 429 | CmdHit.Hide()\r |
| 430 | CmdStand.Hide()\r |
| 431 | CmdDoubleDown.Hide()\r |
| 432 | CmdSplit.Hide()\r |
| 433 | End Sub\r |
| 434 | \r |
| 435 | Private Sub CmdStand_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdStand.Click\r |
| 436 | If SplitStatus = 1 Then ' If player splitted and is playing first hand Then\r |
| 437 | SplitStatus = 2 ' Starts player on second hand\r |
| 438 | CmdHit.Show()\r |
| 439 | CmdStand.Show()\r |
| 440 | CmdDoubleDown.Hide()\r |
| 441 | LblStatus.Text = "Second hand (top)"\r |
| 442 | \r |
| 443 | ElseIf SplitStatus = 2 Then ' ElseIf player splitted and is playing second hand Then\r |
| 444 | EndSplitHands()\r |
| 445 | \r |
| 446 | Else ' player did not split\r |
| 447 | DealerAlgo()\r |
| 448 | \r |
| 449 | '/*************************************************************************/\r |
| 450 | \r |
| 451 | Dim PlayerScore As Integer = 0, DealerScore As Integer = 0\r |
| 452 | If DealerCardSum > 21 And (DealerCardSoftSum > 21 Or DealerCardSoftSum = 0) Then\r |
| 453 | LblStatus.Text = "Dealer busted"\r |
| 454 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text))\r |
| 455 | EnableDeal()\r |
| 456 | Return\r |
| 457 | ElseIf DealerCardSum > 21 And DealerCardSoftSum <> 0 Then\r |
| 458 | DealerScore = DealerCardSoftSum\r |
| 459 | Else\r |
| 460 | DealerScore = DealerCardSum\r |
| 461 | End If\r |
| 462 | \r |
| 463 | If PlayerCardSum > 21 Then PlayerScore = PlayerCardSoftSum Else PlayerScore = PlayerCardSum\r |
| 464 | \r |
| 465 | If PlayerScore > DealerScore Then\r |
| 466 | LblStatus.Text = "You win"\r |
| 467 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text))\r |
| 468 | EnableDeal()\r |
| 469 | ElseIf PlayerScore = DealerScore Then\r |
| 470 | LblStatus.Text = "Push"\r |
| 471 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text))\r |
| 472 | EnableDeal()\r |
| 473 | Else\r |
| 474 | LblStatus.Text = "You lose"\r |
| 475 | EnableDeal()\r |
| 476 | End If\r |
| 477 | \r |
| 478 | '/*************************************************************************/\r |
| 479 | \r |
| 480 | End If\r |
| 481 | End Sub\r |
| 482 | \r |
| 483 | Private Sub CmdDoubleDown_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdDoubleDown.Click\r |
| 484 | CmdDoubleDown.Hide()\r |
| 485 | \r |
| 486 | \r |
| 487 | Dim SecondBet As String\r |
| 488 | SecondBet = InputBox("Enter second bet value:")\r |
| 489 | While Val(SecondBet) > Val(TxtBet.Text) Or Val(SecondBet) > Val(TxtTotal.Text) Or SecondBet = "" Or Not IsNumeric(SecondBet) Or Int(Val(SecondBet)) <= 0\r |
| 490 | If Val(SecondBet) > Val(TxtBet.Text) Or Val(SecondBet) > Val(TxtTotal.Text) Then\r |
| 491 | SecondBet = InputBox("Second bet too large, please enter another value:")\r |
| 492 | Else\r |
| 493 | SecondBet = InputBox("Please enter a correct numerical positive integral value:")\r |
| 494 | End If\r |
| 495 | End While\r |
| 496 | TxtTotal.Text = CStr(Val(TxtTotal.Text) - Val(SecondBet))\r |
| 497 | \r |
| 498 | \r |
| 499 | DealToPlayer()\r |
| 500 | \r |
| 501 | If PlayerCardSoftSum > 21 Or (PlayerCardSum > 21 And PlayerCardSoftSum = 0) Then\r |
| 502 | LblStatus.Text = "You busted"\r |
| 503 | EnableDeal()\r |
| 504 | Return\r |
| 505 | End If\r |
| 506 | \r |
| 507 | DealerAlgo()\r |
| 508 | \r |
| 509 | '/*******************************************************************************/\r |
| 510 | \r |
| 511 | Dim PlayerScore As Integer = 0, DealerScore As Integer = 0\r |
| 512 | If DealerCardSum > 21 And (DealerCardSoftSum > 21 Or DealerCardSoftSum = 0) Then\r |
| 513 | LblStatus.Text = "Dealer busted"\r |
| 514 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text) + 2 * Val(SecondBet))\r |
| 515 | EnableDeal()\r |
| 516 | Return\r |
| 517 | ElseIf DealerCardSum > 21 And DealerCardSoftSum <> 0 Then\r |
| 518 | DealerScore = DealerCardSoftSum\r |
| 519 | Else\r |
| 520 | DealerScore = DealerCardSum\r |
| 521 | End If\r |
| 522 | \r |
| 523 | If PlayerCardSum > 21 Then PlayerScore = PlayerCardSoftSum Else PlayerScore = PlayerCardSum\r |
| 524 | \r |
| 525 | If PlayerScore > DealerScore Then\r |
| 526 | LblStatus.Text = "You win"\r |
| 527 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + 2 * Val(TxtBet.Text) + 2 * Val(SecondBet))\r |
| 528 | EnableDeal()\r |
| 529 | ElseIf PlayerScore = DealerScore Then\r |
| 530 | LblStatus.Text = "Push"\r |
| 531 | TxtTotal.Text = CStr(Val(TxtTotal.Text) + Val(TxtBet.Text) + Val(SecondBet))\r |
| 532 | EnableDeal()\r |
| 533 | Else\r |
| 534 | LblStatus.Text = "You lose"\r |
| 535 | EnableDeal()\r |
| 536 | End If\r |
| 537 | \r |
| 538 | '/********************************************************************************/\r |
| 539 | \r |
| 540 | End Sub\r |
| 541 | \r |
| 542 | Private Sub CmdSplit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdSplit.Click\r |
| 543 | CmdSplit.Hide()\r |
| 544 | TxtSplit1.Text = TxtPlayerCard2.Text\r |
| 545 | TxtSplit1.Visible = True\r |
| 546 | TxtPlayerCard2.Text = ""\r |
| 547 | TxtPlayerCard2.Visible = False\r |
| 548 | \r |
| 549 | LblStatus.Text = "first hand (bottom)"\r |
| 550 | SplitStatus = 1 ' Starts the player on split on first hand\r |
| 551 | \r |
| 552 | '''''BEGIN set counters'''''\r |
| 553 | PlayerCardSum = PlayerCardSum / 2\r |
| 554 | PlayerCardSoftSum = PlayerCardSoftSum / 2\r |
| 555 | PlayerSplitSum = PlayerCardSum\r |
| 556 | PlayerSplitSoftSum = PlayerCardSoftSum\r |
| 557 | PlayerCardCount = 1\r |
| 558 | PlayerSplitCount = 1\r |
| 559 | PlayerSplitCards(1) = PlayerCards(2)\r |
| 560 | PlayerCards(2) = 0\r |
| 561 | '''''END set counters'''''\r |
| 562 | \r |
| 563 | DealToPlayer()\r |
| 564 | DealToSplit()\r |
| 565 | CmdStand.Show()\r |
| 566 | CmdHit.Show()\r |
| 567 | CmdDoubleDown.Hide()\r |
| 568 | End Sub\r |
| 569 | \r |
| 570 | Private Sub CmdRules_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdRules.Click\r |
| 571 | '''''Open a new form with the rules on it'''''\r |
| 572 | Dim rules As New Rules ' Declare the new form\r |
| 573 | rules.Show() ' Show the new form\r |
| 574 | End Sub\r |
| 575 | \r |
| 576 | End Class\r |