QB64 Phoenix Edition
21 Graphical Card Game - Printable Version

+- QB64 Phoenix Edition (https://qb64phoenix.com/forum)
+-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1)
+--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3)
+---- Forum: Games (https://qb64phoenix.com/forum/forumdisplay.php?fid=57)
+---- Thread: 21 Graphical Card Game (/showthread.php?tid=3615)



21 Graphical Card Game - SierraKen - 04-14-2025

This is the old fashioned simple version of the card game 21 where there is no betting, just hits to choose a card to try to get a
higher number than the computer. If you get past 21 you lose. You can play as many games as you wish and it tallies up how many 
games you won and the computer won, and also how many ties. 

There are no extra files needed for this, it makes the cards large by using POINT.  

Back in the 1990's I made a text version of this game with an online friend, who made ASCII graphic cards. This time I decided
to go all out and make animated shuffling of graphical cards. The cards themselves are not real looking because it would be
too much work to place each symbol on the card in the right place, and make half of them upside-down, like a real deck.
But I think you will have fun with this. This game took me longer than I expected (4 or 5 days) but it was a real challenge for me.

It is your turn when the game starts out. Have fun!



[Image: 21-Graphical-Card-Game-by-Sierra-Ken.png]




(Code deleted, scroll down for the newest update.)


RE: 21 Graphical Card Game - SierraKen - 04-14-2025

Here is a small update. You don't have to press Any Key as much now.

(Code deleted, scroll down for newest version.)


RE: 21 Graphical Card Game - SierraKen - 04-14-2025

I just made it a little harder with the computer hitting every time he is less than yours and not just stopping above a certain number.

Code: (Select All)

'21 Graphical Card Game by SierraKen
'April 14, 2025

'This is the old fashioned simple version of the card game 21 where there is no betting, just hits to choose a card to try to get a
'higher number than the computer. If you get past 21 you lose.
'Back in the 1990's I made a text version of this game with an online friend, who made ASCII graphic cards. This time I decided
'to go all out and make animated shuffling of graphical cards. The cards themselves are not real looking because it would be
'too much work to place each symbol on the card in the right place, and make half of them upside-down, like a real deck.
'But I think you will have fun with this. This game took me longer than I expected but it was a real challenge for me.
'It is your turn when the game starts out.

Dim Shared word As String
Dim cards As Single
Dim cards2 As Single
Screen _NewImage(800, 600, 32)
game:
Cls
you = 0
comp = 0
compturn = 0
urturn = 1
start = 1
start2 = 1
compstand = 0
youstand = 0
game = game + 1
Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF

_Title "21 Graphical Card Game by SierraKen"

Randomize Timer

Do

    _PrintString (350, 35), "Game:  " + Str$(game)
    _PrintString (350, 55), "Wins:  " + Str$(wins)
    _PrintString (350, 75), "Loses: " + Str$(loses)
    _PrintString (350, 95), "Ties:  " + Str$(ties)
    Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF

    If urturn = 1 Then _PrintString (350, 200), "Your Turn    "
    If compturn = 1 Then _PrintString (350, 200), "Computer Turn"

    If start = 1 Or start2 = 1 Then
        cards = Int(Rnd * 26) + 1
        card1 cards

        cards2 = Int(Rnd * 25) + 27
        card2 cards2
        GoSub begin
    End If
    _AutoDisplay
    Color _RGB32(255, 255, 255)
    _PrintString (350, 425), "Your Hand:    " + Str$(you)
    _PrintString (350, 445), "Computer Hand: " + Str$(comp)

    GoSub winner

    If urturn = 1 And youstand = 0 And compturn = 0 Then
        Color _RGB32(255, 255, 255)
        _PrintString (350, 465), "Hit (Y/N)?"
        Do
            hit$ = InKey$
            If hit$ = "y" Or hit$ = "Y" Then
                Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
                Line (0, 401)-(800, 600), _RGB32(0, 0, 0), BF
                cards = Int(Rnd * 52) + 1
                card1 cards
                GoSub begin
                Exit Do
            ElseIf hit$ = "n" Or hit$ = "N" Then
                youstand = 1
                Exit Do
            End If
        Loop
    End If

    going:
    If compturn = 1 And compstand = 0 And urturn = 0 Then
        If (comp < 17 And start = 1) Or (comp < you And start = 0) Then
            If start = 1 Then start = 0
            Color _RGB32(255, 255, 255)
            Line (0, 401)-(800, 600), _RGB32(0, 0, 0), BF
            Color _RGB32(255, 255, 255)
            _PrintString (350, 485), "Computer Hits  "
            cards = Int(Rnd * 52) + 1
            _Delay 4
            Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
            card1 cards
            GoSub begin
            _Delay 4
        Else
            Color _RGB32(255, 255, 255)
            _PrintString (350, 485), "Computer Stands"
            compstand = 1
        End If
    End If

    If youstand = 0 And compstand = 0 Then
        Color _RGB32(255, 255, 255)
        _PrintString (350, 505), "Press Any Key.                "
        Do: Loop Until InKey$ <> ""
        _PrintString (350, 485), "                                  "
        _PrintString (350, 505), "                                  "
    End If

    If compstand = 1 And youstand = 1 Then
        If comp > you Then
            _PrintString (350, 505), "You Lose                        "
            loses = loses + 1
            _PrintString (350, 35), "Game:  " + Str$(game)
            _PrintString (350, 55), "Wins:  " + Str$(wins)
            _PrintString (350, 75), "Loses: " + Str$(loses)
            _PrintString (350, 95), "Ties:  " + Str$(ties)
            Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
            GoTo playagain
        End If
        If comp < you Then
            For w = 1 To 5
                Color _RGB32(255, 0, 0)
                _PrintString (350, 505), "You Win!                        "
                _Delay .5
                Color _RGB32(255, 255, 255)
                _PrintString (350, 505), "You Win!                        "
                _Delay .5
            Next w
            wins = wins + 1
            _PrintString (350, 35), "Game:  " + Str$(game)
            _PrintString (350, 55), "Wins:  " + Str$(wins)
            _PrintString (350, 75), "Loses: " + Str$(loses)
            _PrintString (350, 95), "Ties:  " + Str$(ties)
            Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
            GoTo playagain
        End If
        If comp = you Then
            _PrintString (350, 505), "Tie Game!                        "
            ties = ties + 1
            _PrintString (350, 35), "Game:  " + Str$(game)
            _PrintString (350, 55), "Wins:  " + Str$(wins)
            _PrintString (350, 75), "Loses: " + Str$(loses)
            _PrintString (350, 95), "Ties:  " + Str$(ties)
            Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
            GoTo playagain
        End If
    End If

    If urturn = 1 Then
        urturn = 0
        compturn = 1
    Else
        urturn = 1
        compturn = 0
    End If

Loop

begin:
If start = 0 Then Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
_AutoDisplay
If compturn = 1 Then
    If (cards = 1 Or cards = 14) And comp < 11 Then comppick = 11
    If (cards = 1 Or cards = 14) And comp > 10 Then comppick = 1
    If (cards = 2 Or cards = 15) Then comppick = 2
    If (cards = 3 Or cards = 16) Then comppick = 3
    If (cards = 4 Or cards = 17) Then comppick = 4
    If (cards = 5 Or cards = 18) Then comppick = 5
    If (cards = 6 Or cards = 19) Then comppick = 6
    If (cards = 7 Or cards = 20) Then comppick = 7
    If (cards = 8 Or cards = 21) Then comppick = 8
    If (cards = 9 Or cards = 22) Then comppick = 9
    If (cards = 10 Or cards = 23) Then comppick = 10
    If (cards = 11 Or cards = 24) Then comppick = 10
    If (cards = 12 Or cards = 25) Then comppick = 10
    If (cards = 13 Or cards = 26) Then comppick = 10
    If (cards = 27 Or cards = 40) And comp < 11 Then comppick = 11
    If (cards = 27 Or cards = 40) And comp > 10 Then comppick = 1
    If (cards = 28 Or cards = 41) Then comppick = 2
    If (cards = 29 Or cards = 42) Then comppick = 3
    If (cards = 30 Or cards = 43) Then comppick = 4
    If (cards = 31 Or cards = 44) Then comppick = 5
    If (cards = 32 Or cards = 45) Then comppick = 6
    If (cards = 33 Or cards = 46) Then comppick = 7
    If (cards = 34 Or cards = 47) Then comppick = 8
    If (cards = 35 Or cards = 48) Then comppick = 9
    If (cards = 36 Or cards = 49) Then comppick = 10
    If (cards = 37 Or cards = 50) Then comppick = 10
    If (cards = 38 Or cards = 51) Then comppick = 10
    If (cards = 39 Or cards = 52) Then comppick = 10
    comp = comp + comppick
    Color _RGB32(255, 255, 255)
    _PrintString (350, 425), "Your Hand:    " + Str$(you)
    _PrintString (350, 445), "Computer Hand: " + Str$(comp)
    GoSub winner
End If

If compturn = 1 And start = 1 Then
    If (cards2 = 1 Or cards2 = 14) And comp < 11 Then comppick2 = 11
    If (cards2 = 1 Or cards2 = 14) And comp > 10 Then comppick2 = 1
    If (cards2 = 2 Or cards2 = 15) Then comppick2 = 2
    If (cards2 = 3 Or cards2 = 16) Then comppick2 = 3
    If (cards2 = 4 Or cards2 = 17) Then comppick2 = 4
    If (cards2 = 5 Or cards2 = 18) Then comppick2 = 5
    If (cards2 = 6 Or cards2 = 19) Then comppick2 = 6
    If (cards2 = 7 Or cards2 = 20) Then comppick2 = 7
    If (cards2 = 8 Or cards2 = 21) Then comppick2 = 8
    If (cards2 = 9 Or cards2 = 22) Then comppick2 = 9
    If (cards2 = 10 Or cards2 = 23) Then comppick2 = 10
    If (cards2 = 11 Or cards2 = 24) Then comppick2 = 10
    If (cards2 = 12 Or cards2 = 25) Then comppick2 = 10
    If (cards2 = 13 Or cards2 = 26) Then comppick2 = 10
    If (cards2 = 27 Or cards2 = 40) And comp < 11 Then comppick2 = 11
    If (cards2 = 27 Or cards2 = 40) And comp > 10 Then comppick2 = 1
    If (cards2 = 28 Or cards2 = 41) Then comppick2 = 2
    If (cards2 = 29 Or cards2 = 42) Then comppick2 = 3
    If (cards2 = 30 Or cards2 = 43) Then comppick2 = 4
    If (cards2 = 31 Or cards2 = 44) Then comppick2 = 5
    If (cards2 = 32 Or cards2 = 45) Then comppick2 = 6
    If (cards2 = 33 Or cards2 = 46) Then comppick2 = 7
    If (cards2 = 34 Or cards2 = 47) Then comppick2 = 8
    If (cards2 = 35 Or cards2 = 48) Then comppick2 = 9
    If (cards2 = 36 Or cards2 = 49) Then comppick2 = 10
    If (cards2 = 37 Or cards2 = 50) Then comppick2 = 10
    If (cards2 = 38 Or cards2 = 51) Then comppick2 = 10
    If (cards2 = 39 Or cards2 = 52) Then comppick2 = 10
    comp = comp + comppick2
    Color _RGB32(255, 255, 255)
    _PrintString (350, 425), "Your Hand:    " + Str$(you)
    _PrintString (350, 445), "Computer Hand: " + Str$(comp)
    GoSub winner
End If

If urturn = 1 Then

    If (cards = 1 Or cards = 14) And you < 11 Then urpick = 11
    If (cards = 1 Or cards = 14) And you > 10 Then urpick = 1
    If (cards = 2 Or cards = 15) Then urpick = 2
    If (cards = 3 Or cards = 16) Then urpick = 3
    If (cards = 4 Or cards = 17) Then urpick = 4
    If (cards = 5 Or cards = 18) Then urpick = 5
    If (cards = 6 Or cards = 19) Then urpick = 6
    If (cards = 7 Or cards = 20) Then urpick = 7
    If (cards = 8 Or cards = 21) Then urpick = 8
    If (cards = 9 Or cards = 22) Then urpick = 9
    If (cards = 10 Or cards = 23) Then urpick = 10
    If (cards = 11 Or cards = 24) Then urpick = 10
    If (cards = 12 Or cards = 25) Then urpick = 10
    If (cards = 13 Or cards = 26) Then urpick = 10
    If (cards = 27 Or cards = 40) And you < 11 Then urpick = 11
    If (cards = 27 Or cards = 40) And you > 10 Then urpick = 1
    If (cards = 28 Or cards = 41) Then urpick = 2
    If (cards = 29 Or cards = 42) Then urpick = 3
    If (cards = 30 Or cards = 43) Then urpick = 4
    If (cards = 31 Or cards = 44) Then urpick = 5
    If (cards = 32 Or cards = 45) Then urpick = 6
    If (cards = 33 Or cards = 46) Then urpick = 7
    If (cards = 34 Or cards = 47) Then urpick = 8
    If (cards = 35 Or cards = 48) Then urpick = 9
    If (cards = 36 Or cards = 49) Then urpick = 10
    If (cards = 37 Or cards = 50) Then urpick = 10
    If (cards = 38 Or cards = 51) Then urpick = 10
    If (cards = 39 Or cards = 52) Then urpick = 10
    you = you + urpick
    Color _RGB32(255, 255, 255)
    _PrintString (350, 425), "Your Hand:    " + Str$(you)
    _PrintString (350, 445), "Computer Hand: " + Str$(comp)
    GoSub winner
End If

If urturn = 1 And start2 = 1 Then
    If (cards2 = 1 Or cards2 = 14) And you < 11 Then urpick2 = 11
    If (cards2 = 1 Or cards2 = 14) And you > 10 Then urpick2 = 1
    If (cards2 = 2 Or cards2 = 15) Then urpick2 = 2
    If (cards2 = 3 Or cards2 = 16) Then urpick2 = 3
    If (cards2 = 4 Or cards2 = 17) Then urpick2 = 4
    If (cards2 = 5 Or cards2 = 18) Then urpick2 = 5
    If (cards2 = 6 Or cards2 = 19) Then urpick2 = 6
    If (cards2 = 7 Or cards2 = 20) Then urpick2 = 7
    If (cards2 = 8 Or cards2 = 21) Then urpick2 = 8
    If (cards2 = 9 Or cards2 = 22) Then urpick2 = 9
    If (cards2 = 10 Or cards2 = 23) Then urpick2 = 10
    If (cards2 = 11 Or cards2 = 24) Then urpick2 = 10
    If (cards2 = 12 Or cards2 = 25) Then urpick2 = 10
    If (cards2 = 13 Or cards2 = 26) Then urpick2 = 10
    If (cards2 = 27 Or cards2 = 40) And you < 11 Then urpick2 = 11
    If (cards2 = 27 Or cards2 = 40) And you > 10 Then urpick2 = 1
    If (cards2 = 28 Or cards2 = 41) Then urpick2 = 2
    If (cards2 = 29 Or cards2 = 42) Then urpick2 = 3
    If (cards2 = 30 Or cards2 = 43) Then urpick2 = 4
    If (cards2 = 31 Or cards2 = 44) Then urpick2 = 5
    If (cards2 = 32 Or cards2 = 45) Then urpick2 = 6
    If (cards2 = 33 Or cards2 = 46) Then urpick2 = 7
    If (cards2 = 34 Or cards2 = 47) Then urpick2 = 8
    If (cards2 = 35 Or cards2 = 48) Then urpick2 = 9
    If (cards2 = 36 Or cards2 = 49) Then urpick2 = 10
    If (cards2 = 37 Or cards2 = 50) Then urpick2 = 10
    If (cards2 = 38 Or cards2 = 51) Then urpick2 = 10
    If (cards2 = 39 Or cards2 = 52) Then urpick2 = 10
    you = you + urpick2
    start2 = 0
    Color _RGB32(255, 255, 255)
    _PrintString (350, 425), "Your Hand:    " + Str$(you)
    _PrintString (350, 445), "Computer Hand: " + Str$(comp)
    GoSub winner
End If

Return

winner:
If you > 21 Or comp = 21 Then
    _PrintString (350, 505), "You Lose                        "
    loses = loses + 1
    _PrintString (350, 35), "Game:  " + Str$(game)
    _PrintString (350, 55), "Wins:  " + Str$(wins)
    _PrintString (350, 75), "Loses: " + Str$(loses)
    _PrintString (350, 95), "Ties:  " + Str$(ties)
    Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
    GoTo playagain
End If
If comp > 21 Or you = 21 Then
    For w = 1 To 5
        Color _RGB32(255, 0, 0)
        _PrintString (350, 505), "You Win!                        "
        _Delay .5
        Color _RGB32(255, 255, 255)
        _PrintString (350, 505), "You Win!                        "
        _Delay .5
    Next w
    wins = wins + 1
    _PrintString (350, 35), "Game:  " + Str$(game)
    _PrintString (350, 55), "Wins:  " + Str$(wins)
    _PrintString (350, 75), "Loses: " + Str$(loses)
    _PrintString (350, 95), "Ties:  " + Str$(ties)
    Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
    GoTo playagain
End If
If comp = 21 And you = 21 Then
    Locate 30, 5: Print "Tie Game!                      "
    ties = ties + 1
    _PrintString (350, 35), "Game:  " + Str$(game)
    _PrintString (350, 55), "Wins:  " + Str$(wins)
    _PrintString (350, 75), "Loses: " + Str$(loses)
    _PrintString (350, 95), "Ties:  " + Str$(ties)
    Line (25, 0)-(775, 35), _RGB32(0, 0, 0), BF
    GoTo playagain
End If
Return

playagain:
_PrintString (350, 525), "Play Again (Y/N)?"
Do
    ag$ = InKey$
    If ag$ = "y" Or ag$ = "Y" Then GoTo game
    If ag$ = "n" Or ag$ = "N" Then End
Loop

End


Sub card1 (cards)
    Dim col As Long
    For face = 1 To 4
        If face = 1 Or face = 2 Then col = _RGB32(255, 0, 0)
        If face = 3 Or face = 4 Then col = _RGB32(0, 0, 0)
        If face = 1 Then f$ = Chr$(3)
        If face = 2 Then f$ = Chr$(4)
        If face = 3 Then f$ = Chr$(5)
        If face = 4 Then f$ = Chr$(6)
        word2$ = f$
        word = "A"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word
        Locate 2, 32
        Print word2$
        Color _RGB32(255, 0, 0)
        first = -475
        If cc < cards Then
            Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        Color _RGB32(5, 5, 5)
        For c = 2 To 10
            word2$ = f$
            word$ = Str$(c)
            Locate 1, 31
            Color _RGB32(5, 5, 5)
            Print word$
            Locate 2, 32
            Print word2$
            first = -475
            If cc < cards Then
                Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
                make first, col
            Else
                GoTo playing
            End If
            cc = cc + 1
        Next c
        word2$ = f$
        word$ = "J"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word$
        Locate 2, 32
        Print word2$
        first = -475
        If cc < cards Then
            Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        word2$ = f$
        word$ = "Q"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word$
        Locate 2, 32
        Print word2$
        first = -475
        If cc < cards Then
            Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        word2$ = f$
        word$ = "K"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word$
        Locate 2, 32
        Print word2$
        first = -475
        If cc < cards Then
            Line (25, 35)-(300, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
    Next face

    playing:
    cc = 0
End Sub

Sub card2 (cards2)
    Dim col As Long
    For face = 1 To 4
        If face = 1 Or face = 2 Then col = _RGB32(255, 0, 0)
        If face = 3 Or face = 4 Then col = _RGB32(0, 0, 0)
        If face = 1 Then f$ = Chr$(3)
        If face = 2 Then f$ = Chr$(4)
        If face = 3 Then f$ = Chr$(5)
        If face = 4 Then f$ = Chr$(6)
        word2$ = f$
        word = "A"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word$
        Locate 2, 32
        Print word2$
        first = 0
        If cc < cards2 Then
            Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        Color _RGB32(5, 5, 5)
        For c = 2 To 10
            word2$ = f$
            word = Str$(c)
            Locate 1, 31
            Color _RGB32(5, 5, 5)
            Print word
            Locate 2, 32
            Print word2$
            first = 0
            If cc < cards2 Then
                Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
                make first, col
            Else
                GoTo playing
            End If
            cc = cc + 1
        Next c
        word2$ = f$
        word$ = "J"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word
        Locate 2, 32
        Print word2$
        first = 0
        If cc < cards2 Then
            Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        word2$ = f$
        word = "Q"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word$
        Locate 2, 32
        Print word2$
        first = 0
        If cc < cards2 Then
            Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
        word2$ = f$
        word = "K"
        Locate 1, 32
        Color _RGB32(5, 5, 5)
        Print word
        Locate 2, 32
        Print word2$
        first = 0
        If cc < cards2 Then
            Line (500, 35)-(775, 400), _RGB32(254, 254, 254), BF
            make first, col
        Else
            GoTo playing
        End If
        cc = cc + 1
    Next face

    playing:
    cc = 0
End Sub

Sub make (first, col)

    letters = Len(word)
    If letters > 1 Then
        letters = 2
    Else
        letters = 1
    End If

    If Len(word) = 3 Then
        num = 30
        letters = 2
    Else
        num = 0
        letters = 1
    End If
    ll = (letters * 8) - 2
    For I = 248 To 248 + ll Step .15
        For j = 0 To 30 Step .15
            If Point(I, j) = _RGB32(5, 5, 5) Then
                Line ((I - 196) * 4 + 300 + first, j * 4 + 50)-((I - 196) * 4 + 2 + 300 + first, j * 4 + 52), col, BF
                Line ((I - 196) * 4 + (525) - num + first, j * 4 + 270)-((I - 196) * 4 + 2 + 525 - num + first, j * 4 + 272), col, BF
            Else
                PSet ((I - 196) * 4 + 300 + first, j * 4 + 50), _RGB32(254, 254, 254)
                PSet ((I - 196) * 4 + (525) - num + first, j * 4 + 270), _RGB32(254, 254, 254)
            End If
        Next j
    Next I

    Locate 1, 31: Print "    "
    Locate 2, 31: Print "    "
    _Display
    _Delay .05
End Sub






RE: 21 Graphical Card Game - SierraKen - 04-23-2025

@bplus did you get a chance to try this little game? I understand if you don't like it, it's a bit odd in the way it switches back and forth to the computer. But I can take some criticism. Smile The game has been parked here for a week with no replies, so I'm guessing not many people like it. But I understand. At least I figured out how to make generic-looking cards. Smile


RE: 21 Graphical Card Game - bplus - 04-23-2025

When I tried it, it would only hit me once as I recall. I was not impressed but I like your drawn cards Smile

500 LOC seems like allot for this game... I have a 21 game around somewhere.


RE: 21 Graphical Card Game - bplus - 04-23-2025

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.php?tid=3632&pid=33692#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



RE: 21 Graphical Card Game - SierraKen - 04-24-2025

Awesome Bplus! I like the simplicity.