Posted: Thu Sep 18, 2008 8:32 am Post subject: Tic Tac Toe Help - Drawing X's and O's
Ok, i'm working on a little tic tac toe game during spare, and i need to draw the x's and o's. i don't want to use a pile of if\else statements, but will if nessesarry. more or less, i would like to be able to click the "square" and have the x or o drawn there. Any ideas?
Thanks in advance
A\V
Sponsor Sponsor
Ktomislav
Posted: Thu Sep 18, 2008 8:51 am Post subject: Re: Tic Tac Toe Help - Drawing X's and O's
Something like this?
code:
View.Set ('offscreenonly')
var x1, y1, x2, y2: int
var x_mouse, y_mouse, button, buttonupdown: int
x1 := 100
x2 := 200
y1 := 100
y2 := 200
Draw.Box (x1, y1, x2, y2, black)
loop
Mouse.Where (x_mouse, y_mouse, button) % or mousewhere
if (button = 1) then
Mouse.ButtonWait ("up", x_mouse, y_mouse, button, buttonupdown)
Draw.Line (x1, y1, x2, y2, red)
Draw.Line (x2, y1, x1, y2, red)
View.Update
end if
end loop
S_Grimm
Posted: Thu Sep 18, 2008 12:39 pm Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
something like it. but it needs to have a count so that i can check for win.
Insectoid
Posted: Thu Sep 18, 2008 12:48 pm Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
You need a 2-d array to keep track of what square has been claimed by which team. Then you use a combination of for loops an if statements to check if someone has won.
S_Grimm
Posted: Tue Sep 23, 2008 10:32 am Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
so and loop if square one and square 2 and square 3 are claimed by x then end loop sort of style?
Insectoid
Posted: Tue Sep 23, 2008 11:58 am Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
Uh, its a bit more complicated than that...
I suggest looking someone else's tic-tac-toe. (don't use mine, it's unreadable )
Warchamp7
Posted: Tue Sep 23, 2008 12:03 pm Post subject: Re: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
This is how I would end up doing it
If a player goes in a sqaure, set the BoxArray for that square to 1 or 2 depending on the player then have a check
BoxArray (1 to 9)
PlayerCheck
1 is for X
2 is for O
Game Grid
1 2 3
4 5 6
7 8 9
Turing:
%Short example. Basically have every possible way to win in the if statement
for XYZ :1..2
PlayerCheck := XYZ
if(BoxArray(1)= PlayerCheck and BoxArray(2)= PlayerCheck and BoxArray(3)= PlayerCheck)or(BoxArray(1)= PlayerCheck and BoxArray(5)= PlayerCheck and BoxArray(9)= PlayerCheck)then
XWin :=true else endif
endfor
Insectoid
Posted: Tue Sep 23, 2008 12:36 pm Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
I'm fairly sure you need some brackets in that if statement, though I may be wrong.
Sponsor Sponsor
Warchamp7
Posted: Wed Sep 24, 2008 8:21 am Post subject: Re: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
insectoid @ Tue Sep 23, 2008 12:36 pm wrote:
I'm fairly sure you need some brackets in that if statement, though I may be wrong.
I did
Quote:
(BoxArray(1) = PlayerCheck and BoxArray(2) = PlayerCheck and BoxArray(3) = PlayerCheck) or (BoxArray(1) = PlayerCheck and BoxArray(5) = PlayerCheck and BoxArray(9) = PlayerCheck)
Insectoid
Posted: Wed Sep 24, 2008 11:09 am Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
Woops, stupid me. Didn't even see it.
gitoxa
Posted: Wed Sep 24, 2008 9:49 pm Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
Warchamp, what's the point of this line of code?
code:
PlayerCheck := XYZ
And it's much better just to check to see if all the elements are equal to each other, less comparisons. Using your variables:
code:
if (BoxArray(1) = BoxArray(2) and BoxArray(2) = BoxArray(3))
or (BoxArray(1) = BoxArray(5) and BoxArray(5) = BoxArray(9)) then
Warchamp7
Posted: Thu Sep 25, 2008 7:49 am Post subject: Re: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
gitoxa @ Wed Sep 24, 2008 9:49 pm wrote:
Warchamp, what's the point of this line of code?
code:
PlayerCheck := XYZ
And it's much better just to check to see if all the elements are equal to each other, less comparisons. Using your variables:
code:
if (BoxArray(1) = BoxArray(2) and BoxArray(2) = BoxArray(3))
or (BoxArray(1) = BoxArray(5) and BoxArray(5) = BoxArray(9)) then
For the player check, it's just a quick for loop to check player 1 and player 2 with one group of code
As for your method, a nice idea
S_Grimm
Posted: Thu Sep 25, 2008 8:33 am Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
ok thanks guys. I think that gitoxa has the right idea. Now, the only way that i can draw an x or o inside the grid when a mouse button is clicked is to use Mouse.Where and a series of if statements, right?
Here's The Example:
If mousex >= 0 and mousex <= 150 and mousey >= 0 and mousey <= 150 and mousebutton = 1 then
draw x
else .
end if
gitoxa
Posted: Thu Sep 25, 2008 4:29 pm Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
Warchamp, I just meant there's no point in assigning a variable to equal XYZ when you can just use XYZ instead.
And A/V, that's one way to do it. The way I did it wa I used a 2d array for the squares, and div'd the MouseX and MouseY values by the size of the squares (with some other manipulation just to give me the right numbers). That ways probably a little more difficult to incoporate correctly, but it allowed to reduce it down to one if statement, and two number manipulations.
S_Grimm
Posted: Fri Sep 26, 2008 7:27 am Post subject: RE:Tic Tac Toe Help - Drawing X\'s and O\'s