Author Topic: Tic-Tac-Toe  (Read 5895 times)

0 Members and 1 Guest are viewing this topic.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Tic-Tac-Toe
« on: January 29, 2021, 12:19:05 am »
In August 2019 I made this Tic-Tac-Toe game which graphically uses X's and O's and the # grid. It also uses the mouse. What I didn't do back then is make it so the computer chooses who goes first. I think I just was overwhelmed a bit with the game and I thought it might not be possible. Well it's easier than I thought. So here it is, where the computer chooses who goes first. It adds another dynamic to the game and makes you think more. It's a 50/50 chance that you or the computer will go first. This is one of my better games I've made in my opinion. Enjoy :).

Code: QB64: [Select]
  1. 'I've wanted to make this game for decades and finally am able to!
  2. 'This game was made on August 14, 2019 by SierraKen.
  3. 'This is Freeware.
  4. 'Jan. 28, 2021 update to choose at random who goes first.
  5.  
  6. DIM a(10), b(10)
  7. _TITLE "Tic-Tac-Toe     by SierraKen"
  8. SCREEN _NEWIMAGE(600, 480, 32)
  9. LOCATE 10, 32: PRINT "-"
  10. LOCATE 10, 38: PRINT "-"
  11. FOR tic = 1 TO 10
  12.     LOCATE tic, 28: PRINT "TIC"
  13.     _DELAY .2
  14.     LOCATE tic, 28: PRINT "   "
  15. NEXT tic
  16. LOCATE 10, 28: PRINT "TIC"
  17.  
  18. FOR tac = 20 TO 10 STEP -1
  19.     LOCATE tac, 34: PRINT "TAC"
  20.     _DELAY .2
  21.     LOCATE tac, 34: PRINT "   "
  22. NEXT tac
  23. LOCATE 10, 34: PRINT "TAC"
  24.  
  25. FOR toe = 1 TO 10
  26.     LOCATE toe, 40: PRINT "TOE"
  27.     _DELAY .2
  28.     LOCATE toe, 40: PRINT "   "
  29. NEXT toe
  30. LOCATE 10, 40: PRINT "TOE"
  31.  
  32. PRINT "                            By  SierraKen"
  33. PRINT "     Play against the computer in this classic game of Tic-Tac-Toe."
  34. PRINT "                    Whoever gets 3 in a row wins."
  35. PRINT "                  Choose a sqace by using your mouse."
  36. PRINT "                   Computer chooses who goes first."
  37. PRINT "                        Press Space Bar To Begin."
  38. st:
  39. sta$ = INKEY$
  40. IF sta$ = "" THEN GOTO st:
  41. IF sta$ = " " THEN CLS: GOTO start:
  42. GOTO st:
  43. start:
  44. ag$ = ""
  45. t = 0
  46. turn = 0
  47. comp = 0
  48.  
  49. 'Draw Grid
  50. 'Vertical Lines
  51. LINE (220, 100)-(240, 410), _RGB32(255, 255, 255), BF
  52. LINE (360, 100)-(380, 410), _RGB32(255, 255, 255), BF
  53. 'Horizontal Lines
  54. LINE (90, 185)-(510, 205), _RGB32(255, 255, 255), BF
  55. LINE (90, 305)-(510, 325), _RGB32(255, 255, 255), BF
  56.  
  57. whosfirst:
  58. first = INT(RND * 2) + 1
  59. IF first = 1 THEN GOTO computerchoice:
  60.  
  61. Go:
  62. a$ = INKEY$
  63. IF a$ = CHR$(27) THEN END
  64. mouseWheel = 0
  65.     mouseX = _MOUSEX
  66.     mouseY = _MOUSEY
  67.     mouseLeftButton = _MOUSEBUTTON(1)
  68.     mouseRightButton = _MOUSEBUTTON(2)
  69.     mouseMiddleButton = _MOUSEBUTTON(3)
  70.     mouseWheel = mouseWheel + _MOUSEWHEEL
  71.  
  72. IF mouseLeftButton = -1 THEN
  73.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 93 AND mouseY < 182 AND b(1) = 0 AND a(1) = 0 AND t = 0 THEN GOSUB space1:
  74.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 93 AND mouseY < 182 AND b(2) = 0 AND a(2) = 0 AND t = 0 THEN GOSUB space2:
  75.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 93 AND mouseY < 182 AND b(3) = 0 AND a(3) = 0 AND t = 0 THEN GOSUB space3:
  76.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 205 AND mouseY < 302 AND b(4) = 0 AND a(4) = 0 AND t = 0 THEN GOSUB space4:
  77.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 205 AND mouseY < 302 AND b(5) = 0 AND a(5) = 0 AND t = 0 THEN GOSUB space5:
  78.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 205 AND mouseY < 302 AND b(6) = 0 AND a(6) = 0 AND t = 0 THEN GOSUB space6:
  79.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 326 AND mouseY < 410 AND b(7) = 0 AND a(7) = 0 AND t = 0 THEN GOSUB space7:
  80.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 326 AND mouseY < 410 AND b(8) = 0 AND a(8) = 0 AND t = 0 THEN GOSUB space8:
  81.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 326 AND mouseY < 410 AND b(9) = 0 AND a(9) = 0 AND t = 0 THEN GOSUB space9:
  82.  
  83. IF mouseLeftButton = -1 AND ending = 1 THEN GOTO start:
  84. IF mouseRightButton = -1 AND ending = 1 THEN END
  85.  
  86. IF t = 1 THEN GOSUB computer:
  87.  
  88. GOTO Go:
  89.  
  90. checkwin:
  91. 'Check to see if you won.
  92. IF a(1) = 1 AND a(2) = 1 AND a(3) = 1 THEN GOTO won:
  93. IF a(4) = 1 AND a(5) = 1 AND a(6) = 1 THEN GOTO won:
  94. IF a(7) = 1 AND a(8) = 1 AND a(9) = 1 THEN GOTO won
  95. IF a(1) = 1 AND a(4) = 1 AND a(7) = 1 THEN GOTO won:
  96. IF a(2) = 1 AND a(5) = 1 AND a(8) = 1 THEN GOTO won:
  97. IF a(3) = 1 AND a(6) = 1 AND a(9) = 1 THEN GOTO won:
  98. IF a(1) = 1 AND a(5) = 1 AND a(9) = 1 THEN GOTO won:
  99. IF a(3) = 1 AND a(5) = 1 AND a(7) = 1 THEN GOTO won:
  100. turn = turn + 1
  101. SOUND 100, .25
  102. IF turn = 9 THEN GOTO catsgame:
  103. GOTO Go:
  104. won:
  105. FOR snd = 300 TO 900 STEP 50
  106.     SOUND snd, .5
  107. NEXT snd
  108. FOR tt = 1 TO 9
  109.     a(tt) = 0
  110.     b(tt) = 0
  111. NEXT tt
  112. t = 0
  113. LOCATE 2, 32: PRINT "Y O U   W O N ! !"
  114. LOCATE 4, 27: PRINT "Press Space Bar to play again."
  115. LOCATE 6, 27: PRINT "Or any other key to end."
  116. again:
  117. ag$ = INKEY$
  118. IF ag$ = "" THEN GOTO again:
  119. IF ag$ <> " " THEN END
  120. IF ag$ = " " THEN CLS: GOTO start:
  121. GOTO again:
  122.  
  123. computer:
  124.  
  125. 'Check to win.
  126. 'Last space gone.
  127. IF b(1) = 1 AND b(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  128. IF b(4) = 1 AND b(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  129. IF b(7) = 1 AND b(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  130. IF b(1) = 1 AND b(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  131. IF b(2) = 1 AND b(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  132. IF b(3) = 1 AND b(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  133. IF b(1) = 1 AND b(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  134. IF b(3) = 1 AND b(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  135. 'First space gone.
  136. IF b(2) = 1 AND b(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  137. IF b(5) = 1 AND b(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  138. IF b(8) = 1 AND b(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  139. IF b(4) = 1 AND b(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  140. IF b(5) = 1 AND b(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  141. IF b(6) = 1 AND b(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  142. IF b(5) = 1 AND b(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  143. IF b(7) = 1 AND b(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  144. 'Middle space gone.
  145. IF b(1) = 1 AND b(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  146. IF b(4) = 1 AND b(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  147. IF b(7) = 1 AND b(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  148. IF b(1) = 1 AND b(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  149. IF b(2) = 1 AND b(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  150. IF b(3) = 1 AND b(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  151. IF b(1) = 1 AND b(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  152. IF b(3) = 1 AND b(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  153.  
  154. 'Check to block.
  155. 'Last space gone.
  156. IF a(1) = 1 AND a(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  157. IF a(4) = 1 AND a(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  158. IF a(7) = 1 AND a(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  159. IF a(1) = 1 AND a(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  160. IF a(2) = 1 AND a(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  161. IF a(3) = 1 AND a(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  162. IF a(1) = 1 AND a(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  163. IF a(3) = 1 AND a(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  164. 'First space gone.
  165. IF a(2) = 1 AND a(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  166. IF a(5) = 1 AND a(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  167. IF a(8) = 1 AND a(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  168. IF a(4) = 1 AND a(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  169. IF a(5) = 1 AND a(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  170. IF a(6) = 1 AND a(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  171. IF a(5) = 1 AND a(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  172. IF a(7) = 1 AND a(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  173. 'Middle space gone.
  174. IF a(1) = 1 AND a(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  175. IF a(4) = 1 AND a(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  176. IF a(7) = 1 AND a(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  177. IF a(1) = 1 AND a(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  178. IF a(2) = 1 AND a(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  179. IF a(3) = 1 AND a(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  180. IF a(1) = 1 AND a(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  181. IF a(3) = 1 AND a(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  182.  
  183. 'Computer decides a random space.
  184. computerchoice:
  185. comp = INT(RND * 9) + 1
  186. IF b(comp) = 1 THEN GOTO computerchoice:
  187. IF a(comp) = 1 THEN GOTO computerchoice:
  188. IF comp = 1 THEN GOTO compspace1:
  189. IF comp = 2 THEN GOTO compspace2:
  190. IF comp = 3 THEN GOTO compspace3:
  191. IF comp = 4 THEN GOTO compspace4:
  192. IF comp = 5 THEN GOTO compspace5:
  193. IF comp = 6 THEN GOTO compspace6:
  194. IF comp = 7 THEN GOTO compspace7:
  195. IF comp = 8 THEN GOTO compspace8:
  196. IF comp = 9 THEN GOTO compspace9:
  197.  
  198. 'Cat's Game
  199. catsgame:
  200. FOR snd = 400 TO 300 STEP -25
  201.     SOUND snd, .5
  202. NEXT snd
  203. FOR tt = 1 TO 9
  204.     a(tt) = 0
  205.     b(tt) = 0
  206. NEXT tt
  207. t = 0
  208. LOCATE 2, 27: PRINT "Cat's Game - No Winners"
  209. LOCATE 4, 27: PRINT "Press Space Bar to play again."
  210. LOCATE 6, 27: PRINT "Or any other key to end."
  211. again2:
  212. ag$ = INKEY$
  213. IF ag$ = "" THEN GOTO again:
  214. IF ag$ <> " " THEN END
  215. IF ag$ = " " THEN CLS: GOTO start:
  216. GOTO again2:
  217.  
  218. 'Check to see if the computer won.
  219. check:
  220. IF b(1) = 1 AND b(2) = 1 AND b(3) = 1 THEN GOTO compwon:
  221. IF b(4) = 1 AND b(5) = 1 AND b(6) = 1 THEN GOTO compwon:
  222. IF b(7) = 1 AND b(8) = 1 AND b(9) = 1 THEN GOTO compwon
  223. IF b(1) = 1 AND b(4) = 1 AND b(7) = 1 THEN GOTO compwon:
  224. IF b(2) = 1 AND b(5) = 1 AND b(8) = 1 THEN GOTO compwon:
  225. IF b(3) = 1 AND b(6) = 1 AND b(9) = 1 THEN GOTO compwon:
  226. IF b(1) = 1 AND b(5) = 1 AND b(9) = 1 THEN GOTO compwon:
  227. IF b(3) = 1 AND b(5) = 1 AND b(7) = 1 THEN GOTO compwon:
  228. turn = turn + 1
  229. IF turn = 9 THEN GOTO catsgame:
  230. t = 0
  231. GOTO Go:
  232.  
  233. compwon:
  234. FOR snd = 900 TO 300 STEP -50
  235.     SOUND snd, .5
  236. NEXT snd
  237. FOR tt = 1 TO 9
  238.     a(tt) = 0
  239.     b(tt) = 0
  240. NEXT tt
  241. t = 0
  242. LOCATE 2, 33: PRINT "Computer Wins"
  243. LOCATE 4, 27: PRINT "Press Space Bar to play again."
  244. LOCATE 6, 27: PRINT "Or any other key to end."
  245. again3:
  246. ag$ = INKEY$
  247. IF ag$ = "" THEN GOTO again:
  248. IF ag$ <> " " THEN END
  249. IF ag$ = " " THEN CLS: GOTO start:
  250. GOTO again3:
  251.  
  252. 'This part draws the computer's circle.
  253. compspace1:
  254. t = 0
  255. b(1) = 1
  256. FOR s = .25 TO 5 STEP .25
  257.     CIRCLE (160, 137), 40 - s, _RGB32(255, 0, 0)
  258. GOTO check:
  259. compspace2:
  260. t = 0
  261. b(2) = 1
  262. FOR s = .25 TO 5 STEP .25
  263.     CIRCLE (300, 137), 40 - s, _RGB32(255, 0, 0)
  264. GOTO check:
  265. compspace3:
  266. t = 0
  267. b(3) = 1
  268. FOR s = .25 TO 5 STEP .25
  269.     CIRCLE (440, 137), 40 - s, _RGB32(255, 0, 0)
  270. GOTO check:
  271. compspace4:
  272. t = 0
  273. b(4) = 1
  274. FOR s = .25 TO 5 STEP .25
  275.     CIRCLE (160, 257), 40 - s, _RGB32(255, 0, 0)
  276. GOTO check:
  277. compspace5:
  278. t = 0
  279. b(5) = 1
  280. FOR s = .25 TO 5 STEP .25
  281.     CIRCLE (300, 257), 40 - s, _RGB32(255, 0, 0)
  282. GOTO check:
  283. compspace6:
  284. t = 0
  285. b(6) = 1
  286. FOR s = .25 TO 5 STEP .25
  287.     CIRCLE (440, 257), 40 - s, _RGB32(255, 0, 0)
  288. GOTO check:
  289. compspace7:
  290. t = 0
  291. b(7) = 1
  292. FOR s = .25 TO 5 STEP .25
  293.     CIRCLE (160, 372), 40 - s, _RGB32(255, 0, 0)
  294. GOTO check:
  295. compspace8:
  296. t = 0
  297. b(8) = 1
  298. FOR s = .25 TO 5 STEP .25
  299.     CIRCLE (300, 372), 40 - s, _RGB32(255, 0, 0)
  300. GOTO check:
  301. compspace9:
  302. t = 0
  303. b(9) = 1
  304. FOR s = .25 TO 5 STEP .25
  305.     CIRCLE (440, 372), 40 - s, _RGB32(255, 0, 0)
  306. GOTO check:
  307. 'This last part draws your X.
  308. space1:
  309. a(1) = 1
  310. FOR s = .25 TO 5 STEP .25
  311.     LINE (120 + s, 120)-(200 + s, 165), _RGB32(0, 255, 0)
  312.     LINE (200 + s, 120)-(120 + s, 165), _RGB32(0, 255, 0)
  313. t = 1
  314. GOTO checkwin:
  315. space2:
  316. a(2) = 1
  317. FOR s = .25 TO 5 STEP .25
  318.     LINE (260 + s, 120)-(340 + s, 165), _RGB32(0, 255, 0)
  319.     LINE (340 + s, 120)-(260 + s, 165), _RGB32(0, 255, 0)
  320. t = 1
  321. GOTO checkwin:
  322. space3:
  323. a(3) = 1
  324. FOR s = .25 TO 5 STEP .25
  325.     LINE (400 + s, 120)-(480 + s, 165), _RGB32(0, 255, 0)
  326.     LINE (480 + s, 120)-(400 + s, 165), _RGB32(0, 255, 0)
  327. t = 1
  328. GOTO checkwin:
  329. space4:
  330. a(4) = 1
  331. FOR s = .25 TO 5 STEP .25
  332.     LINE (120 + s, 235)-(200 + s, 280), _RGB32(0, 255, 0)
  333.     LINE (200 + s, 235)-(120 + s, 280), _RGB32(0, 255, 0)
  334. t = 1
  335. GOTO checkwin:
  336. space5:
  337. a(5) = 1
  338. FOR s = .25 TO 5 STEP .25
  339.     LINE (260 + s, 235)-(340 + s, 280), _RGB32(0, 255, 0)
  340.     LINE (340 + s, 235)-(260 + s, 280), _RGB32(0, 255, 0)
  341. t = 1
  342. GOTO checkwin:
  343. space6:
  344. a(6) = 1
  345. FOR s = .25 TO 5 STEP .25
  346.     LINE (400 + s, 235)-(480 + s, 280), _RGB32(0, 255, 0)
  347.     LINE (480 + s, 235)-(400 + s, 280), _RGB32(0, 255, 0)
  348. t = 1
  349. GOTO checkwin:
  350. space7:
  351. a(7) = 1
  352. FOR s = .25 TO 5 STEP .25
  353.     LINE (120 + s, 350)-(200 + s, 395), _RGB32(0, 255, 0)
  354.     LINE (200 + s, 350)-(120 + s, 395), _RGB32(0, 255, 0)
  355. t = 1
  356. GOTO checkwin:
  357. space8:
  358. a(8) = 1
  359. FOR s = .25 TO 5 STEP .25
  360.     LINE (260 + s, 350)-(340 + s, 395), _RGB32(0, 255, 0)
  361.     LINE (340 + s, 350)-(260 + s, 395), _RGB32(0, 255, 0)
  362. t = 1
  363. GOTO checkwin:
  364. space9:
  365. a(9) = 1
  366. FOR s = .25 TO 5 STEP .25
  367.     LINE (400 + s, 350)-(480 + s, 395), _RGB32(0, 255, 0)
  368.     LINE (480 + s, 350)-(400 + s, 395), _RGB32(0, 255, 0)
  369. t = 1
  370. GOTO checkwin:
  371.  
TicTacToe.jpg
* TicTacToe.jpg (Filesize: 30.84 KB, Dimensions: 601x504, Views: 140)
« Last Edit: January 29, 2021, 12:28:45 am by SierraKen »

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Tic-Tac-Toe
« Reply #1 on: January 29, 2021, 12:27:24 am »
The intro is adorable!

Sounds go accordingly with win/loss, opponent AI is there, but not impossible to beat - I approve!
You're not done when it works, you're done when it's right.

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #2 on: January 29, 2021, 12:30:13 am »
Thanks Static! Well, I just realized that the game has no _LIMIT commands and was using around 14% of my CPU. So I just added 2 LIMIT commands (one at the start and one in the main loop). So I just updated the code on the first post. Please update your code if you have gotten it already. Sorry about that!

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #3 on: January 30, 2021, 02:03:15 am »
I just added these to the game:
Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game, added text colors.


Code: QB64: [Select]
  1. 'I've wanted to make this game for decades and finally am able to!
  2. 'This game was made on August 14, 2019 by SierraKen.
  3. 'This is Freeware.
  4. 'Jan. 28, 2021 update: Choose at random who goes first.
  5. 'Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game,
  6. 'and added text colors.
  7.  
  8. DIM a(10), b(10)
  9. _TITLE "Tic-Tac-Toe     by SierraKen"
  10. SCREEN _NEWIMAGE(600, 480, 32)
  11. LOCATE 10, 34: PRINT "-"
  12. LOCATE 10, 40: PRINT "-"
  13. FOR tic = 1 TO 10
  14.     LOCATE tic, 30: PRINT "TIC"
  15.     _DELAY .1
  16.     LOCATE tic, 30: PRINT "   "
  17. NEXT tic
  18. LOCATE 10, 30: PRINT "TIC"
  19.  
  20. FOR tac = 20 TO 10 STEP -1
  21.     LOCATE tac, 36: PRINT "TAC"
  22.     _DELAY .1
  23.     LOCATE tac, 36: PRINT "   "
  24. NEXT tac
  25. LOCATE 10, 36: PRINT "TAC"
  26.  
  27. FOR toe = 1 TO 10
  28.     LOCATE toe, 42: PRINT "TOE"
  29.     _DELAY .1
  30.     LOCATE toe, 42: PRINT "   "
  31. NEXT toe
  32. LOCATE 10, 42: PRINT "TOE"
  33.  
  34. PRINT "                              By  SierraKen"
  35. PRINT "       Play against the computer in this classic game of Tic-Tac-Toe."
  36. PRINT "                      Whoever gets 3 in a row wins."
  37. PRINT "                    Choose a sqace by using your mouse."
  38. PRINT "                     Computer chooses who goes first."
  39.  
  40. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  41. _PRINTSTRING (220, 430), "Click Here To Start"
  42. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  43.  
  44.     _LIMIT 30
  45.     mouseWheel = 0
  46.         mouseX = _MOUSEX
  47.         mouseY = _MOUSEY
  48.         mouseLeftButton = _MOUSEBUTTON(1)
  49.         mouseRightButton = _MOUSEBUTTON(2)
  50.         mouseMiddleButton = _MOUSEBUTTON(3)
  51.         mouseWheel = mouseWheel + _MOUSEWHEEL
  52.     LOOP
  53.     ag$ = INKEY$
  54.     IF ag$ = CHR$(27) THEN END
  55.     IF ag$ = " " THEN CLS: GOTO start:
  56.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 370 AND mouseY > 430 AND mouseY < 446 THEN CLS: GOTO start:
  57.  
  58.  
  59.  
  60. start:
  61. ag$ = ""
  62. t = 0
  63. turn = 0
  64. comp = 0
  65.  
  66. c1 = INT(RND * 155) + 100
  67. c2 = INT(RND * 155) + 100
  68. c3 = INT(RND * 155) + 100
  69.  
  70. 'Draw Grid
  71. 'Vertical Lines
  72. LINE (220, 100)-(240, 410), _RGB32(c1, c2, c3), BF
  73. LINE (360, 100)-(380, 410), _RGB32(c1, c2, c3), BF
  74. 'Horizontal Lines
  75. LINE (90, 185)-(510, 205), _RGB32(c1, c2, c3), BF
  76. LINE (90, 305)-(510, 325), _RGB32(c1, c2, c3), BF
  77.  
  78. whosfirst:
  79. first = INT(RND * 2) + 1
  80. IF first = 1 THEN GOTO computerchoice:
  81.  
  82. Go:
  83. a$ = INKEY$
  84. IF a$ = CHR$(27) THEN END
  85. mouseWheel = 0
  86.     mouseX = _MOUSEX
  87.     mouseY = _MOUSEY
  88.     mouseLeftButton = _MOUSEBUTTON(1)
  89.     mouseRightButton = _MOUSEBUTTON(2)
  90.     mouseMiddleButton = _MOUSEBUTTON(3)
  91.     mouseWheel = mouseWheel + _MOUSEWHEEL
  92.  
  93. IF mouseLeftButton = -1 THEN
  94.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 93 AND mouseY < 182 AND b(1) = 0 AND a(1) = 0 AND t = 0 THEN GOSUB space1:
  95.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 93 AND mouseY < 182 AND b(2) = 0 AND a(2) = 0 AND t = 0 THEN GOSUB space2:
  96.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 93 AND mouseY < 182 AND b(3) = 0 AND a(3) = 0 AND t = 0 THEN GOSUB space3:
  97.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 205 AND mouseY < 302 AND b(4) = 0 AND a(4) = 0 AND t = 0 THEN GOSUB space4:
  98.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 205 AND mouseY < 302 AND b(5) = 0 AND a(5) = 0 AND t = 0 THEN GOSUB space5:
  99.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 205 AND mouseY < 302 AND b(6) = 0 AND a(6) = 0 AND t = 0 THEN GOSUB space6:
  100.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 326 AND mouseY < 410 AND b(7) = 0 AND a(7) = 0 AND t = 0 THEN GOSUB space7:
  101.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 326 AND mouseY < 410 AND b(8) = 0 AND a(8) = 0 AND t = 0 THEN GOSUB space8:
  102.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 326 AND mouseY < 410 AND b(9) = 0 AND a(9) = 0 AND t = 0 THEN GOSUB space9:
  103.  
  104. IF mouseLeftButton = -1 AND ending = 1 THEN GOTO start:
  105. IF mouseRightButton = -1 AND ending = 1 THEN END
  106.  
  107. IF t = 1 THEN GOSUB computer:
  108.  
  109. GOTO Go:
  110.  
  111. checkwin:
  112. 'Check to see if you won.
  113. IF a(1) = 1 AND a(2) = 1 AND a(3) = 1 THEN GOTO won:
  114. IF a(4) = 1 AND a(5) = 1 AND a(6) = 1 THEN GOTO won:
  115. IF a(7) = 1 AND a(8) = 1 AND a(9) = 1 THEN GOTO won
  116. IF a(1) = 1 AND a(4) = 1 AND a(7) = 1 THEN GOTO won:
  117. IF a(2) = 1 AND a(5) = 1 AND a(8) = 1 THEN GOTO won:
  118. IF a(3) = 1 AND a(6) = 1 AND a(9) = 1 THEN GOTO won:
  119. IF a(1) = 1 AND a(5) = 1 AND a(9) = 1 THEN GOTO won:
  120. IF a(3) = 1 AND a(5) = 1 AND a(7) = 1 THEN GOTO won:
  121. turn = turn + 1
  122. SOUND 100, .25
  123. IF turn = 9 THEN GOTO catsgame:
  124. GOTO Go:
  125. won:
  126. FOR snd = 300 TO 900 STEP 50
  127.     SOUND snd, .5
  128. NEXT snd
  129. FOR tt = 1 TO 9
  130.     a(tt) = 0
  131.     b(tt) = 0
  132. NEXT tt
  133. t = 0
  134. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  135. LOCATE 2, 32: PRINT "Y O U   W I N ! !"
  136. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  137. GOTO playagain:
  138.  
  139. computer:
  140.  
  141. 'Check to win.
  142. 'Last space gone.
  143. IF b(1) = 1 AND b(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  144. IF b(4) = 1 AND b(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  145. IF b(7) = 1 AND b(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  146. IF b(1) = 1 AND b(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  147. IF b(2) = 1 AND b(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  148. IF b(3) = 1 AND b(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  149. IF b(1) = 1 AND b(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  150. IF b(3) = 1 AND b(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  151. 'First space gone.
  152. IF b(2) = 1 AND b(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  153. IF b(5) = 1 AND b(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  154. IF b(8) = 1 AND b(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  155. IF b(4) = 1 AND b(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  156. IF b(5) = 1 AND b(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  157. IF b(6) = 1 AND b(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  158. IF b(5) = 1 AND b(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  159. IF b(7) = 1 AND b(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  160. 'Middle space gone.
  161. IF b(1) = 1 AND b(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  162. IF b(4) = 1 AND b(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  163. IF b(7) = 1 AND b(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  164. IF b(1) = 1 AND b(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  165. IF b(2) = 1 AND b(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  166. IF b(3) = 1 AND b(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  167. IF b(1) = 1 AND b(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  168. IF b(3) = 1 AND b(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  169.  
  170. 'Check to block.
  171. 'Last space gone.
  172. IF a(1) = 1 AND a(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  173. IF a(4) = 1 AND a(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  174. IF a(7) = 1 AND a(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  175. IF a(1) = 1 AND a(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  176. IF a(2) = 1 AND a(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  177. IF a(3) = 1 AND a(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  178. IF a(1) = 1 AND a(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  179. IF a(3) = 1 AND a(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  180. 'First space gone.
  181. IF a(2) = 1 AND a(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  182. IF a(5) = 1 AND a(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  183. IF a(8) = 1 AND a(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  184. IF a(4) = 1 AND a(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  185. IF a(5) = 1 AND a(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  186. IF a(6) = 1 AND a(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  187. IF a(5) = 1 AND a(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  188. IF a(7) = 1 AND a(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  189. 'Middle space gone.
  190. IF a(1) = 1 AND a(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  191. IF a(4) = 1 AND a(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  192. IF a(7) = 1 AND a(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  193. IF a(1) = 1 AND a(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  194. IF a(2) = 1 AND a(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  195. IF a(3) = 1 AND a(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  196. IF a(1) = 1 AND a(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  197. IF a(3) = 1 AND a(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  198.  
  199. 'Computer decides a random space.
  200. computerchoice:
  201. comp = INT(RND * 9) + 1
  202. IF b(comp) = 1 THEN GOTO computerchoice:
  203. IF a(comp) = 1 THEN GOTO computerchoice:
  204. IF comp = 1 THEN GOTO compspace1:
  205. IF comp = 2 THEN GOTO compspace2:
  206. IF comp = 3 THEN GOTO compspace3:
  207. IF comp = 4 THEN GOTO compspace4:
  208. IF comp = 5 THEN GOTO compspace5:
  209. IF comp = 6 THEN GOTO compspace6:
  210. IF comp = 7 THEN GOTO compspace7:
  211. IF comp = 8 THEN GOTO compspace8:
  212. IF comp = 9 THEN GOTO compspace9:
  213.  
  214. 'Cat's Game
  215. catsgame:
  216. FOR snd = 400 TO 300 STEP -25
  217.     SOUND snd, .5
  218. NEXT snd
  219. FOR tt = 1 TO 9
  220.     a(tt) = 0
  221.     b(tt) = 0
  222. NEXT tt
  223. t = 0
  224. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 255)
  225. LOCATE 2, 29: PRINT "Cat's Game - No Winners"
  226. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  227. GOTO playagain:
  228.  
  229. 'Check to see if the computer won.
  230. check:
  231. IF b(1) = 1 AND b(2) = 1 AND b(3) = 1 THEN GOTO compwon:
  232. IF b(4) = 1 AND b(5) = 1 AND b(6) = 1 THEN GOTO compwon:
  233. IF b(7) = 1 AND b(8) = 1 AND b(9) = 1 THEN GOTO compwon
  234. IF b(1) = 1 AND b(4) = 1 AND b(7) = 1 THEN GOTO compwon:
  235. IF b(2) = 1 AND b(5) = 1 AND b(8) = 1 THEN GOTO compwon:
  236. IF b(3) = 1 AND b(6) = 1 AND b(9) = 1 THEN GOTO compwon:
  237. IF b(1) = 1 AND b(5) = 1 AND b(9) = 1 THEN GOTO compwon:
  238. IF b(3) = 1 AND b(5) = 1 AND b(7) = 1 THEN GOTO compwon:
  239. turn = turn + 1
  240. IF turn = 9 THEN GOTO catsgame:
  241. t = 0
  242. GOTO Go:
  243.  
  244. compwon:
  245. FOR snd = 900 TO 300 STEP -50
  246.     SOUND snd, .5
  247. NEXT snd
  248. FOR tt = 1 TO 9
  249.     a(tt) = 0
  250.     b(tt) = 0
  251. NEXT tt
  252. t = 0
  253. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 255)
  254. LOCATE 2, 33: PRINT "Computer  Wins"
  255. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  256. GOTO playagain:
  257.  
  258. 'This part draws the computer's circle.
  259. compspace1:
  260. t = 0
  261. b(1) = 1
  262. FOR s = .25 TO 5 STEP .25
  263.     CIRCLE (160, 137), 40 - s, _RGB32(255, 0, 0)
  264. GOTO check:
  265. compspace2:
  266. t = 0
  267. b(2) = 1
  268. FOR s = .25 TO 5 STEP .25
  269.     CIRCLE (300, 137), 40 - s, _RGB32(255, 0, 0)
  270. GOTO check:
  271. compspace3:
  272. t = 0
  273. b(3) = 1
  274. FOR s = .25 TO 5 STEP .25
  275.     CIRCLE (440, 137), 40 - s, _RGB32(255, 0, 0)
  276. GOTO check:
  277. compspace4:
  278. t = 0
  279. b(4) = 1
  280. FOR s = .25 TO 5 STEP .25
  281.     CIRCLE (160, 257), 40 - s, _RGB32(255, 0, 0)
  282. GOTO check:
  283. compspace5:
  284. t = 0
  285. b(5) = 1
  286. FOR s = .25 TO 5 STEP .25
  287.     CIRCLE (300, 257), 40 - s, _RGB32(255, 0, 0)
  288. GOTO check:
  289. compspace6:
  290. t = 0
  291. b(6) = 1
  292. FOR s = .25 TO 5 STEP .25
  293.     CIRCLE (440, 257), 40 - s, _RGB32(255, 0, 0)
  294. GOTO check:
  295. compspace7:
  296. t = 0
  297. b(7) = 1
  298. FOR s = .25 TO 5 STEP .25
  299.     CIRCLE (160, 372), 40 - s, _RGB32(255, 0, 0)
  300. GOTO check:
  301. compspace8:
  302. t = 0
  303. b(8) = 1
  304. FOR s = .25 TO 5 STEP .25
  305.     CIRCLE (300, 372), 40 - s, _RGB32(255, 0, 0)
  306. GOTO check:
  307. compspace9:
  308. t = 0
  309. b(9) = 1
  310. FOR s = .25 TO 5 STEP .25
  311.     CIRCLE (440, 372), 40 - s, _RGB32(255, 0, 0)
  312. GOTO check:
  313. 'This last part draws your X.
  314. space1:
  315. a(1) = 1
  316. FOR s = .25 TO 5 STEP .25
  317.     LINE (120 + s, 110)-(200 + s, 175), _RGB32(0, 255, 0)
  318.     LINE (200 + s, 110)-(120 + s, 175), _RGB32(0, 255, 0)
  319. t = 1
  320. GOTO checkwin:
  321. space2:
  322. a(2) = 1
  323. FOR s = .25 TO 5 STEP .25
  324.     LINE (260 + s, 110)-(340 + s, 175), _RGB32(0, 255, 0)
  325.     LINE (340 + s, 110)-(260 + s, 175), _RGB32(0, 255, 0)
  326. t = 1
  327. GOTO checkwin:
  328. space3:
  329. a(3) = 1
  330. FOR s = .25 TO 5 STEP .25
  331.     LINE (400 + s, 110)-(480 + s, 175), _RGB32(0, 255, 0)
  332.     LINE (480 + s, 110)-(400 + s, 175), _RGB32(0, 255, 0)
  333. t = 1
  334. GOTO checkwin:
  335. space4:
  336. a(4) = 1
  337. FOR s = .25 TO 5 STEP .25
  338.     LINE (120 + s, 225)-(200 + s, 290), _RGB32(0, 255, 0)
  339.     LINE (200 + s, 225)-(120 + s, 290), _RGB32(0, 255, 0)
  340. t = 1
  341. GOTO checkwin:
  342. space5:
  343. a(5) = 1
  344. FOR s = .25 TO 5 STEP .25
  345.     LINE (260 + s, 225)-(340 + s, 290), _RGB32(0, 255, 0)
  346.     LINE (340 + s, 225)-(260 + s, 290), _RGB32(0, 255, 0)
  347. t = 1
  348. GOTO checkwin:
  349. space6:
  350. a(6) = 1
  351. FOR s = .25 TO 5 STEP .25
  352.     LINE (400 + s, 225)-(480 + s, 290), _RGB32(0, 255, 0)
  353.     LINE (480 + s, 225)-(400 + s, 290), _RGB32(0, 255, 0)
  354. t = 1
  355. GOTO checkwin:
  356. space7:
  357. a(7) = 1
  358. FOR s = .25 TO 5 STEP .25
  359.     LINE (120 + s, 340)-(200 + s, 405), _RGB32(0, 255, 0)
  360.     LINE (200 + s, 340)-(120 + s, 405), _RGB32(0, 255, 0)
  361. t = 1
  362. GOTO checkwin:
  363. space8:
  364. a(8) = 1
  365. FOR s = .25 TO 5 STEP .25
  366.     LINE (260 + s, 340)-(340 + s, 405), _RGB32(0, 255, 0)
  367.     LINE (340 + s, 340)-(260 + s, 405), _RGB32(0, 255, 0)
  368. t = 1
  369. GOTO checkwin:
  370. space9:
  371. a(9) = 1
  372. FOR s = .25 TO 5 STEP .25
  373.     LINE (400 + s, 340)-(480 + s, 405), _RGB32(0, 255, 0)
  374.     LINE (480 + s, 340)-(400 + s, 405), _RGB32(0, 255, 0)
  375. t = 1
  376. GOTO checkwin:
  377.  
  378. playagain:
  379. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  380. _PRINTSTRING (220, 55), "Click Here To Play Again"
  381. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  382.  
  383.     _LIMIT 30
  384.     mouseWheel = 0
  385.         mouseX = _MOUSEX
  386.         mouseY = _MOUSEY
  387.         mouseLeftButton = _MOUSEBUTTON(1)
  388.         mouseRightButton = _MOUSEBUTTON(2)
  389.         mouseMiddleButton = _MOUSEBUTTON(3)
  390.         mouseWheel = mouseWheel + _MOUSEWHEEL
  391.     LOOP
  392.     ag$ = INKEY$
  393.     IF ag$ = CHR$(27) THEN END
  394.     IF ag$ = " " THEN CLS: GOTO start:
  395.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 412 AND mouseY > 55 AND mouseY < 69 THEN CLS: GOTO start:
  396.  
TicTacToe.jpg
* TicTacToe.jpg (Filesize: 55.99 KB, Dimensions: 601x504, Views: 115)
« Last Edit: January 30, 2021, 02:10:54 am by SierraKen »

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Tic-Tac-Toe
« Reply #4 on: January 30, 2021, 02:08:49 am »
@SierraKen

Is the center square the best play for the first move and is there a best 2nd move if the first move was the center square?
« Last Edit: January 30, 2021, 02:10:18 am by NOVARSEG »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #5 on: January 30, 2021, 02:12:01 am »
Novarseg, I believe the center square is the best square to have first so you have the most options to go from there. As for the second move, I really don't know.

Offline NOVARSEG

  • Forum Resident
  • Posts: 509
    • View Profile
Re: Tic-Tac-Toe
« Reply #6 on: January 30, 2021, 02:20:50 am »
Ran your latest code -  I like the layout colors.

Ok so I started in the center and the computer chose a side. I determined that if the 2nd move is a side move, then the first player wins if played right. The third move in that case is a side move.

If the first move is center and the second move is a corner then it looks like no player can win if played right.
« Last Edit: January 30, 2021, 02:39:27 am by NOVARSEG »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Tic-Tac-Toe
« Reply #7 on: January 30, 2021, 03:21:10 am »
Tic-Tac-Toe is a simplistic game with a very limited set of moves.

Starting out, one of the corner pieces gives you the best chance to win.  Unless your opponent takes the middle with their first move, you win.

XO.
X..
...

X.O
...
..X

X..
..O
X..

I can draw out all the possibilities, if you need, but unless O goes in the center on their first move, X will win.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Tic-Tac-Toe
« Reply #8 on: January 30, 2021, 03:22:50 am »
This should help you draw it Steve. Courtesy of xkcd.

 
tic_tac_toe.png
You're not done when it works, you're done when it's right.

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tic-Tac-Toe
« Reply #9 on: January 30, 2021, 10:25:12 am »
RE: Best moves
If you cant win on next move, spoil opponents possible win, if neither then Center square is best, corner blocking one of other players potential ttt  is 2nd best, take the sides only to stop other from winning, guaranteed win or draw every time, yawn. ;-))

@Anthony.R.Brown has your program got this figured out yet?
« Last Edit: January 30, 2021, 10:26:17 am by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #10 on: January 30, 2021, 02:39:10 pm »
Today I decided to add background blue shades, which you can see in the picture below. I also decided to add a score for you and the computer in the Topic Bar. There's no end so you can play as long as you want.

Code: QB64: [Select]
  1. 'I've wanted to make this game for decades and finally am able to!
  2. 'This game was made on August 14, 2019 by SierraKen.
  3. 'This is Freeware.
  4. 'Jan. 28, 2021 update: Choose at random who goes first.
  5. 'Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game,
  6. 'and added text colors.
  7. 'Jan. 30, 2021 update: Added background blue shades. Also added a score in the Title Bar.
  8.  
  9.  
  10. DIM a(10), b(10)
  11. _TITLE "Tic-Tac-Toe     by SierraKen"
  12. SCREEN _NEWIMAGE(600, 480, 32)
  13. LOCATE 10, 34: PRINT "-"
  14. LOCATE 10, 40: PRINT "-"
  15. FOR tic = 1 TO 10
  16.     LOCATE tic, 30: PRINT "TIC"
  17.     _DELAY .1
  18.     LOCATE tic, 30: PRINT "   "
  19. NEXT tic
  20. LOCATE 10, 30: PRINT "TIC"
  21.  
  22. FOR tac = 20 TO 10 STEP -1
  23.     LOCATE tac, 36: PRINT "TAC"
  24.     _DELAY .1
  25.     LOCATE tac, 36: PRINT "   "
  26. NEXT tac
  27. LOCATE 10, 36: PRINT "TAC"
  28.  
  29. FOR toe = 1 TO 10
  30.     LOCATE toe, 42: PRINT "TOE"
  31.     _DELAY .1
  32.     LOCATE toe, 42: PRINT "   "
  33. NEXT toe
  34. LOCATE 10, 42: PRINT "TOE"
  35. computer = 0
  36. you = 0
  37.  
  38. PRINT "                              By  SierraKen"
  39. PRINT "       Play against the computer in this classic game of Tic-Tac-Toe."
  40. PRINT "                      Whoever gets 3 in a row wins."
  41. PRINT "                    Choose a sqace by using your mouse."
  42. PRINT "                     Computer chooses who goes first."
  43.  
  44. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  45. _PRINTSTRING (220, 430), "Click Here To Start"
  46. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  47.  
  48.     _LIMIT 30
  49.     mouseWheel = 0
  50.         mouseX = _MOUSEX
  51.         mouseY = _MOUSEY
  52.         mouseLeftButton = _MOUSEBUTTON(1)
  53.         mouseRightButton = _MOUSEBUTTON(2)
  54.         mouseMiddleButton = _MOUSEBUTTON(3)
  55.         mouseWheel = mouseWheel + _MOUSEWHEEL
  56.     LOOP
  57.     ag$ = INKEY$
  58.     IF ag$ = CHR$(27) THEN END
  59.     IF ag$ = " " THEN CLS: GOTO start:
  60.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 370 AND mouseY > 430 AND mouseY < 446 THEN CLS: GOTO start:
  61.  
  62. start:
  63. ag$ = ""
  64. t = 0
  65. turn = 0
  66. comp = 0
  67.  
  68. FOR cc = 0 TO 480
  69.     cl = cl + .5
  70.     LINE (0, cc)-(640, cc), _RGB32(0, 0, cl)
  71. NEXT cc
  72. cl = 0
  73. c1 = INT(RND * 155) + 100
  74. c2 = INT(RND * 155) + 100
  75. c3 = INT(RND * 155) + 100
  76.  
  77. 'Draw Grid
  78. 'Vertical Lines
  79. LINE (220, 100)-(240, 410), _RGB32(c1, c2, c3), BF
  80. LINE (360, 100)-(380, 410), _RGB32(c1, c2, c3), BF
  81. 'Horizontal Lines
  82. LINE (90, 185)-(510, 205), _RGB32(c1, c2, c3), BF
  83. LINE (90, 305)-(510, 325), _RGB32(c1, c2, c3), BF
  84.  
  85. whosfirst:
  86. first = INT(RND * 2) + 1
  87. IF first = 1 THEN GOTO computerchoice:
  88.  
  89. Go:
  90. a$ = INKEY$
  91. IF a$ = CHR$(27) THEN END
  92. mouseWheel = 0
  93.     mouseX = _MOUSEX
  94.     mouseY = _MOUSEY
  95.     mouseLeftButton = _MOUSEBUTTON(1)
  96.     mouseRightButton = _MOUSEBUTTON(2)
  97.     mouseMiddleButton = _MOUSEBUTTON(3)
  98.     mouseWheel = mouseWheel + _MOUSEWHEEL
  99.  
  100. IF mouseLeftButton = -1 THEN
  101.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 93 AND mouseY < 182 AND b(1) = 0 AND a(1) = 0 AND t = 0 THEN GOSUB space1:
  102.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 93 AND mouseY < 182 AND b(2) = 0 AND a(2) = 0 AND t = 0 THEN GOSUB space2:
  103.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 93 AND mouseY < 182 AND b(3) = 0 AND a(3) = 0 AND t = 0 THEN GOSUB space3:
  104.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 205 AND mouseY < 302 AND b(4) = 0 AND a(4) = 0 AND t = 0 THEN GOSUB space4:
  105.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 205 AND mouseY < 302 AND b(5) = 0 AND a(5) = 0 AND t = 0 THEN GOSUB space5:
  106.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 205 AND mouseY < 302 AND b(6) = 0 AND a(6) = 0 AND t = 0 THEN GOSUB space6:
  107.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 326 AND mouseY < 410 AND b(7) = 0 AND a(7) = 0 AND t = 0 THEN GOSUB space7:
  108.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 326 AND mouseY < 410 AND b(8) = 0 AND a(8) = 0 AND t = 0 THEN GOSUB space8:
  109.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 326 AND mouseY < 410 AND b(9) = 0 AND a(9) = 0 AND t = 0 THEN GOSUB space9:
  110.  
  111. IF mouseLeftButton = -1 AND ending = 1 THEN GOTO start:
  112. IF mouseRightButton = -1 AND ending = 1 THEN END
  113.  
  114. IF t = 1 THEN GOSUB computer:
  115.  
  116. GOTO Go:
  117.  
  118. checkwin:
  119. 'Check to see if you won.
  120. IF a(1) = 1 AND a(2) = 1 AND a(3) = 1 THEN GOTO won:
  121. IF a(4) = 1 AND a(5) = 1 AND a(6) = 1 THEN GOTO won:
  122. IF a(7) = 1 AND a(8) = 1 AND a(9) = 1 THEN GOTO won
  123. IF a(1) = 1 AND a(4) = 1 AND a(7) = 1 THEN GOTO won:
  124. IF a(2) = 1 AND a(5) = 1 AND a(8) = 1 THEN GOTO won:
  125. IF a(3) = 1 AND a(6) = 1 AND a(9) = 1 THEN GOTO won:
  126. IF a(1) = 1 AND a(5) = 1 AND a(9) = 1 THEN GOTO won:
  127. IF a(3) = 1 AND a(5) = 1 AND a(7) = 1 THEN GOTO won:
  128. turn = turn + 1
  129. SOUND 100, .25
  130. IF turn = 9 THEN GOTO catsgame:
  131. GOTO Go:
  132. won:
  133. FOR snd = 300 TO 900 STEP 50
  134.     SOUND snd, .5
  135. NEXT snd
  136. FOR tt = 1 TO 9
  137.     a(tt) = 0
  138.     b(tt) = 0
  139. NEXT tt
  140. you = you + 1
  141. you$ = STR$(you)
  142. computer$ = STR$(computer)
  143. _TITLE "You: " + you$ + "   Computer: " + comp$
  144. t = 0
  145. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  146. LOCATE 2, 32: PRINT "Y O U   W I N ! !"
  147. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  148. GOTO playagain:
  149.  
  150. computer:
  151.  
  152. 'Check to win.
  153. 'Last space gone.
  154. IF b(1) = 1 AND b(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  155. IF b(4) = 1 AND b(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  156. IF b(7) = 1 AND b(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  157. IF b(1) = 1 AND b(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  158. IF b(2) = 1 AND b(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  159. IF b(3) = 1 AND b(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  160. IF b(1) = 1 AND b(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  161. IF b(3) = 1 AND b(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  162. 'First space gone.
  163. IF b(2) = 1 AND b(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  164. IF b(5) = 1 AND b(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  165. IF b(8) = 1 AND b(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  166. IF b(4) = 1 AND b(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  167. IF b(5) = 1 AND b(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  168. IF b(6) = 1 AND b(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  169. IF b(5) = 1 AND b(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  170. IF b(7) = 1 AND b(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  171. 'Middle space gone.
  172. IF b(1) = 1 AND b(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  173. IF b(4) = 1 AND b(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  174. IF b(7) = 1 AND b(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  175. IF b(1) = 1 AND b(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  176. IF b(2) = 1 AND b(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  177. IF b(3) = 1 AND b(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  178. IF b(1) = 1 AND b(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  179. IF b(3) = 1 AND b(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  180.  
  181. 'Check to block.
  182. 'Last space gone.
  183. IF a(1) = 1 AND a(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  184. IF a(4) = 1 AND a(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  185. IF a(7) = 1 AND a(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  186. IF a(1) = 1 AND a(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  187. IF a(2) = 1 AND a(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  188. IF a(3) = 1 AND a(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  189. IF a(1) = 1 AND a(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  190. IF a(3) = 1 AND a(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  191. 'First space gone.
  192. IF a(2) = 1 AND a(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  193. IF a(5) = 1 AND a(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  194. IF a(8) = 1 AND a(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  195. IF a(4) = 1 AND a(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  196. IF a(5) = 1 AND a(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  197. IF a(6) = 1 AND a(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  198. IF a(5) = 1 AND a(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  199. IF a(7) = 1 AND a(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  200. 'Middle space gone.
  201. IF a(1) = 1 AND a(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  202. IF a(4) = 1 AND a(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  203. IF a(7) = 1 AND a(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  204. IF a(1) = 1 AND a(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  205. IF a(2) = 1 AND a(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  206. IF a(3) = 1 AND a(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  207. IF a(1) = 1 AND a(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  208. IF a(3) = 1 AND a(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  209.  
  210. 'Computer decides a random space.
  211. computerchoice:
  212. comp = INT(RND * 9) + 1
  213. IF b(comp) = 1 THEN GOTO computerchoice:
  214. IF a(comp) = 1 THEN GOTO computerchoice:
  215. IF comp = 1 THEN GOTO compspace1:
  216. IF comp = 2 THEN GOTO compspace2:
  217. IF comp = 3 THEN GOTO compspace3:
  218. IF comp = 4 THEN GOTO compspace4:
  219. IF comp = 5 THEN GOTO compspace5:
  220. IF comp = 6 THEN GOTO compspace6:
  221. IF comp = 7 THEN GOTO compspace7:
  222. IF comp = 8 THEN GOTO compspace8:
  223. IF comp = 9 THEN GOTO compspace9:
  224.  
  225. 'Cat's Game
  226. catsgame:
  227. FOR snd = 400 TO 300 STEP -25
  228.     SOUND snd, .5
  229. NEXT snd
  230. FOR tt = 1 TO 9
  231.     a(tt) = 0
  232.     b(tt) = 0
  233. NEXT tt
  234. t = 0
  235. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 255)
  236. LOCATE 2, 29: PRINT "Cat's Game - No Winners"
  237. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  238. GOTO playagain:
  239.  
  240. 'Check to see if the computer won.
  241. check:
  242. IF b(1) = 1 AND b(2) = 1 AND b(3) = 1 THEN GOTO compwon:
  243. IF b(4) = 1 AND b(5) = 1 AND b(6) = 1 THEN GOTO compwon:
  244. IF b(7) = 1 AND b(8) = 1 AND b(9) = 1 THEN GOTO compwon
  245. IF b(1) = 1 AND b(4) = 1 AND b(7) = 1 THEN GOTO compwon:
  246. IF b(2) = 1 AND b(5) = 1 AND b(8) = 1 THEN GOTO compwon:
  247. IF b(3) = 1 AND b(6) = 1 AND b(9) = 1 THEN GOTO compwon:
  248. IF b(1) = 1 AND b(5) = 1 AND b(9) = 1 THEN GOTO compwon:
  249. IF b(3) = 1 AND b(5) = 1 AND b(7) = 1 THEN GOTO compwon:
  250. turn = turn + 1
  251. IF turn = 9 THEN GOTO catsgame:
  252. t = 0
  253. GOTO Go:
  254.  
  255. compwon:
  256. FOR snd = 900 TO 300 STEP -50
  257.     SOUND snd, .5
  258. NEXT snd
  259. FOR tt = 1 TO 9
  260.     a(tt) = 0
  261.     b(tt) = 0
  262. NEXT tt
  263. t = 0
  264. computer = computer + 1
  265. you$ = STR$(you)
  266. comp$ = STR$(computer)
  267. _TITLE "You: " + you$ + "   Computer: " + comp$
  268. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 255)
  269. LOCATE 2, 33: PRINT "Computer  Wins"
  270. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  271. GOTO playagain:
  272.  
  273. 'This part draws the computer's circle.
  274. compspace1:
  275. t = 0
  276. b(1) = 1
  277. FOR s = .25 TO 5 STEP .25
  278.     CIRCLE (160, 137), 40 - s, _RGB32(255, 0, 0)
  279. GOTO check:
  280. compspace2:
  281. t = 0
  282. b(2) = 1
  283. FOR s = .25 TO 5 STEP .25
  284.     CIRCLE (300, 137), 40 - s, _RGB32(255, 0, 0)
  285. GOTO check:
  286. compspace3:
  287. t = 0
  288. b(3) = 1
  289. FOR s = .25 TO 5 STEP .25
  290.     CIRCLE (440, 137), 40 - s, _RGB32(255, 0, 0)
  291. GOTO check:
  292. compspace4:
  293. t = 0
  294. b(4) = 1
  295. FOR s = .25 TO 5 STEP .25
  296.     CIRCLE (160, 257), 40 - s, _RGB32(255, 0, 0)
  297. GOTO check:
  298. compspace5:
  299. t = 0
  300. b(5) = 1
  301. FOR s = .25 TO 5 STEP .25
  302.     CIRCLE (300, 257), 40 - s, _RGB32(255, 0, 0)
  303. GOTO check:
  304. compspace6:
  305. t = 0
  306. b(6) = 1
  307. FOR s = .25 TO 5 STEP .25
  308.     CIRCLE (440, 257), 40 - s, _RGB32(255, 0, 0)
  309. GOTO check:
  310. compspace7:
  311. t = 0
  312. b(7) = 1
  313. FOR s = .25 TO 5 STEP .25
  314.     CIRCLE (160, 372), 40 - s, _RGB32(255, 0, 0)
  315. GOTO check:
  316. compspace8:
  317. t = 0
  318. b(8) = 1
  319. FOR s = .25 TO 5 STEP .25
  320.     CIRCLE (300, 372), 40 - s, _RGB32(255, 0, 0)
  321. GOTO check:
  322. compspace9:
  323. t = 0
  324. b(9) = 1
  325. FOR s = .25 TO 5 STEP .25
  326.     CIRCLE (440, 372), 40 - s, _RGB32(255, 0, 0)
  327. GOTO check:
  328. 'This last part draws your X.
  329. space1:
  330. a(1) = 1
  331. FOR s = .25 TO 5 STEP .25
  332.     LINE (120 + s, 110)-(200 + s, 175), _RGB32(0, 255, 0)
  333.     LINE (200 + s, 110)-(120 + s, 175), _RGB32(0, 255, 0)
  334. t = 1
  335. GOTO checkwin:
  336. space2:
  337. a(2) = 1
  338. FOR s = .25 TO 5 STEP .25
  339.     LINE (260 + s, 110)-(340 + s, 175), _RGB32(0, 255, 0)
  340.     LINE (340 + s, 110)-(260 + s, 175), _RGB32(0, 255, 0)
  341. t = 1
  342. GOTO checkwin:
  343. space3:
  344. a(3) = 1
  345. FOR s = .25 TO 5 STEP .25
  346.     LINE (400 + s, 110)-(480 + s, 175), _RGB32(0, 255, 0)
  347.     LINE (480 + s, 110)-(400 + s, 175), _RGB32(0, 255, 0)
  348. t = 1
  349. GOTO checkwin:
  350. space4:
  351. a(4) = 1
  352. FOR s = .25 TO 5 STEP .25
  353.     LINE (120 + s, 225)-(200 + s, 290), _RGB32(0, 255, 0)
  354.     LINE (200 + s, 225)-(120 + s, 290), _RGB32(0, 255, 0)
  355. t = 1
  356. GOTO checkwin:
  357. space5:
  358. a(5) = 1
  359. FOR s = .25 TO 5 STEP .25
  360.     LINE (260 + s, 225)-(340 + s, 290), _RGB32(0, 255, 0)
  361.     LINE (340 + s, 225)-(260 + s, 290), _RGB32(0, 255, 0)
  362. t = 1
  363. GOTO checkwin:
  364. space6:
  365. a(6) = 1
  366. FOR s = .25 TO 5 STEP .25
  367.     LINE (400 + s, 225)-(480 + s, 290), _RGB32(0, 255, 0)
  368.     LINE (480 + s, 225)-(400 + s, 290), _RGB32(0, 255, 0)
  369. t = 1
  370. GOTO checkwin:
  371. space7:
  372. a(7) = 1
  373. FOR s = .25 TO 5 STEP .25
  374.     LINE (120 + s, 340)-(200 + s, 405), _RGB32(0, 255, 0)
  375.     LINE (200 + s, 340)-(120 + s, 405), _RGB32(0, 255, 0)
  376. t = 1
  377. GOTO checkwin:
  378. space8:
  379. a(8) = 1
  380. FOR s = .25 TO 5 STEP .25
  381.     LINE (260 + s, 340)-(340 + s, 405), _RGB32(0, 255, 0)
  382.     LINE (340 + s, 340)-(260 + s, 405), _RGB32(0, 255, 0)
  383. t = 1
  384. GOTO checkwin:
  385. space9:
  386. a(9) = 1
  387. FOR s = .25 TO 5 STEP .25
  388.     LINE (400 + s, 340)-(480 + s, 405), _RGB32(0, 255, 0)
  389.     LINE (480 + s, 340)-(400 + s, 405), _RGB32(0, 255, 0)
  390. t = 1
  391. GOTO checkwin:
  392.  
  393. playagain:
  394. COLOR _RGB32(255, 255, 255), _RGB32(255, 0, 0)
  395. _PRINTSTRING (220, 55), "Click Here To Play Again"
  396. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  397.  
  398.     _LIMIT 30
  399.     mouseWheel = 0
  400.         mouseX = _MOUSEX
  401.         mouseY = _MOUSEY
  402.         mouseLeftButton = _MOUSEBUTTON(1)
  403.         mouseRightButton = _MOUSEBUTTON(2)
  404.         mouseMiddleButton = _MOUSEBUTTON(3)
  405.         mouseWheel = mouseWheel + _MOUSEWHEEL
  406.     LOOP
  407.     ag$ = INKEY$
  408.     IF ag$ = CHR$(27) THEN END
  409.     IF ag$ = " " THEN CLS: GOTO start:
  410.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 412 AND mouseY > 55 AND mouseY < 69 THEN CLS: GOTO start:
  411.  
TicTacToe.jpg
* TicTacToe.jpg (Filesize: 73.45 KB, Dimensions: 602x505, Views: 101)

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: Tic-Tac-Toe
« Reply #11 on: January 30, 2021, 04:02:26 pm »
@SierraKen  do you know how to do clear backgrounds for printing? I think that might look better.

Also can get fake 3D effect going by printing same thing over and over with slightly different color and offset.

Code: QB64: [Select]
  1. _TITLE "Fake 3D demo" 'b+ 2020- 01-30
  2.  
  3. CONST xmax = 800, ymax = 600, xc = 400, yc = 300
  4. SCREEN _NEWIMAGE(xmax, ymax, 32)
  5. _DELAY .25 'need time for screen to load before attempting to move it.
  6. FOR i = 1 TO 50
  7.     colr = _RGB32(0 + 5 * i, 0, 0)
  8.     Text 60 + i, 20 + i, 256, colr, "B+"
  9.  
  10. SUB Text (x, y, textHeight, K AS _UNSIGNED LONG, txt$)
  11.     DIM fg AS _UNSIGNED LONG, cur&, I&, multi, xlen
  12.     fg = _DEFAULTCOLOR
  13.     'screen snapshot
  14.     cur& = _DEST
  15.     I& = _NEWIMAGE(8 * LEN(txt$), 16, 32)
  16.     _DEST I&
  17.     COLOR K, _RGBA32(0, 0, 0, 0)
  18.     _PRINTSTRING (0, 0), txt$
  19.     multi = textHeight / 16
  20.     xlen = LEN(txt$) * 8 * multi
  21.     _PUTIMAGE (x, y)-STEP(xlen, textHeight), I&, cur&
  22.     COLOR fg
  23.     _FREEIMAGE I&
  24.  
  25.  
image_2021-01-30_162331.png
* image_2021-01-30_162331.png (Filesize: 5.51 KB, Dimensions: 382x360, Views: 92)
« Last Edit: January 30, 2021, 04:23:32 pm by bplus »

Offline SierraKen

  • Forum Resident
  • Posts: 1454
    • View Profile
Re: Tic-Tac-Toe
« Reply #12 on: January 30, 2021, 06:37:59 pm »
I did it!! Thanks for the idea B+! I turned the game into 3D. I also learned about _CLEARCOLOR which I didn't know about before and used that for my text instead of the background red. This is probably the best looking game or program I've ever made!

Code: QB64: [Select]
  1. 'I've wanted to make this game for decades and finally am able to!
  2. 'This game was made on August 14, 2019 by SierraKen.
  3. 'This is Freeware.
  4. 'Jan. 28, 2021 update: Choose at random who goes first.
  5. 'Jan. 29, 2021 update: Random colored grid, better looking X's, faster welcome screen, centered welcome screen better, made the ability to click to play a new game and another game,
  6. 'and added text colors.
  7. 'Jan. 30, 2021 update: Added background blue shades. Also added a score in the Title Bar. Turned the game into 3D - Thanks to B+ for the idea!
  8.  
  9.  
  10. DIM a(10), b(10)
  11. _TITLE "Tic-Tac-Toe     by SierraKen"
  12. SCREEN _NEWIMAGE(600, 480, 32)
  13. LOCATE 10, 34: PRINT "-"
  14. LOCATE 10, 40: PRINT "-"
  15. FOR tic = 1 TO 10
  16.     LOCATE tic, 30: PRINT "TIC"
  17.     _DELAY .1
  18.     LOCATE tic, 30: PRINT "   "
  19. NEXT tic
  20. LOCATE 10, 30: PRINT "TIC"
  21. FOR tac = 20 TO 10 STEP -1
  22.     LOCATE tac, 36: PRINT "TAC"
  23.     _DELAY .1
  24.     LOCATE tac, 36: PRINT "   "
  25. NEXT tac
  26. LOCATE 10, 36: PRINT "TAC"
  27. FOR toe = 1 TO 10
  28.     LOCATE toe, 42: PRINT "TOE"
  29.     _DELAY .1
  30.     LOCATE toe, 42: PRINT "   "
  31. NEXT toe
  32. LOCATE 10, 42: PRINT "TOE"
  33. computer = 0
  34. you = 0
  35.  
  36. PRINT "                              By  SierraKen"
  37. PRINT "       Play against the computer in this classic game of Tic-Tac-Toe."
  38. PRINT "                      Whoever gets 3 in a row wins."
  39. PRINT "                    Choose a sqace by using your mouse."
  40. PRINT "                     Computer chooses who goes first."
  41.  
  42. COLOR _RGB32(255, 255, 255), _CLEARCOLOR
  43. _PRINTSTRING (220, 430), "Click Here To Start"
  44. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  45.  
  46.     _LIMIT 60
  47.     mouseWheel = 0
  48.         mouseX = _MOUSEX
  49.         mouseY = _MOUSEY
  50.         mouseLeftButton = _MOUSEBUTTON(1)
  51.         mouseRightButton = _MOUSEBUTTON(2)
  52.         mouseMiddleButton = _MOUSEBUTTON(3)
  53.         mouseWheel = mouseWheel + _MOUSEWHEEL
  54.     LOOP
  55.     ag$ = INKEY$
  56.     IF ag$ = CHR$(27) THEN END
  57.     IF ag$ = " " THEN CLS: GOTO start:
  58.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 370 AND mouseY > 430 AND mouseY < 446 THEN CLS: GOTO start:
  59.  
  60. start:
  61. ag$ = ""
  62. t = 0
  63. turn = 0
  64. comp = 0
  65.  
  66. FOR cc = 0 TO 480
  67.     cl = cl + .5
  68.     LINE (0, cc)-(640, cc), _RGB32(0, 0, cl)
  69. NEXT cc
  70. cl = 0
  71. c1 = INT(RND * 155) + 100
  72. c2 = INT(RND * 155) + 100
  73. c3 = INT(RND * 155) + 100
  74.  
  75. 'Draw Grid
  76. 'Vertical Lines
  77. FOR xx = .1 TO 15 STEP .1
  78.     LINE (220 - xx, 100 - xx)-(240 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  79.     LINE (360 - xx, 100 - xx)-(380 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  80. NEXT xx
  81. FOR xx = .1 TO 15 STEP .1
  82.     'Horizontal Lines
  83.     LINE (90 - xx, 185 - xx)-(510 - xx, 205 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  84.     LINE (90 - xx, 305 - xx)-(510 - xx, 325 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
  85. NEXT xx
  86. whosfirst:
  87. first = INT(RND * 2) + 1
  88. IF first = 1 THEN GOTO computerchoice:
  89.  
  90. Go:
  91. a$ = INKEY$
  92. IF a$ = CHR$(27) THEN END
  93. mouseWheel = 0
  94.     mouseX = _MOUSEX
  95.     mouseY = _MOUSEY
  96.     mouseLeftButton = _MOUSEBUTTON(1)
  97.     mouseRightButton = _MOUSEBUTTON(2)
  98.     mouseMiddleButton = _MOUSEBUTTON(3)
  99.     mouseWheel = mouseWheel + _MOUSEWHEEL
  100.  
  101. IF mouseLeftButton = -1 THEN
  102.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 93 AND mouseY < 182 AND b(1) = 0 AND a(1) = 0 AND t = 0 THEN GOSUB space1:
  103.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 93 AND mouseY < 182 AND b(2) = 0 AND a(2) = 0 AND t = 0 THEN GOSUB space2:
  104.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 93 AND mouseY < 182 AND b(3) = 0 AND a(3) = 0 AND t = 0 THEN GOSUB space3:
  105.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 205 AND mouseY < 302 AND b(4) = 0 AND a(4) = 0 AND t = 0 THEN GOSUB space4:
  106.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 205 AND mouseY < 302 AND b(5) = 0 AND a(5) = 0 AND t = 0 THEN GOSUB space5:
  107.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 205 AND mouseY < 302 AND b(6) = 0 AND a(6) = 0 AND t = 0 THEN GOSUB space6:
  108.     IF mouseX > 88 AND mouseX < 218 AND mouseY > 326 AND mouseY < 410 AND b(7) = 0 AND a(7) = 0 AND t = 0 THEN GOSUB space7:
  109.     IF mouseX > 241 AND mouseX < 357 AND mouseY > 326 AND mouseY < 410 AND b(8) = 0 AND a(8) = 0 AND t = 0 THEN GOSUB space8:
  110.     IF mouseX > 381 AND mouseX < 509 AND mouseY > 326 AND mouseY < 410 AND b(9) = 0 AND a(9) = 0 AND t = 0 THEN GOSUB space9:
  111.  
  112. IF mouseLeftButton = -1 AND ending = 1 THEN GOTO start:
  113. IF mouseRightButton = -1 AND ending = 1 THEN END
  114.  
  115. IF t = 1 THEN GOSUB computer:
  116.  
  117. GOTO Go:
  118.  
  119. checkwin:
  120. 'Check to see if you won.
  121. IF a(1) = 1 AND a(2) = 1 AND a(3) = 1 THEN GOTO won:
  122. IF a(4) = 1 AND a(5) = 1 AND a(6) = 1 THEN GOTO won:
  123. IF a(7) = 1 AND a(8) = 1 AND a(9) = 1 THEN GOTO won
  124. IF a(1) = 1 AND a(4) = 1 AND a(7) = 1 THEN GOTO won:
  125. IF a(2) = 1 AND a(5) = 1 AND a(8) = 1 THEN GOTO won:
  126. IF a(3) = 1 AND a(6) = 1 AND a(9) = 1 THEN GOTO won:
  127. IF a(1) = 1 AND a(5) = 1 AND a(9) = 1 THEN GOTO won:
  128. IF a(3) = 1 AND a(5) = 1 AND a(7) = 1 THEN GOTO won:
  129. turn = turn + 1
  130. SOUND 100, .25
  131. IF turn = 9 THEN GOTO catsgame:
  132. GOTO Go:
  133. won:
  134. FOR snd = 300 TO 900 STEP 50
  135.     SOUND snd, .5
  136. NEXT snd
  137. FOR tt = 1 TO 9
  138.     a(tt) = 0
  139.     b(tt) = 0
  140. NEXT tt
  141. you = you + 1
  142. you$ = STR$(you)
  143. computer$ = STR$(computer)
  144. _TITLE "You: " + you$ + "   Computer: " + comp$
  145. t = 0
  146. LOCATE 2, 32: PRINT "Y O U   W I N ! !"
  147. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  148. GOTO playagain:
  149.  
  150. computer:
  151.  
  152. 'Check to win.
  153. 'Last space gone.
  154. IF b(1) = 1 AND b(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  155. IF b(4) = 1 AND b(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  156. IF b(7) = 1 AND b(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  157. IF b(1) = 1 AND b(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  158. IF b(2) = 1 AND b(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  159. IF b(3) = 1 AND b(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  160. IF b(1) = 1 AND b(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  161. IF b(3) = 1 AND b(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  162. 'First space gone.
  163. IF b(2) = 1 AND b(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  164. IF b(5) = 1 AND b(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  165. IF b(8) = 1 AND b(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  166. IF b(4) = 1 AND b(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  167. IF b(5) = 1 AND b(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  168. IF b(6) = 1 AND b(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  169. IF b(5) = 1 AND b(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  170. IF b(7) = 1 AND b(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  171. 'Middle space gone.
  172. IF b(1) = 1 AND b(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  173. IF b(4) = 1 AND b(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  174. IF b(7) = 1 AND b(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  175. IF b(1) = 1 AND b(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  176. IF b(2) = 1 AND b(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  177. IF b(3) = 1 AND b(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  178. IF b(1) = 1 AND b(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  179. IF b(3) = 1 AND b(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  180.  
  181. 'Check to block.
  182. 'Last space gone.
  183. IF a(1) = 1 AND a(2) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  184. IF a(4) = 1 AND a(5) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  185. IF a(7) = 1 AND a(8) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  186. IF a(1) = 1 AND a(4) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  187. IF a(2) = 1 AND a(5) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  188. IF a(3) = 1 AND a(6) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  189. IF a(1) = 1 AND a(5) = 1 AND a(9) = 0 AND b(9) = 0 THEN GOTO compspace9:
  190. IF a(3) = 1 AND a(5) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  191. 'First space gone.
  192. IF a(2) = 1 AND a(3) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  193. IF a(5) = 1 AND a(6) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  194. IF a(8) = 1 AND a(9) = 1 AND a(7) = 0 AND b(7) = 0 THEN GOTO compspace7:
  195. IF a(4) = 1 AND a(7) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  196. IF a(5) = 1 AND a(8) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  197. IF a(6) = 1 AND a(9) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  198. IF a(5) = 1 AND a(9) = 1 AND a(1) = 0 AND b(1) = 0 THEN GOTO compspace1:
  199. IF a(7) = 1 AND a(5) = 1 AND a(3) = 0 AND b(3) = 0 THEN GOTO compspace3:
  200. 'Middle space gone.
  201. IF a(1) = 1 AND a(3) = 1 AND a(2) = 0 AND b(2) = 0 THEN GOTO compspace2:
  202. IF a(4) = 1 AND a(6) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  203. IF a(7) = 1 AND a(9) = 1 AND a(8) = 0 AND b(8) = 0 THEN GOTO compspace8:
  204. IF a(1) = 1 AND a(7) = 1 AND a(4) = 0 AND b(4) = 0 THEN GOTO compspace4:
  205. IF a(2) = 1 AND a(8) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  206. IF a(3) = 1 AND a(9) = 1 AND a(6) = 0 AND b(6) = 0 THEN GOTO compspace6:
  207. IF a(1) = 1 AND a(9) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  208. IF a(3) = 1 AND a(7) = 1 AND a(5) = 0 AND b(5) = 0 THEN GOTO compspace5:
  209.  
  210. 'Computer decides a random space.
  211. computerchoice:
  212. comp = INT(RND * 9) + 1
  213. IF b(comp) = 1 THEN GOTO computerchoice:
  214. IF a(comp) = 1 THEN GOTO computerchoice:
  215. IF comp = 1 THEN GOTO compspace1:
  216. IF comp = 2 THEN GOTO compspace2:
  217. IF comp = 3 THEN GOTO compspace3:
  218. IF comp = 4 THEN GOTO compspace4:
  219. IF comp = 5 THEN GOTO compspace5:
  220. IF comp = 6 THEN GOTO compspace6:
  221. IF comp = 7 THEN GOTO compspace7:
  222. IF comp = 8 THEN GOTO compspace8:
  223. IF comp = 9 THEN GOTO compspace9:
  224.  
  225. 'Cat's Game
  226. catsgame:
  227. FOR snd = 400 TO 300 STEP -25
  228.     SOUND snd, .5
  229. NEXT snd
  230. FOR tt = 1 TO 9
  231.     a(tt) = 0
  232.     b(tt) = 0
  233. NEXT tt
  234. t = 0
  235. COLOR _RGB32(255, 0, 255), _CLEARCOLOR
  236. LOCATE 2, 29: PRINT "Cat's Game - No Winners"
  237. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  238. GOTO playagain:
  239.  
  240. 'Check to see if the computer won.
  241. check:
  242. IF b(1) = 1 AND b(2) = 1 AND b(3) = 1 THEN GOTO compwon:
  243. IF b(4) = 1 AND b(5) = 1 AND b(6) = 1 THEN GOTO compwon:
  244. IF b(7) = 1 AND b(8) = 1 AND b(9) = 1 THEN GOTO compwon
  245. IF b(1) = 1 AND b(4) = 1 AND b(7) = 1 THEN GOTO compwon:
  246. IF b(2) = 1 AND b(5) = 1 AND b(8) = 1 THEN GOTO compwon:
  247. IF b(3) = 1 AND b(6) = 1 AND b(9) = 1 THEN GOTO compwon:
  248. IF b(1) = 1 AND b(5) = 1 AND b(9) = 1 THEN GOTO compwon:
  249. IF b(3) = 1 AND b(5) = 1 AND b(7) = 1 THEN GOTO compwon:
  250. turn = turn + 1
  251. IF turn = 9 THEN GOTO catsgame:
  252. t = 0
  253. GOTO Go:
  254.  
  255. compwon:
  256. FOR snd = 900 TO 300 STEP -50
  257.     SOUND snd, .5
  258. NEXT snd
  259. FOR tt = 1 TO 9
  260.     a(tt) = 0
  261.     b(tt) = 0
  262. NEXT tt
  263. t = 0
  264. computer = computer + 1
  265. you$ = STR$(you)
  266. comp$ = STR$(computer)
  267. _TITLE "You: " + you$ + "   Computer: " + comp$
  268. COLOR _RGB32(128, 255, 255), _CLEARCOLOR
  269. LOCATE 2, 33: PRINT "Computer  Wins"
  270. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  271. GOTO playagain:
  272.  
  273. 'This part draws the computer's circle.
  274. compspace1:
  275. t = 0
  276. b(1) = 1
  277. FOR xx = .1 TO 10 STEP .1
  278.     FOR s = .25 TO 10 STEP .25
  279.         CIRCLE (160 - xx, 130 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  280.     NEXT s
  281. NEXT xx
  282. GOTO check:
  283. compspace2:
  284. t = 0
  285. b(2) = 1
  286. FOR xx = .1 TO 10 STEP .1
  287.     FOR s = .25 TO 10 STEP .25
  288.         CIRCLE (300 - xx, 130 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  289.     NEXT s
  290. NEXT xx
  291. GOTO check:
  292. compspace3:
  293. t = 0
  294. b(3) = 1
  295. FOR xx = .1 TO 10 STEP .1
  296.     FOR s = .25 TO 10 STEP .25
  297.         CIRCLE (440 - xx, 130 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  298.     NEXT s
  299. NEXT xx
  300. GOTO check:
  301. compspace4:
  302. t = 0
  303. b(4) = 1
  304. FOR xx = .1 TO 10 STEP .1
  305.     FOR s = .25 TO 10 STEP .25
  306.         CIRCLE (160 - xx, 250 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  307.     NEXT s
  308. NEXT xx
  309. GOTO check:
  310. compspace5:
  311. t = 0
  312. b(5) = 1
  313. FOR xx = .1 TO 10 STEP .1
  314.     FOR s = .25 TO 10 STEP .25
  315.         CIRCLE (300 - xx, 250 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  316.     NEXT s
  317. NEXT xx
  318. GOTO check:
  319. compspace6:
  320. t = 0
  321. b(6) = 1
  322. FOR xx = .1 TO 10 STEP .1
  323.     FOR s = .25 TO 10 STEP .25
  324.         CIRCLE (440 - xx, 250 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  325.     NEXT s
  326. NEXT xx
  327. GOTO check:
  328. compspace7:
  329. t = 0
  330. b(7) = 1
  331. FOR xx = .1 TO 10 STEP .1
  332.     FOR s = .25 TO 10 STEP .25
  333.         CIRCLE (160 - xx, 365 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  334.     NEXT s
  335. NEXT xx
  336. GOTO check:
  337. compspace8:
  338. t = 0
  339. b(8) = 1
  340. FOR xx = .1 TO 10 STEP .1
  341.     FOR s = .25 TO 10 STEP .25
  342.         CIRCLE (300 - xx, 365 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  343.     NEXT s
  344. NEXT xx
  345. GOTO check:
  346. compspace9:
  347. t = 0
  348. b(9) = 1
  349. FOR xx = .1 TO 10 STEP .1
  350.     FOR s = .25 TO 10 STEP .25
  351.         CIRCLE (440 - xx, 365 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
  352.     NEXT s
  353. NEXT xx
  354. GOTO check:
  355. 'This last part draws your X.
  356. space1:
  357. a(1) = 1
  358. FOR xx = .1 TO 10 STEP .1
  359.     FOR s = .25 TO 10 STEP .25
  360.         LINE (115 + s - xx, 104 - xx)-(195 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  361.         LINE (195 + s - xx, 104 - xx)-(115 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  362.     NEXT s
  363. NEXT xx
  364. t = 1
  365. GOTO checkwin:
  366. space2:
  367. a(2) = 1
  368. FOR xx = .1 TO 10 STEP .1
  369.     FOR s = .25 TO 10 STEP .25
  370.         LINE (255 + s - xx, 104 - xx)-(335 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  371.         LINE (335 + s - xx, 104 - xx)-(255 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  372.     NEXT s
  373. NEXT xx
  374. t = 1
  375. GOTO checkwin:
  376. space3:
  377. a(3) = 1
  378. FOR xx = .1 TO 10 STEP .1
  379.     FOR s = .25 TO 10 STEP .25
  380.         LINE (395 + s - xx, 104 - xx)-(475 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  381.         LINE (475 + s - xx, 104 - xx)-(395 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
  382.     NEXT s
  383. NEXT xx
  384. t = 1
  385. GOTO checkwin:
  386. space4:
  387. a(4) = 1
  388. FOR xx = .1 TO 10 STEP .1
  389.     FOR s = .25 TO 10 STEP .25
  390.         LINE (110 + s - xx, 224 - xx)-(190 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  391.         LINE (190 + s - xx, 224 - xx)-(110 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  392.     NEXT s
  393. NEXT xx
  394. t = 1
  395. GOTO checkwin:
  396. space5:
  397. a(5) = 1
  398. FOR xx = .1 TO 10 STEP .1
  399.     FOR s = .25 TO 10 STEP .25
  400.         LINE (255 + s - xx, 224 - xx)-(335 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  401.         LINE (335 + s - xx, 224 - xx)-(255 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  402.     NEXT s
  403. NEXT xx
  404. t = 1
  405. GOTO checkwin:
  406. space6:
  407. a(6) = 1
  408. FOR xx = .1 TO 10 STEP .1
  409.     FOR s = .25 TO 10 STEP .25
  410.         LINE (395 + s - xx, 224 - xx)-(475 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  411.         LINE (475 + s - xx, 224 - xx)-(395 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
  412.     NEXT s
  413. NEXT xx
  414. t = 1
  415. GOTO checkwin:
  416. space7:
  417. a(7) = 1
  418. FOR xx = .1 TO 10 STEP .1
  419.     FOR s = .25 TO 10 STEP .25
  420.         LINE (110 + s - xx, 339 - xx)-(190 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  421.         LINE (190 + s - xx, 339 - xx)-(110 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  422.     NEXT s
  423. NEXT xx
  424. t = 1
  425. GOTO checkwin:
  426. space8:
  427. a(8) = 1
  428. FOR xx = .1 TO 10 STEP .1
  429.     FOR s = .25 TO 10 STEP .25
  430.         LINE (255 + s - xx, 339 - xx)-(335 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  431.         LINE (335 + s - xx, 339 - xx)-(255 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  432.     NEXT s
  433. NEXT xx
  434. t = 1
  435. GOTO checkwin:
  436. space9:
  437. a(9) = 1
  438. FOR xx = .1 TO 10 STEP .1
  439.     FOR s = .25 TO 10 STEP .25
  440.         LINE (395 + s - xx, 339 - xx)-(475 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  441.         LINE (475 + s - xx, 339 - xx)-(395 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
  442.     NEXT s
  443. NEXT xx
  444. t = 1
  445. GOTO checkwin:
  446.  
  447. playagain:
  448. _PRINTSTRING (220, 55), "Click Here To Play Again"
  449. COLOR _RGB32(255, 255, 255), _RGB32(0, 0, 0)
  450.  
  451.     _LIMIT 60
  452.     mouseWheel = 0
  453.         mouseX = _MOUSEX
  454.         mouseY = _MOUSEY
  455.         mouseLeftButton = _MOUSEBUTTON(1)
  456.         mouseRightButton = _MOUSEBUTTON(2)
  457.         mouseMiddleButton = _MOUSEBUTTON(3)
  458.         mouseWheel = mouseWheel + _MOUSEWHEEL
  459.     LOOP
  460.     ag$ = INKEY$
  461.     IF ag$ = CHR$(27) THEN END
  462.     IF ag$ = " " THEN CLS: GOTO start:
  463.     IF mouseLeftButton = -1 AND mouseX > 220 AND mouseX < 412 AND mouseY > 55 AND mouseY < 69 THEN CLS: GOTO start:
  464.  
TicTacToe.jpg
* TicTacToe.jpg (Filesize: 80.53 KB, Dimensions: 599x503, Views: 98)

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: Tic-Tac-Toe
« Reply #13 on: January 30, 2021, 06:41:15 pm »
Looks like the O’s need to move down a little.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline STxAxTIC

  • Library Staff
  • Forum Resident
  • Posts: 1091
  • he lives
    • View Profile
Re: Tic-Tac-Toe
« Reply #14 on: January 30, 2021, 06:44:27 pm »
Maybe just change the plot order so the X's and O's appear to be "on shelves" - give it a try.
You're not done when it works, you're done when it's right.