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




PostPosted: Thu Dec 15, 2011 10:10 am   Post subject: 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


Turing:


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
Sponsor
Sponsor
Sponsor
sponsor
Velocity




PostPosted: Thu Dec 15, 2011 10:14 am   Post subject: 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




PostPosted: Thu Dec 15, 2011 4:48 pm   Post subject: 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




PostPosted: Thu Dec 15, 2011 7:30 pm   Post subject: 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:
Turing:

get player2
cls %<-- NEW LINE
%Game
delay (1000)


Then I went into the loop and made sure that your score board and the names where pasted in the same place, you made it easy, and it's in the position 1,1 on the Turing screen. I use the locate function, and re-wrote the information on top of the scoreboard and names... So it looks like this:

Turing:

locate(1,1) %<-- NEW LINE WITHIN LOOP
%cls <-- NO NEED FOR THE CLS
scoreboard

gameBoard

put ""
if playerturn=true then
put player1, "'s turn"
else
put player2,"'s turn"
end if


And that's it... Not sure how you plan to keep score because no one wins yet... haha, but it should let the Xs and Os stay now! If you are planning to win, however, you'll need to make an array which keeps the placements of the Xs and Os, and then when the Xs or Os line up, you can tell who won!
Scrubtastic




PostPosted: Fri Dec 16, 2011 10:39 am   Post subject: Re: Tic Tac Toe help!!!

Okay so how do i determine if a person won or is it a tie?

i know we have to use an array to keep track of the spots but i don't know how to do it?
Aange10




PostPosted: Fri Dec 16, 2011 3:34 pm   Post subject: RE:Tic Tac Toe help!!!

Try looking at http://compsci.ca/v3/viewtopic.php?p=249837#249837 to see how using an array works and how flags work. Instead of toggling on or off, toggle it X/O/Empty.


How do you determine if a person wins or its a tie? ... It's tic-tac-toe...
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  [ 6 Posts ]
Jump to:   


Style:  
Search: