Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 tic tac toe help
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
anon656




PostPosted: 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)
Sponsor
Sponsor
Sponsor
sponsor
Insectoid




PostPosted: Thu Jun 08, 2017 6:22 pm   Post subject: RE:tic tac toe help

What have you tried so far?
anon656




PostPosted: 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
anon656




PostPosted: Thu Jun 08, 2017 6:48 pm   Post subject: RE:tic tac toe help

that is what i have so far
Insectoid




PostPosted: Thu Jun 08, 2017 6:51 pm   Post subject: RE:tic tac toe help

What do you want to happen inside those if statements?
anon656




PostPosted: 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.
anon656




PostPosted: Thu Jun 08, 2017 6:55 pm   Post subject: RE:tic tac toe help

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




PostPosted: 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?
Sponsor
Sponsor
Sponsor
sponsor
anon656




PostPosted: Thu Jun 08, 2017 7:12 pm   Post subject: RE:tic tac toe help

so do i set the variables as Boolean?
Insectoid




PostPosted: 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?
anon656




PostPosted: 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
anon656




PostPosted: 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
anon656




PostPosted: 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
anon656




PostPosted: 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.
Insectoid




PostPosted: Thu Jun 08, 2017 8:02 pm   Post subject: RE:tic tac toe help

What have you tried so far to get turns working?
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 18 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: