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

Username:   Password: 
 RegisterRegister   
 Help wiht Tic Tac Toe Checking
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Ennsy_908




PostPosted: Tue May 22, 2007 8:58 am   Post subject: Help wiht Tic Tac Toe Checking

Im making a Tic Tac Toe Program for class and i dont know how to get the program to check if there is a win

here's the code
Turing:

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%                                         Tic Tac Toe                                         %
%                                    Created by: Chris Enns                                   %
%                                          ICS 3M1                                            %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
var location : int

proc GameBoard %Draws Game Board
    Draw.ThickLine (325, 150, 580, 150, 5, 16)  % Bottom Horizontal Line
    Draw.ThickLine (410, 65, 410, 320, 5, 16)  % Left Vertical Line
    Draw.ThickLine (495, 65, 495, 320, 5, 16)  % Right Vertical Line
    Draw.ThickLine (325, 235, 580, 235, 5, 16)  % Top Horizontal Line
end GameBoard
proc XBL % Draws X in bottom left spot
    Draw.ThickLine (335, 140, 400, 70, 3, 12)
    Draw.ThickLine (335, 70, 400, 140, 3, 12)
end XBL

proc XBM % Draws X in bottom middle spot
    Draw.ThickLine (420, 140, 485, 70, 3, 12)
    Draw.ThickLine (420, 70, 485, 140, 3, 12)
end XBM

proc XBR % Draws X in bottom right spot
    Draw.ThickLine (505, 140, 570, 70, 3, 12)
    Draw.ThickLine (505, 70, 570, 140, 3, 12)
end XBR

proc XML % Draws X in middle left spot
    Draw.ThickLine (335, 225, 400, 160, 3, 12)
    Draw.ThickLine (335, 160, 400, 225, 3, 12)
end XML

proc XM % Draws X in middle spot
    Draw.ThickLine (420, 225, 485, 160, 3, 12)
    Draw.ThickLine (420, 160, 485, 225, 3, 12)
end XM

proc XMR % Draws X in middle right spot
    Draw.ThickLine (505, 225, 580, 160, 3, 12)
    Draw.ThickLine (505, 160, 580, 225, 3, 12)
end XMR

proc XTL % Draws X in top left spot
    Draw.ThickLine (335, 315, 400, 245, 3, 12)
    Draw.ThickLine (335, 246, 400, 315, 3, 12)
end XTL

proc XTM % Draws X in top middle spot
    Draw.ThickLine (420, 315, 485, 245, 3, 12)
    Draw.ThickLine (420, 245, 485, 315, 3, 12)
end XTM

proc XTR % Draws X in top right spot
    Draw.ThickLine (505, 315, 580, 245, 3, 12)
    Draw.ThickLine (505, 245, 580, 315, 3, 12)
end XTR

proc OBL % Draw O in bottom left spot
    Draw.Oval (367, 107, 30, 30, blue)
    Draw.Oval (367, 107, 37, 37, blue)
    Draw.Fill (367, 140, blue, blue)
end OBL

proc OBM % Draws O in bottom middle spot
    Draw.Oval (452, 107, 30, 30, blue)
    Draw.Oval (452, 107, 37, 37, blue)
    Draw.Fill (452, 140, blue, blue)
end OBM

proc OBR % Draws O in bottom right spot
    Draw.Oval (537, 107, 30, 30, blue)
    Draw.Oval (537, 107, 37, 37, blue)
    Draw.Fill (537, 140, blue, blue)
end OBR

proc OML % Draws O in middle left spot
    Draw.Oval (367, 192, 30, 30, blue)
    Draw.Oval (367, 192, 37, 37, blue)
    Draw.Fill (367, 223, blue, blue)
end OML

proc OM % Draws O in middle spot
    Draw.Oval (452, 192, 30, 30, blue)
    Draw.Oval (452, 192, 37, 37, blue)
    Draw.Fill (452, 223, blue, blue)
end OM

proc OMR % Draws O in middle right spot
    Draw.Oval (537, 192, 30, 30, blue)
    Draw.Oval (537, 192, 37, 37, blue)
    Draw.Fill (537, 223, blue, blue)
end OMR

proc OTL % Draws O in top left spot
    Draw.Oval (367, 277, 30, 30, blue)
    Draw.Oval (367, 277, 37, 37, blue)
    Draw.Fill (367, 310, blue, blue)
end OTL

proc OTM % Draws O in top middle spot
    Draw.Oval (452, 277, 30, 30, blue)
    Draw.Oval (452, 277, 37, 37, blue)
    Draw.Fill (452, 310, blue, blue)
end OTM

proc OTR % Draws O in top right spot
    Draw.Oval (537, 277, 30, 30, blue)
    Draw.Oval (537, 277, 37, 37, blue)
    Draw.Fill (537, 310, blue, blue)
end OTR

proc DrawX % Draws x in place selected
    var x, y, b, r : int
    loop
        Mouse.Where (x, y, b)

        if b = 1 and x > 325 and x < 410
                and y > 65 and y < 150 then
            XBL
           
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 65 and y < 150 then
            XBM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 65 and y < 150 then
            XBR
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 150 and y < 235 then
            XML
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 150 and y < 235 then
            XM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 150 and y < 235 then
            XMR
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 235 and y < 320 then
            XTL
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 235 and y < 320 then
            XTM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 235 and y < 320 then
            XTR
            exit when b = 1
        end if
    end loop
end DrawX

proc DrawO % Draws O in place selected
    var x, y, b : int
    loop
        Mouse.Where (x, y, b)

        if b = 1 and x > 325 and x < 410
                and y > 65 and y < 150 then
            OBL
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 65 and y < 150 then
            OBM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 65 and y < 150 then
            OBR
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 150 and y < 235 then
            OML
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 150 and y < 235 then
            OM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 150 and y < 235 then
            OMR
            exit when b = 1
        elsif b = 1 and x > 325 and x < 410
                and y > 235 and y < 320 then
            OTL
            exit when b = 1
        elsif b = 1 and x > 410 and x < 495
                and y > 235 and y < 320 then
            OTM
            exit when b = 1
        elsif b = 1 and x > 495 and x < 580
                and y > 235 and y < 320 then
            OTR
            exit when b = 1
        end if
    end loop
end DrawO

put "X starts"
put ""
put "Click were you want to put an X or O"
delay (500)

GameBoard
DrawX
delay (500)
DrawO
delay (500)
DrawX
delay (500)
DrawO
delay (500)
DrawX
delay (500)
DrawO
delay (500)
DrawX
delay (500)
DrawO
delay (500)
DrawX

all i need is the code for one check i can figure the rest out myself


Edited by Clayton: Guess what I added?
Sponsor
Sponsor
Sponsor
sponsor
Carey




PostPosted: Tue May 22, 2007 9:20 am   Post subject: Re: Help wiht Tic Tac Toe Checking

You should use a 3*3 2D array to keep track of what player has gone where, and when checking for a win, just use 2 for loops to check for the vertical and horizontal win and 2 if statements to check for the diagonals. I think there is an example somewhere on this site you can look at for ideas.

ps. Clayton is going to add code tags for you Very Happy Very Happy Very Happy
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  [ 2 Posts ]
Jump to:   


Style:  
Search: