tictactoe. onclipevent (mouseup) { if (hittest(_root._xmouse, _root._ymouse, false) &&...

7
TicTacToe

Upload: jonathan-fisher

Post on 16-Dec-2015

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

TicTacToe

Page 2: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• onClipEvent (mouseUp) {• if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status !=

"end") {• if (String(this.txt_value.text) == "") {• this.txt_value.text = _root.userTime;• _root.CheckGame();• if (_root.userTime == "X") {• _root.userTime = "O";• } else if (_root.userTime == "O") {• _root.userTime = "X";• }• if (_root.game_status !="end"){• _root.txtStatus.text = "Time of Player

"+_root.userTime;• }• }• }• }

Page 3: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• userTime = "X";

• game_status = "play";

• txtStatus.text = "Time of Player "+userTime;

• function PieceX(col) {

• return xBase+col*xSpace;

• }

Page 4: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• function PieceY(row) {

• return yBase+row*ySpace;

• }

• numRows = 3;

• numCols = 3;

• numCells = numRows*numCols;

Page 5: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• xBase = box0._x;

• yBase = box0._y;

• xSpace = box0._width*1.07;

• ySpace = box0._height*1.07;

• var c = 1;

• var r = 0;

Page 6: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• for (var i = 1; i<numCells; i++) {• var name = "box"+i;• box0.duplicateMovieClip(name, i);• var newPiece = eval(name);• newPiece._x = PieceX(c);• newPiece._y = PieceY(r);• if (++c>=numCols) {• c = 0;• r++;• }• }

Page 7: TicTacToe. onClipEvent (mouseUp) { if (hitTest(_root._xmouse, _root._ymouse, false) && _root.game_status != "end") { if (String(this.txt_value.text) ==

• function CheckGame() {• win0 = "0,1,2";• win1 = "3,4,5";• win2 = "6,7,8";• win3 = "0,3,6";• win4 = "1,4,7";• win5 = "2,5,8";• win6 = "0,4,8";• win7 = "2,4,6";• notWin = String(_root.box8.txt_value.text);• for (winCheck=0; winCheck<=7; winCheck++) {• winTemp = eval("win"+winCheck).split(",");• boxValue1 = String(eval("_root.box"+winTemp[0]).txt_value.text);• boxValue2 = String(eval("_root.box"+winTemp[1]).txt_value.text);• boxValue3 = String(eval("_root.box"+winTemp[2]).txt_value.text);• if (boxValue1 == boxValue2 && boxValue2 == boxValue3 &&

boxValue1 != "") {• txtStatus.text = "Player "+boxValue1+" win";• game_status = "end";• } else {• notWin += String(eval("box"+winCheck).txt_value.text);• if (notWin.length>=9) {• txtStatus.text = "NoWinNoLoose";• game_status = "end";• }• }• }• }• stop();