Computer Science Canada

tic tac toe help

Author:  anon656 [ Thu Jun 08, 2017 6:08 pm ]
Post subject:  tic tac toe help

I am trying to make a two player tic tac toe game but it seems that I cannot figure out how to fill in the spaces with X or O, each time switching when one is entered.

this is my tic tac toe board

var mainWin : int := Window.Open ("position:middle;center,graphics:800;650,nobuttonbar,title:tic-tac-toe")
Draw.ThickLine (300, 100, 300, 550, 10, 7)
Draw.ThickLine (500, 100, 500, 550, 10, 7)
Draw.ThickLine (100, 400, 700, 400, 10, 7)
Draw.ThickLine (100, 250, 700, 250, 10, 7)

Author:  Insectoid [ Thu Jun 08, 2017 6:22 pm ]
Post subject:  RE:tic tac toe help

What have you tried so far?

Author:  anon656 [ Thu Jun 08, 2017 6:45 pm ]
Post subject:  RE:tic tac toe help

var picX,picO,x, y, button : int
picX:=Pic.FileNew ("picX.jpg")
picO:=Pic.FileNew ("picO.jpg")
Draw.ThickLine (300, 100, 300, 550, 10, 7)
Draw.ThickLine (500, 100, 500, 550, 10, 7)
Draw.ThickLine (100, 400, 700, 400, 10, 7)
Draw.ThickLine (100, 250, 700, 250, 10, 7)
loop
Mouse.Where (x, y, button)
if button = 1 then
if x >= 100 and x <=300 and y >= 100 and y <= 250 then

elsif x >= 300 and x < 500 and y >= 100 and y <= 250 then

elsif x >= 500 and x < 700 and y >= 100 and y <= 250 then

elsif x >= 100 and x < 300 and y >= 250 and y <= 400 then

elsif x >= 300 and x < 500 and y >= 250 and y <= 400 then

elsif x >= 500 and x < 700 and y >= 250 and y <= 400 then

elsif x >= 100 and x < 300 and y >= 400 and y <= 550 then

elsif x >= 300 and x < 500 and y >= 400 and y <= 550 then

elsif x >= 500 and x < 700 and y >= 400 and y <= 550 then

end if
end if
end loop

Author:  anon656 [ Thu Jun 08, 2017 6:48 pm ]
Post subject:  RE:tic tac toe help

that is what i have so far

Author:  Insectoid [ Thu Jun 08, 2017 6:51 pm ]
Post subject:  RE:tic tac toe help

What do you want to happen inside those if statements?

Author:  anon656 [ Thu Jun 08, 2017 6:54 pm ]
Post subject:  RE:tic tac toe help

display X or O but the problem is that i don't know how to make picX or picO switch. Also how do I make the program determine if the space is filled in.

Author:  anon656 [ Thu Jun 08, 2017 6:55 pm ]
Post subject:  RE:tic tac toe help

sorry about my wording. Im not a perfect English speaker.

Author:  Insectoid [ Thu Jun 08, 2017 7:07 pm ]
Post subject:  RE:tic tac toe help

You've got 9 squares in tic tac toe. Why don't we start with 9 variables that store the state of each square?

Author:  anon656 [ Thu Jun 08, 2017 7:12 pm ]
Post subject:  RE:tic tac toe help

so do i set the variables as Boolean?

Author:  Insectoid [ Thu Jun 08, 2017 7:25 pm ]
Post subject:  RE:tic tac toe help

Why don't you try it and see how it goes?

Author:  anon656 [ Thu Jun 08, 2017 7:42 pm ]
Post subject:  RE:tic tac toe help

var a1, a2, a3, b1, b2, b3, c1, c2, c3 : boolean := false

Author:  anon656 [ Thu Jun 08, 2017 7:43 pm ]
Post subject:  RE:tic tac toe help

when the space is filled it will be set as true

Author:  anon656 [ Thu Jun 08, 2017 7:52 pm ]
Post subject:  RE:tic tac toe help

var picX, picO, x, y, button : int
var a1, a2, a3, b1, b2, b3, c1, c2, c3 : boolean := false
picX := Pic.FileNew ("picX.jpg")
picO := Pic.FileNew ("picO.jpg")
Draw.ThickLine (300, 100, 300, 550, 10, 7)
Draw.ThickLine (500, 100, 500, 550, 10, 7)
Draw.ThickLine (100, 400, 700, 400, 10, 7)
Draw.ThickLine (100, 250, 700, 250, 10, 7)
loop
Mouse.Where (x, y, button)
if button = 1 then
if x >= 100 and x <= 300 and y >= 100 and y <= 250 and a1=false then
Pic.Draw (picX, 150, 120, picCopy)
a1:=true
elsif x >= 300 and x < 500 and y >= 100 and y <= 250 a2=false then
Pic.Draw (picX, 350, 120, picCopy)
a2:=true
elsif x >= 500 and x < 700 and y >= 100 and y <= 250 a3=false then
Pic.Draw (picX, 550, 120, picCopy)
a3:=true
elsif x >= 100 and x < 300 and y >= 250 and y <= 400 b1=falsethen
Pic.Draw (picX, 150, 275, picCopy)
b1:=true
elsif x >= 300 and x < 500 and y >= 250 and y <= 400 b2=false then
Pic.Draw (picX, 350, 275, picCopy)
b2:=true
elsif x >= 500 and x < 700 and y >= 250 and y <= 400 b3=false then
Pic.Draw (picX, 550, 275, picCopy)
b3:=true
elsif x >= 100 and x < 300 and y >= 400 and y <= 550 c1=falsethen
Pic.Draw (picX, 150, 430, picCopy)
c1:=true
elsif x >= 300 and x < 500 and y >= 400 and y <= 550 c2=falsethen
Pic.Draw (picX, 350, 430, picCopy)
c2:=true
elsif x >= 500 and x < 700 and y >= 400 and y <= 550c3=false then
Pic.Draw (picX, 550, 430, picCopy)
c3:=true
end if
end if
end loop

Author:  anon656 [ Thu Jun 08, 2017 7:55 pm ]
Post subject:  RE:tic tac toe help

I am done the thing that checks if the space is filled. I need help with the turns now.
Can you also check if what I did is right? Thank you for the help and your patience.

Author:  Insectoid [ Thu Jun 08, 2017 8:02 pm ]
Post subject:  RE:tic tac toe help

What have you tried so far to get turns working?

Author:  anon656 [ Thu Jun 08, 2017 8:23 pm ]
Post subject:  RE:tic tac toe help

Turing:
var a1, a2, a3, b1, b2, b3, c1, c2, c3 : boolean := false
var turn : boolean := false %true for X and false for O
var turns : int := 1
var mainWin : int := Window.Open ("position:middle;center,graphics:800;650,nobuttonbar,title:tic-tac-toe")

proc userturns
if turns mod 2 = 0 then
turn := true
else
turn := false
end if
end userturns

proc userInput
userturns
var picX, picO, x, y, button : int
picX := Pic.FileNew ("picX.jpg")
picO := Pic.FileNew ("picO.jpg")
Draw.ThickLine (300, 100, 300, 550, 10, 7)
Draw.ThickLine (500, 100, 500, 550, 10, 7)
Draw.ThickLine (100, 400, 700, 400, 10, 7)
Draw.ThickLine (100, 250, 700, 250, 10, 7)
loop
Mouse.Where (x, y, button)
if button = 1 then
if x >= 100 and x <= 300 and y >= 100 and y <= 250 and a1 = false then
if turn = true then
Pic.Draw (picX, 150, 120, picCopy)
turn := false
else
Pic.Draw (picO, 150, 120, picCopy)
turn := true
end if
a1 := true
elsif x >= 300 and x < 500 and y >= 100 and y <= 250 and a2 = false then
if turn = true then
Pic.Draw (picX, 350, 120, picCopy)
turn := false
else
Pic.Draw (picO, 350, 120, picCopy)
turn := true
end if
a2 := true
elsif x >= 500 and x < 700 and y >= 100 and y <= 250 and a3 = false then
if turn = true then
Pic.Draw (picX, 550, 120, picCopy)
turn := false
else
Pic.Draw (picO, 550, 120, picCopy)
turn := true
end if
a3 := true
elsif x >= 100 and x < 300 and y >= 250 and y <= 400 and b1 = false then
if turn = true then
Pic.Draw (picX, 150, 275, picCopy)
turn := false
else
Pic.Draw (picO, 150, 275, picCopy)
turn := true
end if
b1 := true
elsif x >= 300 and x < 500 and y >= 250 and y <= 400 and b2 = false then
if turn = true then
Pic.Draw (picX, 350, 275, picCopy)
turn := false
else
Pic.Draw (picO, 350, 275, picCopy)
turn := true
end if
b2 := true
elsif x >= 500 and x < 700 and y >= 250 and y <= 400 and b3 = false then
if turn = true then
Pic.Draw (picX, 550, 275, picCopy)
turn := false
else
Pic.Draw (picO, 550, 275, picCopy)
turn := true
end if
b3 := true
elsif x >= 100 and x < 300 and y >= 400 and y <= 550 and c1 = false then
if turn = true then
Pic.Draw (picX, 150, 430, picCopy)
turn := false
else
Pic.Draw (picO, 150, 430, picCopy)
turn := true
end if
c1 := true
elsif x >= 300 and x < 500 and y >= 400 and y <= 550 and c2 = false then
if turn = true then
Pic.Draw (picX, 350, 430, picCopy)
turn := false
else
Pic.Draw (picO, 350, 430, picCopy)
turn := true
end if
c2 := true
elsif x >= 500 and x < 700 and y >= 400 and y <= 550 and c3 = false then
Pic.Draw (picX, 550, 430, picCopy)
if turn = true then
Pic.Draw (picX, 550, 430, picCopy)
turn := false
else
Pic.Draw (picO, 550, 430, picCopy)
turn := true
end if
c3 := true
end if
end if
end loop
end userInput
userInput

Author:  anon656 [ Thu Jun 08, 2017 8:27 pm ]
Post subject:  RE:tic tac toe help

How can i make something that figures out who wins?

Author:  Insectoid [ Fri Jun 09, 2017 4:20 am ]
Post subject:  RE:tic tac toe help

How do you win a game of tic tac toe?


: