// tttBasic

// two players alternate

// no win check, no AI

// creates cell object blank state is an invisible rectangle!





init();



function init(){

  //set up X and Y values

  xVals = new Array(130, 230, 330, 130, 230, 330, 130, 230, 330);

  yVals = new Array(120, 120, 120, 210, 210, 210, 300, 300, 300);



  //board is data representation

  board = new Array("blank", "blank", "blank", "blank", "blank", 

                    "blank", "blank", "blank", "blank");



  turn = "x"; //who's turn is it?

	

  //build classes from cell movieClip

  for (i = 0; i < 9; i++){

    _root.attachMovie("cell", "cell_" + i, 100 + i);



    theCell = eval("cell_" + i);

    theCell._x = xVals[i];

    theCell._y = yVals[i];

    theCell.state = "blank";

    theCell.index = i;

    theCell.gotoAndStop(theCell.state);

	  

    //add click event

    theCell.onMouseUp = function(){

      //respond only if mouse is over me (aaaargh!)

      if (this.hitTest(_root._xmouse, _root._ymouse, false)){

        currentSquare = this.index;

        if(board[currentSquare] == "blank"){

          board[currentSquare] = turn;

          this.state = turn;

          this.gotoAndStop(this.state);



          if (turn == "x"){

            turn = "o";

          } else {

            turn = "x";

          } // end 'whos turn' if



        } // end 'board is blank' if

      } // end "hit this instance" if

    } // end mouseUp

  } // end for

} // end init