
-----------------------------------
S_Grimm
Thu Sep 18, 2008 8:32 am

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

-----------------------------------
Ktomislav
Thu Sep 18, 2008 8:51 am

Re: Tic Tac Toe Help - Drawing X's and O's
-----------------------------------
Something like this?


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
Thu Sep 18, 2008 12:39 pm

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
Thu Sep 18, 2008 12:48 pm

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
Tue Sep 23, 2008 10:32 am

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
Tue Sep 23, 2008 11:58 am

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
Tue Sep 23, 2008 12:03 pm

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


%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
end if

end for


-----------------------------------
Insectoid
Tue Sep 23, 2008 12:36 pm

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.

-----------------------------------
Warchamp7
Wed Sep 24, 2008 8:21 am

Re: 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.

I did

(BoxArray(1) = PlayerCheck and BoxArray(2) = PlayerCheck and BoxArray(3) = PlayerCheck) or (BoxArray(1) = PlayerCheck and BoxArray(5) = PlayerCheck and BoxArray(9) = PlayerCheck)

-----------------------------------
Insectoid
Wed Sep 24, 2008 11:09 am

RE:Tic Tac Toe Help - Drawing X\'s and O\'s
-----------------------------------
Woops, stupid me. Didn't even see it.

-----------------------------------
gitoxa
Wed Sep 24, 2008 9:49 pm

RE:Tic Tac Toe Help - Drawing X\'s and O\'s
-----------------------------------
Warchamp, what's the point of this line of code? :P

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:
if (BoxArray(1) = BoxArray(2) and BoxArray(2) = BoxArray(3)) 
or (BoxArray(1) = BoxArray(5) and BoxArray(5) = BoxArray(9)) then

-----------------------------------
Warchamp7
Thu Sep 25, 2008 7:49 am

Re: RE:Tic Tac Toe Help - Drawing X\'s and O\'s
-----------------------------------
Warchamp, what's the point of this line of code? :P

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:
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
Thu Sep 25, 2008 8:33 am

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 = 0 and mousey 