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

Username:   Password: 
 RegisterRegister   
 Need help with a Tic Tac Toe Program!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
ialoguh




PostPosted: Tue Jul 17, 2012 2:17 pm   Post subject: Need help with a Tic Tac Toe Program!

What is it you are trying to achieve?
I am trying to write a Tic Tac Toe program

What is the problem you are having?
I can't make the program switch turns.

Describe what you have tried to solve this problem
I tried using a even/odd method but every time I do that it just draws the X and the O in the same spot

Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
setscreen ("graphics:600,620")

Draw.Line (0,200,600,200, black)
Draw.Line (0,400,600,400, black)
Draw.Line (200,0,200,600, black)
Draw.Line (400,0,400,600, black)

var xvalue,yvalue,b:int
var count:int:= 0
var turn:boolean

%%%%%%%% procedures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%% changing turns %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure switch
if count mod 2 = 0 then
turn := true
else
turn := false
end if
end switch
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%% drawing x %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure drawx
for x: 0..400 by 200
for y: 0..400 by 200
if xvalue>x and xvalue<x +200 and yvalue>y and yvalue<y + 200 then
Draw.Line (x + 20,y + 20,x + 180,y + 180, black)
Draw.Line (x + 20,y + 180,x + 180,y + 20, black)
end if
end for
end for
end drawx
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%% drawing O %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure drawo
for x: 0..400 by 200
for y: 0..400 by 200
if xvalue>x and xvalue<x +200 and yvalue>y and yvalue<y + 200 then
Draw.Oval (x + 100,y + 100,90,90, black)
end if
end for
end for
end drawo
%%%%%% End Procedures %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%% Start action %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
loop
loop
Mouse.Where (xvalue,yvalue,b)
if b = 1 then
switch
if turn = true then
drawx
count := count + 1
end if
if turn = false then
drawo
count := count + 1
end if
end if
exit when b = 1
end loop
end loop

[/syntax]

Please specify what version of Turing you are using
4.1.1
Sponsor
Sponsor
Sponsor
sponsor
Dreadnought




PostPosted: Tue Jul 17, 2012 2:22 pm   Post subject: Re: Need help with a Tic Tac Toe Program!

Try adding a delay, you're switching turns before you let go of the mouse button.
Zren




PostPosted: Tue Jul 17, 2012 3:50 pm   Post subject: Re: Need help with a Tic Tac Toe Program!

Dreadnought @ Tue Jul 17, 2012 3:22 pm wrote:
Try adding a delay, you're switching turns before you let go of the mouse button.

If that's the problem, then he should be storing the last button state, and comparing them. A delay is an imperfect fix.

Turing:

if not lastMouseState.pressed and currentMouseState.pressed then
    % Mouse was just pressed down
end if
Amarylis




PostPosted: Thu Jul 19, 2012 5:57 am   Post subject: RE:Need help with a Tic Tac Toe Program!

Currently, you don't have anything that tells Turing that your square is blocked off, so although you may be able to stop both turns from going at the same time, you will still be writing both in the same cell.

How could you be able to know if the square had already been drawn to or not? Think of that for a little bit, it'll be useful when you're figuring out how to find out who won as well
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 1  [ 4 Posts ]
Jump to:   


Style:  
Search: