21 Card Game (Not Blackjack) - SierraKen - 04-19-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 the POINT command.
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]](https://i.ibb.co/DfCbtcvB/21-Graphical-Card-Game-by-Sierra-Ken.png)
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
|