Computer Science Canada Tic Tac Toe Help - Drawing X's and O's |
Author: | S_Grimm [ 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 |
Author: | Ktomislav [ Thu Sep 18, 2008 8:51 am ] | ||
Post subject: | Re: Tic Tac Toe Help - Drawing X's and O's | ||
Something like this?
|
Author: | S_Grimm [ 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. |
Author: | Insectoid [ 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. |
Author: | S_Grimm [ 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? |
Author: | Insectoid [ 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 ![]() |
Author: | Warchamp7 [ 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
|
Author: | Insectoid [ 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. |
Author: | Warchamp7 [ 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) |
Author: | Insectoid [ 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. |
Author: | gitoxa [ 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? ![]()
And it's much better just to check to see if all the elements are equal to each other, less comparisons. Using your variables:
|
Author: | Warchamp7 [ 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?
![]()
And it's much better just to check to see if all the elements are equal to each other, less comparisons. Using your variables:
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 ![]() |
Author: | S_Grimm [ 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 |
Author: | gitoxa [ 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. |
Author: | S_Grimm [ Fri Sep 26, 2008 7:27 am ] |
Post subject: | RE:Tic Tac Toe Help - Drawing X\'s and O\'s |
ok thanks guys. |
Author: | Zeroth [ Fri Sep 26, 2008 11:17 am ] |
Post subject: | Re: RE:Tic Tac Toe Help - Drawing X\'s and O\'s |
gitoxa @ Thu Sep 25, 2008 1:29 pm wrote: Warchamp, I just meant there's no point in assigning a variable to equal XYZ when you can just use XYZ instead.
Yes there is. Its called Magic Numbers. Why are we comparing to XYZ? What does XYZ signify? Its a bad, bad, bad habit to get into, and can really slow down maintenance in larger programs. Really, you should be encouraging the behaviour of Warchamp, not smacking him down for it. From personal experience, magic numbers are the most insidious, nasty, confusing thing to deal with in 6-month old, 1 year old code. |
Author: | gitoxa [ Fri Sep 26, 2008 11:27 am ] |
Post subject: | RE:Tic Tac Toe Help - Drawing X\'s and O\'s |
Why is he using XYZ in the first place? In a different context I could understand him doing that, but not this one. |
Author: | Clayton [ Fri Sep 26, 2008 1:17 pm ] | ||||
Post subject: | RE:Tic Tac Toe Help - Drawing X\'s and O\'s | ||||
I'm going to tend to agree with gitoxa here, why have:
As opposed to:
? |
Author: | S_Grimm [ Tue Sep 30, 2008 11:29 am ] |
Post subject: | RE:Tic Tac Toe Help - Drawing X\'s and O\'s |
gitoxa's methond does seem simpler....... hmm... Ill try it and see what happens... I plan on having a rough code for you all to look at out by tommorow. i haven't really had time to work on it, between work and homework (that takes up most of my spare). if anyone else has any good ideas for it, let me know plz. |