Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
3D Looking Tic-Tac-Toe
#1
I made this a year ago. Smile It uses the mouse and it randomly picks who goes first. 

Code: (Select All)
'I've wanted to make this game for decades and finally am able to!
'This game was made on August 14, 2019 by SierraKen.
'This is Freeware.
'Jan. 28, 2021 update: Choose at random who goes first.
'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,
'and added text colors.
'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!


Dim a(10), b(10)
_Limit 60
_Title "Tic-Tac-Toe     by SierraKen"
Screen _NewImage(600, 480, 32)
Cls
Print: Print: Print
Locate 10, 34: Print "-"
Locate 10, 40: Print "-"
For tic = 1 To 10
    Locate tic, 30: Print "TIC"
    _Delay .1
    Locate tic, 30: Print "   "
Next tic
Locate 10, 30: Print "TIC"
For tac = 20 To 10 Step -1
    Locate tac, 36: Print "TAC"
    _Delay .1
    Locate tac, 36: Print "   "
Next tac
Locate 10, 36: Print "TAC"
For toe = 1 To 10
    Locate toe, 42: Print "TOE"
    _Delay .1
    Locate toe, 42: Print "   "
Next toe
Locate 10, 42: Print "TOE"
computer = 0
you = 0

Print: Print: Print
Print "                              By  SierraKen"
Print: Print: Print
Print "       Play against the computer in this classic game of Tic-Tac-Toe."
Print "                      Whoever gets 3 in a row wins."
Print
Print "                    Choose a sqace by using your mouse."
Print "                     Computer chooses who goes first."

Color _RGB32(255, 255, 255), _ClearColor
_PrintString (220, 430), "Click Here To Start"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)

Do
    _Limit 60
    mouseWheel = 0
    Do While _MouseInput
        mouseX = _MouseX
        mouseY = _MouseY
        mouseLeftButton = _MouseButton(1)
        mouseRightButton = _MouseButton(2)
        mouseMiddleButton = _MouseButton(3)
        mouseWheel = mouseWheel + _MouseWheel
    Loop
    ag$ = InKey$
    If ag$ = Chr$(27) Then End
    If ag$ = " " Then Cls: GoTo start:
    If mouseLeftButton = -1 And mouseX > 220 And mouseX < 370 And mouseY > 430 And mouseY < 446 Then Cls: GoTo start:
Loop

start:
ag$ = ""
t = 0
turn = 0
comp = 0

For cc = 0 To 480
    cl = cl + .5
    Line (0, cc)-(640, cc), _RGB32(0, 0, cl)
Next cc
cl = 0
Randomize Timer
c1 = Int(Rnd * 155) + 100
c2 = Int(Rnd * 155) + 100
c3 = Int(Rnd * 155) + 100

GoSub grid:

whosfirst:
Randomize Timer
first = Int(Rnd * 2) + 1
If first = 1 Then GoTo computerchoice:

Go:
_Limit 60
a$ = InKey$
If a$ = Chr$(27) Then End
mouseWheel = 0
Do While _MouseInput
    mouseX = _MouseX
    mouseY = _MouseY
    mouseLeftButton = _MouseButton(1)
    mouseRightButton = _MouseButton(2)
    mouseMiddleButton = _MouseButton(3)
    mouseWheel = mouseWheel + _MouseWheel
Loop

If mouseLeftButton = -1 Then
    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:
    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:
    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:
    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:
    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:
    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:
    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:
    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:
    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:
End If

If mouseLeftButton = -1 And ending = 1 Then GoTo start:
If mouseRightButton = -1 And ending = 1 Then End

If t = 1 Then GoSub computer:

GoTo Go:

checkwin:
'Check to see if you won.
If a(1) = 1 And a(2) = 1 And a(3) = 1 Then GoTo won:
If a(4) = 1 And a(5) = 1 And a(6) = 1 Then GoTo won:
If a(7) = 1 And a(8) = 1 And a(9) = 1 Then GoTo won
If a(1) = 1 And a(4) = 1 And a(7) = 1 Then GoTo won:
If a(2) = 1 And a(5) = 1 And a(8) = 1 Then GoTo won:
If a(3) = 1 And a(6) = 1 And a(9) = 1 Then GoTo won:
If a(1) = 1 And a(5) = 1 And a(9) = 1 Then GoTo won:
If a(3) = 1 And a(5) = 1 And a(7) = 1 Then GoTo won:
turn = turn + 1
Sound 100, .25
If turn = 9 Then GoTo catsgame:
GoTo Go:
won:
For snd = 300 To 900 Step 50
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
you = you + 1
you$ = Str$(you)
computer$ = Str$(computer)
_Title "You: " + you$ + "   Computer: " + comp$
t = 0
Color _RGB32(255, 0, 0), _ClearColor
Locate 2, 32: Print "Y O U   W I N ! !"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

computer:

'Check to win.
'Last space gone.
If b(1) = 1 And b(2) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If b(4) = 1 And b(5) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If b(7) = 1 And b(8) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(1) = 1 And b(4) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If b(2) = 1 And b(5) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If b(3) = 1 And b(6) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(1) = 1 And b(5) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If b(3) = 1 And b(5) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
'First space gone.
If b(2) = 1 And b(3) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(5) = 1 And b(6) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If b(8) = 1 And b(9) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If b(4) = 1 And b(7) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(5) = 1 And b(8) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If b(6) = 1 And b(9) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If b(5) = 1 And b(9) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If b(7) = 1 And b(5) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
'Middle space gone.
If b(1) = 1 And b(3) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If b(4) = 1 And b(6) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(7) = 1 And b(9) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If b(1) = 1 And b(7) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If b(2) = 1 And b(8) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(3) = 1 And b(9) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If b(1) = 1 And b(9) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If b(3) = 1 And b(7) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:

'Check to block.
'Last space gone.
If a(1) = 1 And a(2) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If a(4) = 1 And a(5) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If a(7) = 1 And a(8) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(1) = 1 And a(4) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If a(2) = 1 And a(5) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If a(3) = 1 And a(6) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(1) = 1 And a(5) = 1 And a(9) = 0 And b(9) = 0 Then GoTo compspace9:
If a(3) = 1 And a(5) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
'First space gone.
If a(2) = 1 And a(3) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(5) = 1 And a(6) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If a(8) = 1 And a(9) = 1 And a(7) = 0 And b(7) = 0 Then GoTo compspace7:
If a(4) = 1 And a(7) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(5) = 1 And a(8) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If a(6) = 1 And a(9) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
If a(5) = 1 And a(9) = 1 And a(1) = 0 And b(1) = 0 Then GoTo compspace1:
If a(7) = 1 And a(5) = 1 And a(3) = 0 And b(3) = 0 Then GoTo compspace3:
'Middle space gone.
If a(1) = 1 And a(3) = 1 And a(2) = 0 And b(2) = 0 Then GoTo compspace2:
If a(4) = 1 And a(6) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(7) = 1 And a(9) = 1 And a(8) = 0 And b(8) = 0 Then GoTo compspace8:
If a(1) = 1 And a(7) = 1 And a(4) = 0 And b(4) = 0 Then GoTo compspace4:
If a(2) = 1 And a(8) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(3) = 1 And a(9) = 1 And a(6) = 0 And b(6) = 0 Then GoTo compspace6:
If a(1) = 1 And a(9) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:
If a(3) = 1 And a(7) = 1 And a(5) = 0 And b(5) = 0 Then GoTo compspace5:

'Computer decides a random space.
computerchoice:
Randomize Timer
comp = Int(Rnd * 9) + 1
If b(comp) = 1 Then GoTo computerchoice:
If a(comp) = 1 Then GoTo computerchoice:
If comp = 1 Then GoTo compspace1:
If comp = 2 Then GoTo compspace2:
If comp = 3 Then GoTo compspace3:
If comp = 4 Then GoTo compspace4:
If comp = 5 Then GoTo compspace5:
If comp = 6 Then GoTo compspace6:
If comp = 7 Then GoTo compspace7:
If comp = 8 Then GoTo compspace8:
If comp = 9 Then GoTo compspace9:

'Cat's Game
catsgame:
For snd = 400 To 300 Step -25
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
t = 0
Color _RGB32(255, 0, 255), _ClearColor
Locate 2, 29: Print "Cat's Game - No Winners"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

'Check to see if the computer won.
check:
If b(1) = 1 And b(2) = 1 And b(3) = 1 Then GoTo compwon:
If b(4) = 1 And b(5) = 1 And b(6) = 1 Then GoTo compwon:
If b(7) = 1 And b(8) = 1 And b(9) = 1 Then GoTo compwon
If b(1) = 1 And b(4) = 1 And b(7) = 1 Then GoTo compwon:
If b(2) = 1 And b(5) = 1 And b(8) = 1 Then GoTo compwon:
If b(3) = 1 And b(6) = 1 And b(9) = 1 Then GoTo compwon:
If b(1) = 1 And b(5) = 1 And b(9) = 1 Then GoTo compwon:
If b(3) = 1 And b(5) = 1 And b(7) = 1 Then GoTo compwon:
turn = turn + 1
If turn = 9 Then GoTo catsgame:
t = 0
GoTo Go:

compwon:
For snd = 900 To 300 Step -50
    Sound snd, .5
Next snd
For tt = 1 To 9
    a(tt) = 0
    b(tt) = 0
Next tt
t = 0
computer = computer + 1
you$ = Str$(you)
comp$ = Str$(computer)
_Title "You: " + you$ + "   Computer: " + comp$
Color _RGB32(128, 255, 255), _ClearColor
Locate 2, 33: Print "Computer  Wins"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)
GoTo playagain:

'This part draws the computer's circle.
compspace1:
t = 0
b(1) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace2:
t = 0
b(2) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace3:
t = 0
b(3) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 140 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace4:
t = 0
b(4) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace5:
t = 0
b(5) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace6:
t = 0
b(6) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 260 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoSub grid:
GoTo check:
compspace7:
t = 0
b(7) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (160 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
compspace8:
t = 0
b(8) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (300 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
compspace9:
t = 0
b(9) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Circle (440 - xx, 375 - xx), 40 - s, _RGB32(255 - (xx * 10), 0, 0)
    Next s
Next xx
GoTo check:
'This last part draws your X.
space1:
a(1) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (115 + s - xx, 104 - xx)-(195 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (195 + s - xx, 104 - xx)-(115 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space2:
a(2) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 104 - xx)-(335 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 104 - xx)-(255 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space3:
a(3) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 104 - xx)-(475 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 104 - xx)-(395 + s - xx, 169 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space4:
a(4) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (110 + s - xx, 224 - xx)-(190 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (190 + s - xx, 224 - xx)-(110 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space5:
a(5) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 224 - xx)-(335 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 224 - xx)-(255 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space6:
a(6) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 224 - xx)-(475 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 224 - xx)-(395 + s - xx, 289 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space7:
a(7) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (110 + s - xx, 339 - xx)-(190 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (190 + s - xx, 339 - xx)-(110 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space8:
a(8) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (255 + s - xx, 339 - xx)-(335 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (335 + s - xx, 339 - xx)-(255 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:
space9:
a(9) = 1
For xx = .1 To 10 Step .1
    For s = .25 To 10 Step .25
        Line (395 + s - xx, 339 - xx)-(475 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
        Line (475 + s - xx, 339 - xx)-(395 + s - xx, 404 - xx), _RGB32(0, 255 - (xx * 10), 0)
    Next s
Next xx
t = 1
GoTo checkwin:

playagain:
Color _RGB32(255, 0, 0), _ClearColor
_PrintString (220, 55), "Click Here To Play Again"
Color _RGB32(255, 255, 255), _RGB32(0, 0, 0)

Do
    _Limit 60
    mouseWheel = 0
    Do While _MouseInput
        mouseX = _MouseX
        mouseY = _MouseY
        mouseLeftButton = _MouseButton(1)
        mouseRightButton = _MouseButton(2)
        mouseMiddleButton = _MouseButton(3)
        mouseWheel = mouseWheel + _MouseWheel
    Loop
    ag$ = InKey$
    If ag$ = Chr$(27) Then End
    If ag$ = " " Then Cls: GoTo start:
    If mouseLeftButton = -1 And mouseX > 220 And mouseX < 412 And mouseY > 55 And mouseY < 69 Then Cls: GoTo start:
Loop

grid:
'Draw Grid
'Vertical Lines
For xx = .1 To 15 Step .1
    Line (220 - xx, 100 - xx)-(240 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
    Line (360 - xx, 100 - xx)-(380 - xx, 410 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
Next xx
For xx = .1 To 15 Step .1
    'Horizontal Lines
    Line (90 - xx, 185 - xx)-(510 - xx, 205 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
    Line (90 - xx, 305 - xx)-(510 - xx, 325 - xx), _RGB32(c1 - (xx * 10), c2 - (xx * 10), c3 - (xx * 10)), BF
Next xx
Return
Reply
#2
nice job
Reply
#3
Thanks!
Reply




Users browsing this thread: 1 Guest(s)