Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
21 Graphical Card Game
#6
Here is one, of course it's not the big fancy one I shared with Terry that Johnno and I did way back.
Found the zip on big fancy version: https://qb64phoenix.com/forum/showthread...2#pid33692

here is quickie
Code: (Select All)
Option _Explicit
_Title "minimum BlackJack" 'B+ started from Bluatigro Blackjack fix B+ mod at JB 2019-06-05
' "Cards": Suits are not displayed, X counts as 10 as do J, Q, K designate Jack, Queen, King. Ace designated by A is 1 | 11.
' Rules at this house:
' Since this is one on one, Player against Dealer, Player gets all his cards first and plays out hand.
' If Player is not busted, dealer will play to match or beat Player's hand or bust.
' With ties Dealer wins but a Player's Blackjack will immediately pay double.

DefInt A-Z
Randomize Timer
Const rank$ = "A23456789XJQK"
Dim Shared deck$(51)
Dim Shared deckIndex, playerTotal, dealerTotal, BJflag

Dim i, r, risk, points
Dim playAgain$
For i = 0 To 51 'create deck
    deck$(i) = Mid$(rank$ + rank$ + rank$ + rank$, i + 1, 1)
Next
points = 100
While points 'the main loop manages the points
    Cls '
    Print "For Blackjack, you have"; points; "points to risk."
    Input "Enter how many you wish to risk (0 quits) > "; risk
    If risk <= 0 Then Exit While
    If risk > points Then risk = points
    For i = 51 To 1 Step -1 'shuffle
        r = Int((i + 1) * Rnd)
        Swap deck$(i), deck$(r)
    Next i
    ''test BlackJack code
    'deck$(0) = "A"
    'deck$(1) = "J"
    Print
    playHand 1 'player
    If BJflag Then
        BJflag = 0
        points = points + 2 * risk
        Print "BlackJack! You win twice your risk."
        GoTo BJskip
    End If
    playHand 0 'dealer
    If playerTotal > 21 Or (playerTotal <= dealerTotal And dealerTotal < 22) Then
        Print "You loose.": points = points - risk
    Else
        Print "You win!": points = points + risk
    End If
    BJskip:
    Print
    If points Then
        Do
            playAgain$ = ""
            Input "Play again? Enter y for yes, n for no..."; playAgain$
        Loop Until playAgain$ = "y" Or playAgain$ = "n"
        If playAgain$ = "n" Then Exit While
    Else
        Print "Out of Points!"
    End If
Wend
Print "Goodbye!": End

Sub playHand (TFplayer)
    Dim i, index, total, addCard, ace
    Dim hand$(12), inp$
    index = 0
    If TFplayer Then
        deckIndex = 0
    Else
        If playerTotal > 21 Then Exit Sub 'player lost already
    End If
    For i = 1 To 2 'deal first 2 cards
        hand$(index) = deck$(deckIndex)
        index = index + 1
        deckIndex = deckIndex + 1
    Next
    Do
        If TFplayer Then Print "Player's hand: "; Else Print "Dealer's hand: ";
        total = 0
        For i = 0 To index - 1
            Print hand$(i); " ";
            total = total + cardValue(hand$(i))
            If hand$(i) = "A" Then ace = -1
        Next
        If ace And total < 12 Then total = total + 10
        Print
        If TFplayer Then Print "Player's total = "; Else Print "Dealer's total = ";
        Print total
        If TFplayer And total < 21 Then
            Input "Do you want another card ? (y for yes) "; inp$
            If inp$ = "y" Then addCard = -1 Else addCard = 0
        Else
            If TFplayer And total = 21 And index = 2 Then BJflag = -1: Exit Sub
            If total < 21 And total < playerTotal Then addCard = -1 Else addCard = 0
        End If
        If addCard Then
            hand$(index) = deck$(deckIndex)
            index = index + 1
            deckIndex = deckIndex + 1
        Else
            If TFplayer Then playerTotal = total Else dealerTotal = total
            Exit Do
        End If
    Loop
    Print
End Sub

Function cardValue (card$) ' I like bluatigro's method of getting card value
    If InStr(rank$, card$) > 10 Then cardValue = 10 Else cardValue = InStr(rank$, card$)
End Function


Attached Files Thumbnail(s)
   
  724  855  599  923  575  468  400  206  147  564  878  823  652  556 bxor cross forever
Reply


Messages In This Thread
21 Graphical Card Game - by SierraKen - 04-14-2025, 08:46 PM
RE: 21 Graphical Card Game - by SierraKen - 04-14-2025, 08:56 PM
RE: 21 Graphical Card Game - by SierraKen - 04-14-2025, 09:17 PM
RE: 21 Graphical Card Game - by SierraKen - 04-23-2025, 10:50 PM
RE: 21 Graphical Card Game - by bplus - 04-23-2025, 11:13 PM
RE: 21 Graphical Card Game - by bplus - 04-23-2025, 11:21 PM
RE: 21 Graphical Card Game - by SierraKen - 04-24-2025, 02:36 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  The Card Game Bowlman84 9 1,816 12-11-2024, 10:36 PM
Last Post: Bowlman84

Forum Jump:


Users browsing this thread: 1 Guest(s)