home *** CD-ROM | disk | FTP | other *** search
- DefInt A-Z
-
- Sub ShowHandIndicator ()
- ' If the player has split hands, then show the arrow indicator for
- ' the active hand.
- If Split Then
- BjForm.HandIndicator(ActivePlayer).Picture = BjForm.HandIndicator(0).Picture
- BjForm.HandIndicator(3 - ActivePlayer).Picture = LoadPicture()
- End If
-
- End Sub
-
- Sub Shuffle ()
-
- ' shuffle the cards
- Static Check(53)
- ' Set our check array to all 1's
- For Count = 1 To 52
- Check(Count) = 1
- Next
- ' Stack the deck(s)
- For Count = 1 To CARDSINDECK * Decks
- RandomNumber = Rnd(1) * CARDSINDECK
- 'if we haven't assigned this card yet for each deck
- If Check(RandomNumber) <= Decks And RandomNumber <> 0 Then
- Check(RandomNumber) = Check(RandomNumber) + 1' Mark it as assigned
- Cards(Count) = RandomNumber
- Else
- Count = Count - 1 ' continue through loop
- End If
- Next
- CardsLeft = CARDSINDECK * Decks
- NextCard = 1
-
- End Sub
-
- Sub ShowBetAmount ()
-
- BjForm.BaseBetAmount.text = Str$(Bet(PLAYER))
-
- End Sub
-
- Sub ShowStakeAmount ()
-
- ' Show the stake in the text box
- BjForm.Amount(0).Caption = Str$(Stake&)
-
- End Sub
-
- Function CardValue (Who%, WhichCard%)
-
- Temp% = Hands(Who%, WhichCard) Mod 13
- If Temp% = 0 Then
- Temp = 13 ' isolate to 1-13 (A-K)
- End If
- CardValue = Temp
-
- End Function
-
- Function HandValue (Who%) ' calculate the value of a hand
-
- Aces = 0 ' Start with no aces
- Tot = 0 ' and zero total
- ' For each card
- For WhichCard = 1 To HowManyCards(Who)
- Cvalue = CardValue(Who, WhichCard)
- ' If it's 10, J, Q or K
- If Cvalue >= 10 Then
- Cvalue = 10
- ElseIf Cvalue = 1 Then ' If it's an ace
- Aces = Aces + 1
- End If
-
- ' Accumulate the total
- Tot = Tot + Cvalue
-
- ' If hand totals eleven, and there's one ace, and only
- ' two cards in the hand, then it must be blackjack!
- If Tot = 11 And Aces = 1 And HowManyCards(Who) = 2 Then
- PlayerHasBJ(Who) = 1
- Tot = 21
- Exit For
- End If
- Next
- HandValue = Tot
-
- End Function
-
- Sub ShowFirst ()
-
- ' This sub adds text to the message if it's a split hand
- If Split Then
- If ActivePlayer = PLAYERB Then
- Message$ = Message$ + " (2nd hand)"
- Else
- Message$ = Message$ + " (1st hand)"
- End If
- End If
-
- End Sub
-
- Sub YouLose ()
-
- Stake& = Stake& - Bet(ActivePlayer)
- ShowStakeAmount
- Message$ = "You lose your bet!"
- ShowFirst
- MsgBox Message$, 64, "Too Bad!"
-
- End Sub
-
- Sub YouPush ()
-
- Message$ = "This hand is a push. At least you didn't lose!"
- ShowFirst
- MsgBox Message$, 64, "Nobody Wins!"
-
- End Sub
-
- Sub YouWin ()
-
- Stake& = Stake& + Bet(ActivePlayer)
- ShowStakeAmount
- Message$ = "You win!"
- ShowFirst
- MsgBox Message$, 64, "Congratulations!"
-
- End Sub
-
- Sub YouWinBJ ()
-
- Stake& = Stake& + Bet(ActivePlayer) + Bet(ActivePlayer) / 2
- ShowStakeAmount
- Message$ = "You win 1.5 times your bet!"
- ShowFirst
- MsgBox Message$, 64, "LOOSE DEALER!"
-
- End Sub
-
- Sub YouLoseInsurance ()
-
- Stake& = Stake& - Bet(ActivePlayer) / 2
- ShowStakeAmount
- Message$ = "You lose your insurance bet!"
- ShowFirst
- MsgBox Message$, 64, "Oops!"
-
- End Sub
-
- Sub ShowValue (Who%)
-
- ' Calculates the hand value and displays it in a label
- Total(Who) = HandValue(Who)
- If Who = DEALER Then
- DealerVisible = MhTrue
- End If
-
- If PlayerHasBJ(Who) Then
- BjForm.ScoreBox(Who%).ForeColor = RGB(128, 0, 0) ' Red
- BjForm.ScoreBox(Who%).Caption = "BLACKJACK!"
- PlayerDone(Who) = 1
- Exit Sub
- End If
-
- BjForm.ScoreBox(Who%).ForeColor = RGB(0, 0, 0) ' Assume black
- Temp = Total(Who) ' Secondary hand value counter
- Message$ = Str$(Total(Who)) ' Start with raw score
-
- ' If we're calculating dealer's score, adjust temp to account
- ' for all possible values
- Do While Who = DEALER And Temp <= 11 And Aces <> 0
- Temp = Temp + 10
- Aces = Aces - 1
- ' If the dealer has 17 or more, he must stand
- If Temp >= 17 Then
- Total(Who) = Temp
- Message$ = Str$(Temp)
- PlayerDone(DEALER) = 1
- End If
- Loop
-
- ' Anytime a player has 21, we no longer offer a hit
- If Total(Who) = 21 Then
- PlayerDone(Who) = 1
- End If
-
- ' If the player is done, then calculate final hand value
- If PlayerDone(Who) Then
- While Temp <= 11 And Aces <> 0
- Temp = Temp + 10
- Aces = Aces - 1
- Wend
- Total(Who) = Temp
- Message$ = Str$(Temp)
- Else
- ' Calculate all possible values
- While Temp <= 11 And Aces <> 0
- Temp = Temp + 10
- Message$ = Message$ + " or" + Str$(Temp)
- Aces = Aces - 1
- Wend
- End If
- If Temp = 21 Then
- Total(Who) = 21
- PlayerDone(Who) = 1
- Message$ = "21"
- ElseIf Total(Who) >= 22 Then
- Busted(Who) = 1
- PlayerDone(Who) = 1
- BjForm.ScoreBox(Who%).ForeColor = RGB(128, 0, 0) ' Red
- Message$ = Message$ + " and is busted"
- End If
- BjForm.ScoreBox(Who).Caption = Message$
-
- End Sub
-
- Sub DrawCard (Who%, WhichCard%, BackOrFace%)
-
- ' Draws a card
-
- WhichBox = Who * 10 + WhichCard - 1
- BjForm.CardBox(WhichBox).Visible = MhTrue
-
- If BackOrFace = FACE Then
- ' Copy previously loaded bitmap
- Ind = Hands(Who, WhichCard) ' Relative to one
- Card = CardValue(Who, WhichCard) - 1 ' 0-12
- Suit = Ind \ 13 + ((Ind Mod 13) = 0) ' 0-3
- W% = 74: H% = 99 ' Bit map spacing in big BMP
- X% = Card * W%
- Y% = Suit * H%
- W% = 72: H% = 97 ' Actual bitmap dimensions
- R% = BitBlt(BjForm.CardBox(WhichBox).Hdc, 0, 0, W%, H%, FDeck.FullDeck.Hdc, X%, Y%, SRCCOPY)
- BjForm.CardBox(WhichBox).Refresh
- Else
- ' Set up correct bitmap file to draw
- Select Case WhichDeck
- Case 0
- BjForm.CardBox(WhichBox).Picture = SelectForm.MirageDeck.Picture
- Case 1
- BjForm.CardBox(WhichBox).Picture = SelectForm.BlueSq.Picture
- Case 2
- BjForm.CardBox(WhichBox).Picture = SelectForm.RedSq.Picture
- Case 3
- BjForm.CardBox(WhichBox).Picture = SelectForm.RedDi.Picture
- Case 4
- BjForm.CardBox(WhichBox).Picture = SelectForm.BlueDi.Picture
- End Select
- End If
-
- End Sub
-
- Sub Hit (Who%)
-
- If BjForm.DoubleButton.Enabled Then
- BjForm.DoubleButton.Enabled = MhFalse
- End If
- If HowManyCards(Who) = 5 Then
- ' Move all the cards over for this hand (overlap them)
- ' and adjust the CardColumn array for this hand.
- ' Get difference (x) between first two cards
- Difference = BjForm.CardBox(1).Left - BjForm.CardBox(0).Left
- For I = 2 To 9
- WhichBox = Who * 10 + I - 1
- CardColumn(Who, I) = CardColumn(Who, I - 1) + Difference / 2
- BjForm.CardBox(WhichBox).Left = CardColumn(Who, I)
- Next
- R% = DoEvents() ' Update the screen
- End If
- HowManyCards(Who) = HowManyCards(Who) + 1
- Hands(Who, HowManyCards(Who)) = Cards(NextCard)
- NextCard = NextCard + 1
- CardsLeft = CardsLeft - 1
- DrawCard Who, HowManyCards(Who), FACE
-
- End Sub
-
- Sub SetUpForDeal ()
-
- BjForm.HandIndicator(PLAYER).Picture = LoadPicture()
- BjForm.HandIndicator(PLAYERB).Picture = LoadPicture()
- BjForm.BaseBetAmount.Enabled = MhTrue
- If BjForm.HitButton.Enabled Then
- BjForm.HitButton.Enabled = MhFalse
- End If
- If BjForm.DoubleButton.Enabled Then
- BjForm.DoubleButton.Enabled = MhFalse
- End If
- For I = 0 To 2
- BjForm.DeckButton(I).Enabled = MhTrue
- Next
- HandInPlay = MhFalse
- ActivePlayer = PLAYER
-
- End Sub
-
- Sub AnalyzeHand ()
-
- ' Show the dealer's hidden card
- DrawCard DEALER, 2, FACE
- ' and his hand value
- ShowValue DEALER
- If BjForm.HitButton.Enabled Then
- BjForm.HitButton.Enabled = MhFalse
- End If
- ' if neither hand is busted
- If (Busted(PLAYER) = 0 And Split = 0) Or (Split <> 0 And Busted(PLAYER) = 0) Or (Busted(PLAYERB) = 0 And Split <> 0) Then
- ' if only 1 hand and he doesn't have bj or
- ' 2 hands and one or other doesn't have bj
- If (PlayerHasBJ(PLAYER) = 0 And Split = 0) Or (Split <> 0 And PlayerHasBJ(PLAYER) = 0 Or PlayerHasBJ(PLAYERB) = 0) Then
- ' play for the dealer until >=17 or busts
- While Total(DEALER) <= 16
- Hit (DEALER)
- ShowValue (DEALER)
- Wend
- End If
- End If
- PlayerDone(DEALER) = 1
- For ActivePlayer = PLAYER To PLAYER + Split
- If Busted(ActivePlayer) Then
- Outcome(ActivePlayer) = LOSE
- ElseIf PlayerHasBJ(ActivePlayer) Then
- Outcome(ActivePlayer) = WINBJ
- ElseIf Busted(DEALER) Then
- Outcome(ActivePlayer) = WIN
- ElseIf Total(DEALER) > Total(ActivePlayer) Then
- Outcome(ActivePlayer) = LOSE
- ElseIf Total(DEALER) < Total(ActivePlayer) Then
- Outcome(ActivePlayer) = WIN
- Else
- Outcome(ActivePlayer) = PUSH
- End If
- ShowHandIndicator
- Select Case Outcome(ActivePlayer)
- Case WIN
- YouWin
- Case LOSE
- YouLose
- Case WINBJ
- YouWinBJ
- Case PUSH
- YouPush
- End Select
- Next
-
- SetUpForDeal
- If CardsLeft < CARDSINDECK / 4 Then
- MsgBox "The cards have been shuffled!", 64, "The house doesn't like counters!"
- Shuffle
- End If
- BjForm.StandButton.SetFocus
-
- End Sub
-
- Sub Deal ()
-
- ' Hide cards not in use
- For Who = DEALER To PLAYERB
- For WhichCard = 1 To HowManyCards(Who)
- WhichBox = Who * 10 + WhichCard - 1
- BjForm.CardBox(WhichBox).Picture = LoadPicture()
- BjForm.CardBox(WhichBox).Visible = MhFalse
- Next
- Next
-
- ' Make unused boxes invisible
- BjForm.ScoreBox(PLAYERB).Caption = ""
- BjForm.ScoreBox(DEALER).Caption = ""
- BjForm.PlayerBTextBox.Caption = ""
-
- ' Reset CardBox().Left in case a player had more than 5 cards
- For I = DEALER To PLAYERB
- For J = 2 To 5
- If CardColumn(I, J) <> MasterCardColumn(I, J) Then
- CardColumn(I, J) = MasterCardColumn(I, J)
- BjForm.CardBox(I * 10 + J - 1).Left = CardColumn(I, J)
- End If
- Next
- Next
-
- ' here's the actual deal
- Hands(PLAYER, 1) = Cards(NextCard)
- Hands(DEALER, 1) = Cards(NextCard + 1)
- Hands(PLAYER, 2) = Cards(NextCard + 2)
- Hands(DEALER, 2) = Cards(NextCard + 3)
- NextCard = NextCard + 4
- HowManyCards(DEALER) = 2
- HowManyCards(PLAYER) = 2
- DrawCard PLAYER, 1, FACE
- DrawCard PLAYER, 2, FACE
- DrawCard DEALER, 1, FACE
- DrawCard DEALER, 2, BACK
-
- CardsLeft = CardsLeft - 4
- HandInPlay = MhTrue
- DealerVisible = MhFalse
- Bet(PLAYER) = Bet(DEALER)
- Bet(PLAYERB) = Bet(DEALER)
-
- End Sub
-
- Sub ShowAdvanceAmount ()
-
- ' Place the advance amount in the text box
- BjForm.Amount(1).Caption = Str$(Advance&)
-
- End Sub
-
- Sub KeyDown (KeyCode As Integer, Shift As Integer)
-
- If KeyCode = HELPKEYCODE Then
- If Len(HelpFileName$) Then
- WinHelp BjForm.hWnd, HelpFileName$, HELP_INDEX, 0&
- Else
- MsgBox "Online help is not available inside the Visual Basic environment.", 64, "VB Bug!"
- End If
- Exit Sub
- End If
- ' This procedure acts on "quick keys" keypresses.
- ' If the appropriate field is enabled, then
- ' this proc simulates a mouse click on the field.
- Select Case KeyCode
- Case 66, 98'48 'B
- If BjForm.BaseBetAmount.Enabled Then
- BjForm.BaseBetAmount.SetFocus
- End If
- Case 49'2, 79 '1
- If BjForm.DeckButton(0).Enabled Then
- BjForm.DeckButton(0).Value = MhTrue
- End If
- Case 50'3, 80 ' 2
- If BjForm.DeckButton(0).Enabled Then
- BjForm.DeckButton(1).Value = MhTrue
- End If
- Case 54'7, 77 ' 6
- If BjForm.DeckButton(0).Enabled Then
- BjForm.DeckButton(2).Value = MhTrue
- End If
- Case 68, 100, 83, 115'31 'D/S
- If BjForm.StandButton.Enabled Then
- BjForm.StandButton.Value = MhTrue
- End If
- Case 72, 104'35 'H
- If BjForm.HitButton.Enabled Then
- BjForm.HitButton.Value = MhTrue
- End If
- Case 79, 111'11, 82'O
- If BjForm.DoubleButton.Enabled Then
- BjForm.DoubleButton.Value = MhTrue
- End If
- Case 80, 112'25 'P
- If BjForm.SplitButton.Enabled Then
- BjForm.SplitButton.Value = MhTrue
- End If
- Case 77, 109'50 'M
- If BjForm.AdvanceButton.Enabled Then
- BjForm.AdvanceButton.Value = MhTrue
- End If
- End Select
-
- End Sub
-
-