Author Topic: Card Game 21  (Read 2523 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
Card Game 21
« on: July 09, 2019, 09:22:52 pm »
Hi all. Today I worked all day on my really old card game of 21. You play against the computer.  I converted it from the ASIC 5.0 computer language (which was a lot like GW-BASIC with a tiny compiler). I made it much better with QB64. After testing it dozens of times lol I think there's no problems with it, but if you find any, please tell me. Thanks. I added ASCII card graphics as well as the ability for the computer to hold his cards without choosing one. It's usually who goes over 21 loses, like the original card game is, but if the computer holds his cards and you hold your cards, nobody gets to 21 and it's whoever has the highest number wins.  Unlike the original card game, you get to see the computer's cards and he gets to see yours. So, like many card games, it's all about chance. I also added colored text and fixed the graphic detail on the welcome page. This is a good example of how BASIC programs used to be made in the 80's and 90's. :)

Edit: Instructions updated and re-posted on July 10, 2019.

Code: QB64: [Select]
  1. 'This game was made using ASIC programming language, which is like GW-BASIC, in 1997.
  2. 'It was later updated for QB64 programming language on July 9, 2019.
  3.  
  4. _TITLE "Twenty-One"
  5. _SCREENMOVE 400, 200
  6. st:
  7. RESTORE design
  8. f = 0
  9. face = 0
  10. pl = 0
  11. t = 0
  12. tt = 0
  13. nn = 0
  14. n = 0
  15. c = 0
  16. cc = 0
  17. co = 0
  18. uquit = 0
  19. SCREEN _NEWIMAGE(800, 600, 12)
  20. FOR a = 1 TO 45
  21.     FOR b = 1 TO 13
  22.         READ co
  23.         LINE (b * 2, a * 2)-((b + 5) * 2, (a + 5) * 2), co, BF
  24.     NEXT b
  25. COLOR 10, 0
  26. LOCATE 10, 20
  27. PRINT "Card Game 21"
  28. LOCATE 13, 20
  29. PRINT "By Ken G."
  30. LOCATE 30, 20
  31. INPUT "Press enter to begin game.", a$
  32. COLOR 15, 0
  33. PRINT "                Instructions"
  34. PRINT "        Whoever is closest to 21 wins."
  35. PRINT "        But whoever goes over 21, loses."
  36. INPUT "        Press enter to begin.", beg$
  37. start:
  38. you:
  39. COLOR 15, 0
  40. IF pl = 0 THEN GOTO you2:
  41. IF pl = 1 THEN GOTO you2:
  42. PRINT "Do you want to pick up a card (Y/N)";
  43. INPUT ac$
  44. IF ac$ = "N" THEN uquit = 1: GOTO computer:
  45. IF ac$ = "n" THEN uquit = 1: GOTO computer:
  46. IF ac$ = "no" THEN uquit = 1: GOTO computer:
  47. IF ac$ = "NO" THEN uquit = 1: GOTO computer:
  48. IF ac$ = "No" THEN uquit = 1: GOTO computer:
  49. you2:
  50. COLOR 10, 0
  51. tt = tt + 1
  52. LOCATE 2, 20: PRINT "Round: "; tt
  53. pl = 1
  54. n = INT(RND * 10) + 1
  55. PRINT "Your card is a "
  56. f = n
  57. GOSUB cards:
  58. c = c + n
  59. PRINT "Your total is: ";
  60. IF c > 21 THEN GOTO uover:
  61. computer:
  62. COLOR 12, 0
  63. pl = 2
  64. t = t + 1
  65. IF cc = c AND uquit = 1 THEN GOTO tie:
  66. IF cc > 16 AND cc > c THEN
  67.     tt = tt + 1
  68.     PRINT
  69.     PRINT "Round: "; tt
  70.     PRINT
  71.     PRINT "Computer holds his cards."
  72.     IF uquit = 1 THEN GOTO total:
  73.     GOTO you:
  74. nn = INT(RND * 10) + 1
  75. f = nn
  76. PRINT "The Computer's card is a "
  77. GOSUB cards:
  78. cc = cc + nn
  79. PRINT "The Computer's total is: ";
  80. IF cc > 21 THEN GOTO uwin:
  81. IF uquit = 1 THEN
  82.     PRINT
  83.     INPUT "Press enter for computer's turn.", b$
  84.     GOTO computer:
  85. GOTO you:
  86. uover:
  87. COLOR 12, 0
  88. PRINT "You went over 21!"
  89. PRINT "The Computer automatically wins."
  90. FOR snd = 500 TO 100 STEP -10
  91.     SOUND snd, .5
  92. NEXT snd
  93. GOTO done:
  94. uwin:
  95. COLOR 10, 0
  96. PRINT "You Win!"
  97. FOR snd = 400 TO 600 STEP 10
  98.     SOUND snd, .5
  99. NEXT snd
  100. PRINT "Here is the score:"
  101. COLOR 12, 0
  102. PRINT "Computer: ";
  103. COLOR 10, 0
  104. PRINT "You: ";
  105.  
  106. GOTO done:
  107. total:
  108. COLOR 12, 0
  109. t = t - 1
  110. t$ = STR$(t)
  111. PRINT "Computer quits after " + t$ + " cards."
  112. PRINT "The Computer's total is: ";
  113. IF cc > c THEN GOTO cwins:
  114. IF cc < c THEN GOTO uwin:
  115. IF cc = c THEN GOTO tie:
  116. tie:
  117. COLOR 10, 0
  118. PRINT "You and Computer finishes with a Tie!"
  119. PRINT "Here is the score: "
  120. COLOR 12, 0
  121. PRINT "Computer: ";
  122. COLOR 10, 0
  123. PRINT "You: ";
  124. FOR snd = 400 TO 600 STEP 10
  125.     SOUND snd, .5
  126. NEXT snd
  127. GOTO done:
  128.  
  129. cwins:
  130. COLOR 12, 0
  131. FOR snd = 500 TO 100 STEP -10
  132.     SOUND snd, .5
  133. NEXT snd
  134. PRINT "Computer Wins."
  135. PRINT "Here is the score:"
  136. PRINT "Computer: ";
  137. COLOR 10, 0
  138. PRINT "You: ";
  139.  
  140.  
  141. done:
  142. COLOR 15, 0
  143. PRINT "Do you want to play again (Y/N)";
  144. INPUT ag$
  145. IF ag$ = "Y" OR ag$ = "y" THEN GOTO st:
  146.  
  147. cards:
  148. face = INT(RND * 4) + 1
  149. IF face = 1 THEN
  150.     c$ = CHR$(3)
  151. IF face = 2 THEN
  152.     c$ = CHR$(4)
  153. IF face = 3 THEN
  154.     c$ = CHR$(5)
  155. IF face = 4 THEN
  156.     c$ = CHR$(6)
  157. f$ = STR$(f)
  158. IF f < 10 THEN
  159.     PRINT "   ------"
  160.     PRINT "   |"; f$; "  |"
  161.     PRINT "   | "; c$; "  |"
  162.     PRINT "   |    |"
  163.     PRINT "   ------"
  164.  
  165. IF f = 10 THEN
  166.     PRINT "   ------"
  167.     PRINT "   |"; f; "|"
  168.     PRINT "   | "; c$; "  |"
  169.     PRINT "   |    |"
  170.     PRINT "   ------"
  171.  
  172.  
  173. design:
  174. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  175. DATA 1,1,1,1,2,2,1,2,2,1,1,1,1
  176. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  177. DATA 1,1,2,2,2,2,2,2,2,2,2,1,1
  178. DATA 1,1,2,2,2,2,2,2,2,2,2,1,1
  179. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  180. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  181. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  182. DATA 1,1,1,1,1,1,2,1,1,1,1,1,1
  183. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  184. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  185. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  186. DATA 1,1,1,1,1,1,2,1,1,1,1,1,1
  187. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  188. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  189. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  190. DATA 1,1,2,2,2,2,2,2,2,2,2,1,1
  191. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  192. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  193. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  194. DATA 1,1,1,1,1,1,2,1,1,1,1,1,1
  195. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  196. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  197. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  198. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  199. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  200. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  201. DATA 1,1,2,2,2,2,2,2,2,2,2,1,1
  202. DATA 1,1,2,2,2,2,2,2,2,2,2,1,1
  203. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  204. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  205. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  206. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  207. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  208. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  209. DATA 1,1,1,1,1,1,2,1,1,1,1,1,1
  210. DATA 1,1,1,1,1,2,2,2,1,1,1,1,1
  211. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  212. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  213. DATA 1,1,1,2,2,2,2,2,2,2,1,1,1
  214. DATA 1,1,2,2,1,1,2,1,1,2,2,1,1
  215. DATA 1,1,2,1,1,2,2,2,1,1,2,1,1
  216. DATA 1,1,1,1,2,2,2,2,2,1,1,1,1
  217. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  218. DATA 1,1,1,1,1,1,1,1,1,1,1,1,1
  219.  
  220.  
  221.  
« Last Edit: July 10, 2019, 02:36:18 pm by SierraKen »