PDA

View Full Version : tic tac toe



Ineedsleep
July 9th, 2005, 06:35 PM
Im learning flash and am to make a tic tac toe game what is the best way to test for a winning line???

if you know of any good tutorials etc!

NiñoScript
July 9th, 2005, 08:39 PM
give me a reference of how are u doing it, and ill help
_______
ive got an idea, i hope u get it, its a bit complex :P

if u name the squares like this:
0_0_mc 1_0_mc 2_0_mc
0_1_mc 1_1_mc 2_1_mc
0_2_mc 1_2_mc 2_2_mc

and in each MC they should have 2 vars, the same that say on their names, like this:
1_2_mc.x=1
1_2_mc.y=2

so if u make them with a for, it should be easy to insert them those vars, k?


u could use a function like this:
function checkRow (xPos, yPos, xDir, yDir){
if(_root[(xPos+xDir)+"_"+(yPos+yDir)+"_mc"].checked){
if(_root[(xPos+2*xDir)+"_"+(yPos+2*yDir)+"_mc"].checked){
_root.youWon=true;
}
}
};


but how to use that function ur asking?, ill tell u, we use another function to tell that to the 8 possible positions the row could be:

function octupleCheck(xPos, yPos){
for (x=-1; x<=1; x++) {
for (y=-1; y<=1; y++) {
if (x != 0 || y != 0) {
checkRow(xPos, yPos, x, y);
}
}
}
};
get it?

and after u click in the movieclip, they should say something like this:
movieclip.onRelease= function(){
this.checked=true
octupleCheck(this.x, this.y)
};

i'll make myself one of this game, and ill use this code to make it work, i think its a good idea :)

Ineedsleep
July 9th, 2005, 08:41 PM
Im using gotoAndStop just changing varaibales around to get the right response but i know that this is the long way round.

what would be the best way to make the game?

Templarian
July 9th, 2005, 09:15 PM
//deleted what i said.
//edit something glitched, those posts didnt show up for me sry.

NiñoScript
July 9th, 2005, 09:27 PM
(read my last post, i edited it) ;P
———————
damn, there's a huge problem with my way, u cant win if u press the middle one in the row, im gonna solve that i a while :cool:

Ineedsleep
July 9th, 2005, 10:03 PM
that helped!!!

thank i now have it working sort of!

is a bit rough but is good for my first game!!!!!

NiñoScript
July 9th, 2005, 11:26 PM
Hooray!, i finished my tic tac toe game!, i won ;P

CLICK HERE TO PLAY MY TIC TAC TOE GAME :P (http://img.photobucket.com/albums/v720/NekoChanPics/tic_tac_toe.swf)

Eh?
July 9th, 2005, 11:35 PM
Nice simple game......you need to add a play again button if its a tie though

nathan99
July 10th, 2005, 12:09 AM
lol yeaa

unchew
July 10th, 2005, 01:25 AM
Very nice... but wasn't this question posted before today?

Ineedsleep
July 13th, 2005, 07:46 PM
could you post the code you used to test the win logic?

also how long did it take you do to do that?

if there is no logical way am going to have to make a big bad if statement

Ineedsleep
July 13th, 2005, 08:07 PM
eureka I was pouring over the code when I realised!!!!!!

what I need to do is make a loop that will sytematicaly test ofor all of the different squares

if you could post a copy of the fla file so i COULD see how you have odne it the I would be able to have a look to further understand it

many thanks

NiñoScript
July 14th, 2005, 07:44 PM
well, that took me like one hour...
, here it is, the precious fla, made with my own bare hands...

you own me 20 dollars for CopyRight Issues
lol :pleased:

NiñoScript
July 14th, 2005, 07:53 PM
BTW, do u like this prototype? i found it very usefull :pleased:

MovieClip.prototype.trace = function(texto) {
trace(this._name+" :"+chr(13)+'\"'+texto+'\"'+chr(13));
};

try it in a named instance, like this:
NiñoScript.trace("hello, how are you?")