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




PostPosted: Mon Dec 19, 2011 10:04 am   Post subject: Tic tac toe help again

What is it you are trying to achieve?
Tic tac toe in turing


What is the problem you are having?
cannot find who wins, or if it's a tie





Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)


Turing:


setscreen ("graphics:800;600")          % change to 800x600 size

%Introduction page
var player1, player2 : string                       % player names
var anykey : string                                 % dummy variable for inputting any key to start
var player1Score, player2Score := 0                 % player 1 and 2's scores
var xvalue, yvalue, click, button : int             % mouseclick cordinate variables
var playerturn : boolean := true                    % find which player's turn it is
var taken : array 1 .. 3, 1 .. 3 of int := init (0, 0, 0, 0, 0, 0, 0, 0, 0)


%%%%%%---PROCEDURES---%%%%%%
% This is the logo
procedure logo
    put " _______    ___      ________         ___      ________    _____   _______"
    put "    |    | /   \\         |     /\\    /   \\         |      /     \\  |"
    put "    |    | |             |    /__\\   |             |      |      | |____"
    put "    |    | |             |   /    \\  |             |      |      | |"
    put "    |    | \\___/         |  /      \\ \\___/         |      \\______/ |______"
end logo
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% This is the scoreboard
procedure scoreboard
    put "SCOREBOARD"
    put "======"
    put player1, ": ", player1Score
    put player2, ": ", player2Score
end scoreboard
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Drawing the game board
procedure gameBoard
    for x : 30 .. 230 by 100
        for y : 180 .. 380 by 100
            drawbox (x, y, x + 100, y + 100, 4)
        end for
    end for
end gameBoard


%%%%%---END PROCEDURES%%%%%

logo
put ""              % Welcome screen
put ""
put "Welcome!"
put ""
put "press any key to start"
anykey := getchar ()
cls
logo
put ""
put ""
put "What is your name Player 1?"               % Inputting players' names and their marker
get player1
put ""
put "What is your name, Player 2?"
get player2
delay (1000)                                    % wait 1 seconds for screen to be set to game
cls
% Game

loop
    locate (1, 1)
    scoreboard                                  % shows the scoreboard

    gameBoard                                   % shows the board

    put ""

    if playerturn = true then                   % Output which player's turn
        put player1, "'s turn"
    else
        put player2, "'s turn"
    end if

    buttonwait ("down", xvalue, yvalue, click, button)  % find mouseclick

    if xvalue > 30 and xvalue < 130 and yvalue > 180 and yvalue < 280 then  % Box (1,1) is clicked
        if taken (1, 1) = 0 then
            if playerturn = true then
                Draw.ThickLine (40, 190, 120, 270, 10, black)
                Draw.ThickLine (120, 190, 40, 270, 10, black)
                taken (1, 1) := 1
                playerturn := false
            else
                Draw.FillOval (80, 230, 45, 45, black)
                Draw.FillOval (80, 230, 35, 35, white)
                taken (1, 1) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 30 and xvalue < 130 and yvalue > 280 and yvalue < 380 then
        if taken (1, 2) = 0 then
            if playerturn = true then
                Draw.ThickLine (40, 290, 120, 370, 10, black)
                Draw.ThickLine (120, 290, 40, 370, 10, black)
                taken (1, 2) := 1
                playerturn := false
            else
                Draw.FillOval (80, 330, 45, 45, black)
                Draw.FillOval (80, 330, 35, 35, white)
                taken (1, 2) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 30 and xvalue < 130 and yvalue > 380 and yvalue < 480 then
        if taken (1, 3) = 0 then
            if playerturn = true then
                Draw.ThickLine (40, 390, 120, 470, 10, black)
                Draw.ThickLine (120, 390, 40, 470, 10, black)
                taken (1, 3) := 1
                playerturn := false
            else
                Draw.FillOval (80, 430, 45, 45, black)
                Draw.FillOval (80, 430, 35, 35, white)
                taken (1, 2) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 130 and xvalue < 230 and yvalue > 180 and yvalue < 280 then
        if taken (2, 1) = 0 then
            if playerturn = true then
                Draw.ThickLine (140, 190, 220, 270, 10, black)
                Draw.ThickLine (220, 190, 140, 270, 10, black)
                taken (2, 1) := 1
                playerturn := false
            else
                Draw.FillOval (180, 230, 45, 45, black)
                Draw.FillOval (180, 230, 35, 35, white)
                taken (2, 1) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 130 and xvalue < 230 and yvalue > 280 and yvalue < 380 then
        if taken (2, 2) = 0 then
            if playerturn = true then
                Draw.ThickLine (140, 290, 220, 370, 10, black)
                Draw.ThickLine (220, 290, 140, 370, 10, black)
                taken (2, 2) := 1
                playerturn := false
            else
                Draw.FillOval (180, 330, 45, 45, black)
                Draw.FillOval (180, 330, 35, 35, white)
                taken (2, 2) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 130 and xvalue < 230 and yvalue > 380 and yvalue < 480 then
        if taken (2, 3) = 0 then
            if playerturn = true then
                Draw.ThickLine (140, 390, 220, 470, 10, black)
                Draw.ThickLine (220, 390, 140, 470, 10, black)
                taken (2, 3) := 1
                playerturn := false
            else
                Draw.FillOval (180, 430, 45, 45, black)
                Draw.FillOval (180, 430, 35, 35, white)
                taken (2, 3) := 2
                playerturn := true
            end if
        end if
    elsif xvalue > 230 and xvalue < 330 and yvalue > 180 and yvalue < 280 then
        if playerturn = true then
            Draw.ThickLine (240, 190, 320, 270, 10, black)
            Draw.ThickLine (320, 190, 240, 270, 10, black)
            taken (3, 1) := 1
            playerturn := false
        else
            Draw.FillOval (280, 230, 45, 45, black)
            Draw.FillOval (280, 230, 35, 35, white)
            taken (3, 1) := 2
            playerturn := true
        end if
    elsif xvalue > 230 and xvalue < 330 and yvalue > 280 and yvalue < 380 then
        if playerturn = true then
            Draw.ThickLine (240, 290, 320, 370, 10, black)
            Draw.ThickLine (320, 290, 240, 370, 10, black)
            taken (3, 2) := 1
            playerturn := false
        else
            Draw.FillOval (280, 330, 45, 45, black)
            Draw.FillOval (280, 330, 35, 35, white)
            taken (3, 2) := 2
            playerturn := true
        end if
    elsif xvalue > 230 and xvalue < 330 and yvalue > 380 and yvalue < 480 then
        if playerturn = true then
            Draw.ThickLine (240, 390, 320, 470, 10, black)
            Draw.ThickLine (320, 390, 240, 470, 10, black)
            taken (3, 3) := 1
            playerturn := false
        else
            Draw.FillOval (280, 430, 45, 45, black)
            Draw.FillOval (280, 430, 35, 35, white)
            taken (3, 3) := 2
            playerturn := true
        end if
    end if

end loop
%%%%%%%%%% The following is borrowed from Turing reference(F10)
var row, column, colr : int
loop
    randint (row, 1, maxrow - 1)
    randint (column, 1, maxcol)
    randint (colr, 1, 6)
    color (colr)
    locate (row, column)
    put "TIC TAC TOE " ..          % Use dot-dot to avoid clearing end of line
    delay (1)
end loop
%%%%%%%%%% End borrowed code




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




PostPosted: Mon Dec 19, 2011 5:34 pm   Post subject: RE:Tic tac toe help again

kk i got it
its just that when it asks if i want to keep playing and you click were the box was and you type yes to keep playing, some Xs and Os are already there
0.0
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: