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
Index -> Programming, Turing -> Turing Submissions
View previous topic Printable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
endusto




PostPosted: Sat Feb 11, 2006 3:19 pm   Post subject: tic tac toe

i realise theres probably a few better tic tac toe games here and that this one could easily be changed to half the size but oh well. heres my tic tac toe game
code:

% TIC TAC TOE
% PROGRAMMED BY: ANDREW COWAN

var x, y, buttonnumber, buttonupdown, buttons, font, p1turn, p2turn : int
var sq1, sq2, sq3, sq4, sq5, sq6, sq7, sq8, sq9, sq1taken, sq2taken, sq3taken,
sq4taken, sq5taken, sq6taken, sq7taken, sq8taken, sq9taken, sq1taken2, sq2taken2,
sq3taken2, sq4taken2, sq5taken2, sq6taken2, sq7taken2, sq8taken2, sq9taken2, sq1taken3,
sq2taken3, sq3taken3, sq4taken3, sq5taken3, sq6taken3, sq7taken3, sq8taken3,
sq9taken3, win : int := 0
var ch : string(1)
font := Font.New ("hooplah:36")
setscreen ("graphics:400,400, nobuttonbar")
p1turn := 1
p2turn := 0
% DRAW THE PLAYING FIELD
Draw.FillBox (maxx, maxy, 0, 0, 254)
Draw.FillBox (135, 0, 131, maxy, 2)
Draw.FillBox (268, 0, 264, maxy, 2)
Draw.FillBox (0, 135, maxx, 131, 2)
Draw.FillBox (0, 268, maxx, 264, 2)

% EXECUTE THIS IF SOMEONE WINS

process gg()

put "Play again? Y/N"
getch(ch)
if ch = "y" or ch = "Y" then
cls
Draw.FillBox (maxx, maxy, 0, 0, 254)
Draw.FillBox (135, 0, 131, maxy, 2)
Draw.FillBox (268, 0, 264, maxy, 2)
Draw.FillBox (0, 135, maxx, 131, 2)
Draw.FillBox (0, 268, maxx, 264, 2)

sq1 := 0
sq2 := 0
sq3 := 0
sq4 := 0
sq5 := 0
sq6 := 0
sq7 := 0
sq8 := 0
sq9 := 0
sq1taken  := 0
sq2taken  := 0
sq3taken  := 0
sq4taken  := 0
sq5taken  := 0
sq6taken  := 0
sq7taken  := 0
sq8taken  := 0
sq9taken  := 0

sq1taken2  := 0
sq2taken2  := 0
sq3taken2  := 0
sq4taken2  := 0
sq5taken2  := 0
sq6taken2  := 0
sq7taken2  := 0
sq8taken2  := 0
sq9taken2  := 0

sq1taken3  := 0
sq2taken3  := 0
sq3taken3  := 0
sq1taken3  := 0
sq2taken3  := 0
sq3taken3  := 0
sq4taken3  := 0
sq5taken3  := 0
sq6taken3  := 0
sq7taken3  := 0
sq8taken3  := 0
sq9taken3  := 0

win := 0
else
put ":("
end if
end gg


loop
% WAIT FOR MOUSE BUTTON TO BE PRESSED
buttonwait("down", x, y, buttonnumber, buttonupdown)



% DETECT CLICK FOR ALL SQUARES

% DETECT SQUARE 1
if x >= 0 and x <= 133 and y >= 268  and sq1taken = 0 and sq1taken2 = 0 and win not= 1 then
if p1turn = 1 and sq1taken = 0 then
Draw.Text ("X", 50, 320, font, red)
sq1taken := 1
sq1taken3 := 1
p1turn := 0
p2turn := 1
elsif p2turn = 1  and sq1taken = 0 and sq1taken2 = 0 and win not= 1  then
Draw.Text ("O", 50, 320, font, blue)
sq1taken2 := 1
sq1taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 2
if x >= 134 and x <= 266 and y >= 268   and sq2taken = 0 and sq2taken2 = 0 and win not= 1  then
if p1turn = 1 and sq2taken = 0 then
Draw.Text ("X", 175, 320, font, red)
sq2taken := 1
sq2taken3 := 1
p1turn := 0
p2turn := 1
elsif p2turn = 1 and sq2taken = 0  and win not= 1 then
Draw.Text ("O", 175, 320, font, blue)
sq2taken2 := 1
sq2taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 3
if x >= 267 and x <= maxx and y >= 268  and sq3taken = 0 and sq3taken2 = 0  and win not= 1 then
if p1turn = 1 and sq3taken = 0 then
Draw.Text ("X", 300, 320, font, red)
sq3taken := 1
sq3taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1  and sq3taken = 0 and sq3taken2 = 0  and win not= 1 then
Draw.Text ("O", 300, 320, font, blue)
sq3taken2 := 1
sq3taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 4
if x >= 0 and x <= 133 and y <= 268 and y >= 135   and sq4taken = 0 and sq4taken2 = 0  and win not= 1 then
if p1turn = 1 and sq4taken = 0 then
Draw.Text ("X", 50, 175, font, red)
sq4taken := 1
sq4taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq4taken = 0 and sq4taken2 = 0  and win not= 1 then
Draw.Text ("O", 50, 175, font, blue)
sq4taken2 := 1
sq4taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 5
if x >= 134 and x <= 268 and y >= 135 and y <= 268 and sq5taken = 0 and sq5taken2 = 0  and win not= 1 then
if p1turn = 1 and sq5taken = 0 then
Draw.Text ("X", 175, 175, font, red)
sq5taken := 1
sq5taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq5taken = 0 and sq5taken2 = 0  and win not= 1 then
Draw.Text ("O", 175, 175, font, blue)
sq5taken2 := 1
sq5taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 6
if x >= 267 and x <= maxx and y >= 135 and y <= 268  and sq6taken = 0 and sq6taken2 = 0  and win not= 1 then
if p1turn = 1 and sq6taken = 0 then
Draw.Text ("X", 300, 175, font, red)
sq6taken := 1
sq6taken3 := 6
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq6taken = 0 and sq6taken2 = 0  and win not= 1 then
Draw.Text ("O", 300, 175, font, blue)
sq6taken2 := 1
sq6taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 7
if x >= 0 and x <= 133 and y >= 0 and y <= 134  and sq7taken = 0 and sq7taken2 = 0  and win not= 1 then
if p1turn = 1 and sq7taken = 0 then
Draw.Text ("X", 50, 50, font, red)
sq7taken := 1
sq7taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq7taken = 0 and sq7taken2 = 0 and win not= 1  then
Draw.Text ("O", 50, 50, font, blue)
sq7taken2 := 1
sq7taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 8
if x >= 134 and x <= 268 and y >= 0 and y <= 134  and sq8taken = 0 and sq8taken2 = 0  and win not= 1 then
if p1turn = 1 and sq8taken = 0 then
Draw.Text ("X", 175, 50, font, red)
sq8taken := 1
sq8taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq8taken = 0 and sq8taken2 = 0  and win not= 1 then
Draw.Text ("O", 175, 50, font, blue)
sq8taken2 := 1
sq8taken3 := 1
p1turn := 1
p2turn := 0
end if
end if

% DETECT SQUARE 9
if x >= 268 and x <= maxx and y >= 0 and y <= 134  and sq9taken = 0 and sq9taken2 = 0  and win not= 1 then
if p1turn = 1 and sq9taken = 0 then
Draw.Text ("X", 300, 50, font, red)
sq9taken := 1
sq9taken3 := 1
p1turn := 0
p2turn := 1
end if
if p2turn = 1 and sq9taken = 0 and sq9taken2 = 0 and win not= 1  then
Draw.Text ("O", 300, 50, font, blue)
sq9taken2 := 1
sq9taken3 := 1
p1turn := 1
p2turn := 0
end if
end if




% CHECK IF PLAYER 1 WINS
if sq1taken = 1 and sq2taken = 1 and sq3taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq4taken = 1 and sq5taken = 1 and sq6taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq7taken = 1 and sq8taken = 1 and sq9taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq1taken = 1 and sq5taken = 1 and sq9taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq3taken = 1 and sq5taken = 1 and sq7taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq1taken = 1 and sq4taken = 1 and sq7taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq2taken = 1 and sq5taken = 1 and sq8taken = 1 then
put "X's win!"
fork gg()
win := 1
end if
if sq3taken = 1 and sq6taken = 1 and sq9taken = 1 then
put "X's win!"
fork gg()
win := 1
end if



% CHECK IF PLAYER 2 WINS
if sq1taken2 = 1 and sq2taken2 = 1 and sq3taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq4taken2 = 1 and sq5taken2 = 1 and sq6taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq7taken2 = 1 and sq8taken2 = 1 and sq9taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq1taken2 = 1 and sq5taken2 = 1 and sq9taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq3taken2 = 1 and sq5taken2 = 1 and sq7taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq1taken2 = 1 and sq4taken2 = 1 and sq7taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq2taken2 = 1 and sq5taken2 = 1 and sq8taken2 = 1 and win not= 1 then
put "O's win!"
fork gg()
win := 1
end if
if sq3taken2 = 1 and sq6taken2 = 1 and sq9taken2 = 1and win not= 1  then
put "O's win!"
fork gg()
win := 1
end if
% CHECK IF NOBODY WINS
if sq1taken3 = 1 and sq2taken3 = 1 and sq3taken3 = 1 and sq4taken3 = 1 and sq5taken3 = 1
and sq6taken3 = 1 and sq7taken3 = 1 and sq8taken3 = 1 and sq9taken3 = 1 and win not= 1 then
put "It's a tie!"
fork gg()
win := 1
end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sat Feb 11, 2006 3:26 pm   Post subject: (No subject)

Woah...
-Indent your code!
-Use Mouse.Where() instead of buttonwait()
-Learn arrays!
-Use for loops!
Check for this stuff at the Turing Walkthrough.
endusto




PostPosted: Sat Feb 11, 2006 3:28 pm   Post subject: (No subject)

lol i know, ive only used turing for about 3 days last year, now i just used it for the first time in a year today
Andy




PostPosted: Sat Feb 11, 2006 4:43 pm   Post subject: (No subject)

i think catalyst was it? did it in 20 lines haha.. but its a good start
batman




PostPosted: Thu Mar 02, 2006 9:36 pm   Post subject: Tic Tac Toe Game

Awesome Tic Tac Toe game. I like how you used different colours for your game. You know what would make your game even better? IF you kept the score of the two players x and o.
Delos




PostPosted: Thu Mar 02, 2006 9:43 pm   Post subject: (No subject)

Thank you for you comments batman. Now take a careful look at the dates in this post. The last was made last month - about 3 weeks ago! This is an old topic, turn-over time in [Turing Help], [Turing Source], and even [Turing Applications] is rather low. In other words, if you see an old-ish topic, you're better off PM'ing the user if you have specific comments.
batman




PostPosted: Thu Mar 02, 2006 9:53 pm   Post subject: tic tac toe game

Oh ok! Thanks for the information Delos I didn't know that.
gogeunks1




PostPosted: Tue Jan 13, 2009 6:13 pm   Post subject: Re: tic tac toe

Can someone explain me the part about the procedures??? Rolling Eyes Sad
Sponsor
Sponsor
Sponsor
sponsor
syntax_error




PostPosted: Tue Jan 13, 2009 7:16 pm   Post subject: RE:tic tac toe

What dont you get? What they are or how to use them?
Parker




PostPosted: Wed Jan 14, 2009 9:00 am   Post subject: RE:tic tac toe

Great game, the code is another thing but gameplay is fine Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Submissions
View previous topic Tell A FriendPrintable versionDownload TopicRate TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: