
-----------------------------------
Scrubtastic
Thu Dec 15, 2011 10:10 am

Tic Tac Toe help!!!
-----------------------------------
What is it you are trying to achieve?
Making a tic tac toe game in turing for my isu


What is the problem you are having?
i can get the game to work but every time i click with my mouse on a box nothing appears, and the turns changes 





Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Here is my code




setscreen ("graphics")                  % use graphics mode
setscreen ("graphics:800;600")          % change to 800x600 size
%Introduction page
var player1, player2 : string     % player names and their corresponding markers
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

%%%%%%---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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Drawing the X on the board
procedure drawX
   for x : 30 .. 230 by 100
       for y : 180 .. 380 by 100
           if xvalue > x and xvalue < x + 100 and yvalue > y and yvalue < y + 100 then
               Draw.ThickLine (x + 10, y + 10, x + 90, y + 90, 10, black)
               Draw.ThickLine (x + 90, y + 10, x + 10, y + 90, 10, black)
           end if
       end for
   end for
end drawX
%%%%%%%%%%%%%%%%%%%%%%%%%%%
procedure drawO
for x : 30 .. 230 by 100
   for y : 180 .. 380 by 100
       if xvalue > x and xvalue < x + 100 and yvalue > y and yvalue < y + 100 then
           Draw.FillOval (x+50,y+50,45,45,black)
           Draw.FillOval (x+50,y+50,35,35,white)
       end if
   end for
end for
end drawO
%%%%%---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
%Game
delay (1000)                                    % wait 2 seconds for screen to be set to game

loop
cls
scoreboard

gameBoard

put ""
if playerturn=true then
put player1, "'s turn"
else
put player2,"'s turn"
end if



buttonwait ("down", xvalue, yvalue, click, button)      % find mouseclick
buttonwait ("up", xvalue, yvalue, click, button)

if playerturn=true then
drawX
playerturn:=false
else
drawO
playerturn:=true
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, 0, maxcolor)
   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
i'm using turing 4.1.1

-----------------------------------
Velocity
Thu Dec 15, 2011 10:14 am

RE:Tic Tac Toe help!!!
-----------------------------------
var tic : int := (mousewhere, (x, y pos))
var tac : int := (mousewhere, (x, y pos))
so when they click it it appears and stays there, look into a tutorial for mouse down.

-----------------------------------
Scrubtastic
Thu Dec 15, 2011 4:48 pm

RE:Tic Tac Toe help!!!
-----------------------------------
it works but i need to change the score but keep the Xs and Os  where they are
i don't understand how to do that

-----------------------------------
Linkxgl
Thu Dec 15, 2011 7:30 pm

RE:Tic Tac Toe help!!!
-----------------------------------
You're very close. There are two ways to do this. Using an array to keep which spaces on the board are occupied and each time it runs through the loop and clears the screen, you load up the occupied spaces and the score... OR, the easier way, delete lines manually without deleting the board. This is the way I dealt with the problems...

First, I added a cls right before you start the game. Here:

get player2 
cls %