Creating system to record mouse click spots Tic Tac Toe
Author |
Message |
icsguy123
|
Posted: Mon Jan 21, 2013 11:47 am Post subject: Creating system to record mouse click spots Tic Tac Toe |
|
|
What is it you are trying to achieve?
Creating a recording system for Tic Tac Toe for where the player clicks
What is the problem you are having?
I can't figure out why it isn't working. I've created a record system, but am having trouble figuring out how to initialize it, and to make it work.
Describe what you have tried to solve this problem
I've tried creating a function to tell me when the board is full, but that dosent work with Tic Tac Toe. The other idea I tried is whats included in the text provided, makig a record for the spots.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
Turing: |
%Set up variables
var player1, player2 : string %names of players
var presskey : string %press any key to start the game
var player1score := 1 %player1's score
var player2score := 2 %player2's score
var playerturn : boolean := true %records players turn
var xvalue, yvalue, mouseclick, button : int %creating coordinates for where the player clicks
%Creating record for player click spots
var gridplacement : array 1.. 9 of
record
spots : array 1.. 9 of int
end record
%Drawing gameboard
procedure gameBoard
for x : 30 .. 300 by 100
for y : 75 .. 330 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 .. 300 by 100
for y : 75 .. 330 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
%Drawing O on the board
procedure drawO
for x : 30 .. 300 by 100
for y : 75 .. 330 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
%start output
put "Welcome to Tic Tac Toe!!" %outputs game type
put " "
put "Press any key to start" %starts game once a key is pressed
presskey := getchar ()
delay (100)
put "Please insert player1's name" %determines player1 and player2's names
get player1
put "player2, please insert your name"
get player2
%Game start
put "Lets start the game then!" %Output comfirmation of game start
put "When clicking in the box, make sure to click as close to the centre of that specific box as possible.Ready? Go!"
delay (2000)
cls %clears screen
loop
locate (1, 1)
put "It is " ..
delay (100)
if playerturn = true then %determines which player's turn it is
put player1, " 's turn" ..
else
put player2, " 's turn" ..
end if
gameBoard
buttonwait ("down", xvalue, yvalue, mouseclick, button ) % find mouseclick
buttonwait ("up", xvalue, yvalue, mouseclick, button )
if playerturn = true then %figuring out which player goes and what symbol is created when the player clicks
drawX
playerturn := false
else
drawO
playerturn := true
end if
end loop
|
Turing: |
%What I need to figure out is a recording system that records where the x's and o's have been
var gridplacement : array 1..9 of
record
spots : array 1..9 of int
end record
%This is what I have so far...
|
Please specify what version of Turing you are using
Turing 4.1.1
Please Help I hope somebody can help, I am a noob at this so please don't give me a hard time! Thanks! |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Raknarg
|
Posted: Mon Jan 21, 2013 5:07 pm Post subject: RE:Creating system to record mouse click spots Tic Tac Toe |
|
|
First of all... Why are you making an array of 81 slots? You can just use an array 1 .. 9, or an array 1 .. 3, 1 .. 3 |
|
|
|
|
|
icsguy123
|
Posted: Mon Jan 21, 2013 5:24 pm Post subject: RE:Creating system to record mouse click spots Tic Tac Toe |
|
|
Oops.Did I mention I was a noob? lol so I've sorted that out, now Ive initialized the array, but where should I place it in the program for it to take affect? In the loop? |
|
|
|
|
|
Raknarg
|
Posted: Tue Jan 22, 2013 8:51 pm Post subject: RE:Creating system to record mouse click spots Tic Tac Toe |
|
|
Wherever it's needed, whenever you need to access it. For instance lets say on o's turn the player selects the top left corner. WE could say slots (1, 1) = "O" or something. or if X selects the middle right, you would set slots (3, 2) to "X".
You can put it wherever you want. Remember this is basically a set of instructions. Think about what you want to do exactly and tell your program to do exactly that. |
|
|
|
|
|
|
|