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 "x and o" prob
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
venom




PostPosted: Thu Dec 07, 2006 2:01 pm   Post subject: tic tac toe "x and o" prob

im having trouble with the games pieces
it works fine untill its player 2's turn when you select the the area to place it , the player one's game piece takes it place
i have no clue to fix this problem and i've been trying for a few days now
and the treads here havent helped to much

i bet there are more problems but i dont care atm Rolling Eyes

code:

View.Set ("offscreenonly")
var font1, font2 : int
var x, y : int                                     %locates the x and y coords and the clicking of the mouse
var btn : int := 0
var picID : int := 0
var picIDgp, picIDgp1, picIDflipgp1 : int          %the whole process to create the gamepiece
var picIDgp2, picIDgp3, picIDflipgp2 : int
var plyr1 : int := 0                               %player one
var plyr2 : int := 0                               %player 2
var click : int := 0                               %when btn is pressed
var grid1, grid2, grid3 : int := 0
%, f, g, h, i, j, k
font1 := Font.New ("Verdana:10")                                 %text font is changed
assert font1 > 0                                                 %checks if font changed
font2 := Font.New ("BankGothic Lt BT:28")                        %text font is changed
assert font2 > 0                                                 %checks if font changed
%-----------------------------------------------------------------------------------
proc ticgrid

    Draw.ThickLine (175, 75, 175, 375, 5, blue)                  %tic-tac toe grid
    Draw.ThickLine (275, 375, 275, 75, 5, green)                 %tic-tac toe grid
    Draw.ThickLine (75, 275, 375, 275, 5, red)                   %tic-tac toe grid
    Draw.ThickLine (75, 175, 375, 175, 5, brown)                %tic-tac toe grid
    Draw.DashedLine (75, 75, 375, 75, drawDashDotDot, brightblue) %part of outer box
    Draw.DashedLine (375, 375, 75, 375, drawDashDotDot, brightblue) %part of outer box
    Draw.DashedLine (75, 75, 75, 375, drawDashDotDot, brightblue) %part of outer box
    Draw.DashedLine (375, 375, 375, 75, drawDashDotDot, brightblue) %part of outer box
    Font.Draw ("TIC-TAC TOE ", 100, 430, font2, black)           %text font in BankGothic
    Font.Draw ("CLASSIC ", 130, 400, font2, black)               %text font in Verdana
    Font.Draw ("name: ", 410, 330, font1, black)                 %text font in Verdana
    Font.Draw ("score: ", 410, 310, font1, black)                %text font in Verdana
    Font.Draw ("name:", 410, 200, font1, black)                  %text font in Verdana
    Font.Draw ("score:", 410, 180, font1, black)                 %text font in Verdana
    Pic.Draw (picIDflipgp1, 450, 75, picMerge)
    Pic.Draw (picIDflipgp2, 450, -75, picMerge)

    % locate (10,40)
    % put f ..
    % locate (10,50)
    % put g ..
    % locate (10,60)
    % put h ..
    % locate (10,70)
    % put i ..
    % locate (10,80)
    % put j ..
    % locate (20,10)
    % put k ..
end ticgrid
proc gamepiece
    drawline (0, 10, 20, 50, red)            %... main body
    drawline (40, 10, 20, 50, red)           %... main body
    drawline (0, 10, 20, 20, red)            %... main body
    drawline (40, 10, 20, 20, red)           %... main body
    for i : 1 .. 15
        drawline (0, 10, 20, 20 + i, blue)   %... engine
        drawline (40, 10, 20, 20 + i, blue)  %... engine
        drawline (13, 35, 27, 35, green)      %... engine
        drawline (20, 20 + i, 13, 35, green) %...weapon type
        drawline (27, 34, 20, 20 + i, green) %...weapon type
        View.Update
    end for
end gamepiece

proc gamepiece2
    drawline (0, 10, 20, 50, black)            %... main body
    drawline (40, 10, 20, 50, black)           %... main body
    drawline (0, 10, 20, 20, black)            %... main body
    drawline (40, 10, 20, 20, black)           %... main body
    for i : 1 .. 15
        drawline (0, 10, 20, 20 + i, red)   %... engine
        drawline (40, 10, 20, 20 + i, red)  %... engine
        drawline (13, 35, 27, 35, blue)      %... engine
        drawline (20, 20 + i, 13, 35, blue) %...weapon type
        drawline (27, 34, 20, 20 + i, blue) %...weapon type
        View.Update
    end for
end gamepiece2
%------------------------------------------------------------------
gamepiece
% draws the character
picIDgp := Pic.New (0, 8, 42, 50)                  % allows the character to move
picIDgp1 := Pic.New (0, 8, 42, 221)                  % draws unaltered version of boss
cls
picIDflipgp1 := Pic.Flip (picIDgp1)                     % flips the  pic
Pic.Draw (picIDflipgp1, 20, 20, picMerge)
cls
picIDgp1 := Pic.Scale (picIDflipgp1, 3 * 50, 3 * 150)


gamepiece2
picIDgp2 := Pic.New (0, 8, 42, 50)                  % allows the character to move
picIDgp2 := Pic.New (0, 8, 42, 221)                  % draws unaltered version of boss
cls
picIDflipgp2 := Pic.Flip (picIDgp2)                     % flips the  pic
Pic.Draw (picIDflipgp2, 20, 20, picMerge)
cls
picIDgp2 := Pic.Scale (picIDflipgp2, 3 * 50, 3 * 150)


%-----------------------------------------------------------------------------------

%plyr to click icon
loop

    mousewhere (x, y, btn)
    View.Update
    cls
    ticgrid            %draws the grid

    % if btn = 1 then
    %     loop
    %         mousewhere (x, y, btn)
    %        locate(10,20)
    %          put x ..
    %         put y ..
    %         View.Update
    %         exit when btn = 0
    %     end loop
    % end if

    put btn ..       %shows if the button is pressed
    put click ..     % also shows the btn being pressed used to show the gamepiece
   
    %comand to draw the gamepiece to follow the mouse
    if x > 450 and x < 490 and y > 240 and y < 290 and btn = 1 then
        Pic.Draw (picIDflipgp1, -20 + x, -200 + y, picMerge)
        picID := picIDflipgp1
        plyr1 := 1
        click := 1
    end if
    if picID = picIDflipgp1 and click = 1 then
        Pic.Draw (picIDflipgp1, -20 + x, -200 + y, picMerge)
        click := 1
    end if

    %comand to draw the gamepiece to follow the mouse
    if x > 440 and x < 490 and y > 90 and y < 140 and btn = 1 then
        Pic.Draw (picIDflipgp2, -20 + x, -200 + y, picMerge)
        picID := picIDflipgp2
        plyr2 := 2
        click := 2
    end if
    if picID = picIDflipgp2 and click = 2 then
        Pic.Draw (picIDflipgp2, -20 + x, -200 + y, picMerge)
        click := 2
    end if



    %... the code for placement of game pieces on grid 1
    %%%%%%%%%%%%%%%%%%%%%PROBLEM AREA%%%%%%%%%%%%%%%%%%%%%%%%
    if x > 80 and x < 170 and y > 280 and y < 370 and btn = 1 and plyr1 = 1 and grid1 = 0 then
        grid1 := 1
    end if
    if x > 80 and x < 170 and y > 280 and y < 370 and btn = 1 and plyr2 = 2 and grid1 = 0 then
        grid1 := 2
    end if
   
   
    if grid1 = 1 and plyr1 = 1 then
        Pic.Draw (picIDflipgp1, 105, 130, picMerge)
    end if
    if grid1 = 2 and plyr2 = 2 then
        Pic.Draw (picIDflipgp2, 105, 130, picMerge)
    end if


    %... the code for placement of game pieces on grid 2
    if x > 180 and x < 270 and y > 280 and y < 372 and btn = 1 and plyr1 = 1 and grid2 = 0 then
        grid2 := 1
    end if
    if x > 180 and x < 270 and y > 280 and y < 372 and btn = 1 and plyr2 = 2 and grid2 = 0 then
        grid2 := 2
    end if
    if grid2 = 1 and plyr1 = 1 then
        Pic.Draw (picIDflipgp1, 205, 130, picMerge)
    end if
    if grid2 = 2 and plyr2 = 2 then
        Pic.Draw (picIDflipgp2, 205, 130, picMerge)
    end if


    %... the code for placement of game pieces on grid 3
    if x > 280 and x < 370 and y > 280 and y < 372 and btn = 1 and plyr1 = 1 and grid3 = 0 then
        grid3 := 1
    end if
    if x > 280 and x < 370 and y > 280 and y < 372 and btn = 1 and plyr2 = 2 and grid3 = 0 then
        grid3 := 2
    end if
    if grid3 = 1 and plyr1 = 1 then
        Pic.Draw (picIDflipgp1, 305, 130, picMerge)
    end if
    if grid3 = 2 and plyr2 = 2 then
        Pic.Draw (picIDflipgp2, 305, 130, picMerge)
    end if

end loop
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Thu Dec 07, 2006 2:37 pm   Post subject: (No subject)

Without wanting to look through all that code, are you using a variable to record which turn it is? It would be an integer, and be initialized to 0. With each run through your main loop, it gets incrimented. If it's even, it's player 1's turn, and you draw an X. If it's odd, it's player 2's turn, and you draw an O.

Even better would be to mod it by 2 each time through the loop. Then you are sure your variable will never get ridiculously big (yeah, even if this is tic-tac-toe, it bothers me) and you don't have to check for even or odd, just whether it equals zero or equals one.
Hack.saw




PostPosted: Fri Dec 08, 2006 12:34 pm   Post subject: (No subject)

Ouch too hard for me to read =) I got a generic tic tac toe for you but you will have to compare and figure out how to implement and change the code you need. You will also need an understanding of how it works to know what code you need. Sorry for being lazy but i don't have the time to read through that right now =) I feel a headache coming on just looking at it Wink


TIC TAC TOE.ace
 Description:
Hope this works =)

Download
 Filename:  TIC TAC TOE.ace
 Filesize:  5.9 KB
 Downloaded:  88 Time(s)

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  [ 3 Posts ]
Jump to:   


Style:  
Search: