[JavaScript] Jogo Da Velha.
Autor: Webmaster | Publicado: 2012-02-20T22:54:00-02:00

&nbsp;Código JavaScript:
&lt;SCRIPT&gt;


//if IE4/NS6, apply style
if (document.all||document.getElementById){
document.write('&lt;style&gt;.tictac{')
document.write('width:50px;height:50px;')
document.write('}&lt;/style&gt;')
}

var sqr1
var sqr2
var sqr3
var sqr4
var sqr5
var sqr6
var sqr7
var sqr8
var sqr9
var sqr1T = 0
var sqr2T = 0
var sqr3T = 0
var sqr4T = 0
var sqr5T = 0
var sqr6T = 0
var sqr7T = 0
var sqr8T = 0
var sqr9T = 0
var moveCount = 0
var turn = 0
var mode = 1

function vari()
{
sqr1 = document.tic.sqr1.value
sqr2 = document.tic.sqr2.value
sqr3 = document.tic.sqr3.value
sqr4 = document.tic.sqr4.value
sqr5 = document.tic.sqr5.value
sqr6 = document.tic.sqr6.value
sqr7 = document.tic.sqr7.value
sqr8 = document.tic.sqr8.value
sqr9 = document.tic.sqr9.value
}
function check()
{
&nbsp; if(sqr1 == " X " &amp;&amp; sqr2 == " X " &amp;&amp; sqr3 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr4 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr6 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr7 == " X " &amp;&amp; sqr8 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr4 == " X " &amp;&amp; sqr7 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr2 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr8 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr6 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr7 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Ganhou!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else
&nbsp; {
&nbsp;&nbsp;&nbsp; winCheck()
&nbsp;&nbsp;&nbsp; check2()
&nbsp;&nbsp;&nbsp; drawCheck() 
&nbsp; }
}

function check2()
{
&nbsp; vari()
&nbsp; drawCheck()
&nbsp; if(sqr1 == " O " &amp;&amp; sqr2 == " O " &amp;&amp; sqr3 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr4 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr6 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr7 == " O " &amp;&amp; sqr8 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr4 == " O " &amp;&amp; sqr7 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr2 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr8 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr6 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr7 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Você Perdeu!!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
}

function player1Check()
{
&nbsp; if(sqr1 == " X " &amp;&amp; sqr2 == " X " &amp;&amp; sqr3 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr4 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr6 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr7 == " X " &amp;&amp; sqr8 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr4 == " X " &amp;&amp; sqr7 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr2 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr8 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr6 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr7 == " X ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 1 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else
&nbsp; {
&nbsp;&nbsp;&nbsp; player2Check()
&nbsp;&nbsp;&nbsp; drawCheck() 
&nbsp; }
}

function player2Check()
{
&nbsp; vari()
&nbsp; drawCheck()
&nbsp; if(sqr1 == " O " &amp;&amp; sqr2 == " O " &amp;&amp; sqr3 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr4 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr6 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()

&nbsp; }
&nbsp; else if(sqr7 == " O " &amp;&amp; sqr8 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr4 == " O " &amp;&amp; sqr7 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr2 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr8 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr6 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr7 == " O ")
&nbsp; {
&nbsp;&nbsp;&nbsp; alert("Player 2 wins!")
&nbsp;&nbsp;&nbsp; reset()
&nbsp; }
}

function drawCheck()
{
&nbsp; vari()
&nbsp; moveCount = sqr1T + sqr2T + sqr3T + sqr4T + sqr5T + sqr6T + sqr7T + sqr8T + sqr9T
&nbsp; if(moveCount == 9)
&nbsp; {
&nbsp;&nbsp;&nbsp; reset()
&nbsp;&nbsp;&nbsp; alert("Outra vez.")
&nbsp; }
}

function winCheck()
{
&nbsp; check2()
&nbsp; if(sqr1 == " O " &amp;&amp; sqr2 == " O " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " O " &amp;&amp; sqr3 == " O " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr6T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr6.value = " O "
&nbsp;&nbsp;&nbsp; sqr6T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " O " &amp;&amp; sqr6 == " O " &amp;&amp; sqr4T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr4.value = " O "
&nbsp;&nbsp;&nbsp; sqr4T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " O " &amp;&amp; sqr8 == " O " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr8 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr3 == " O " &amp;&amp; sqr2T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr2.value = " O "
&nbsp;&nbsp;&nbsp; sqr2T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " O " &amp;&amp; sqr6 == " O " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr8T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr8.value = " O "
&nbsp;&nbsp;&nbsp; sqr8T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr7 == " O " &amp;&amp; sqr4T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr4.value = " O "
&nbsp;&nbsp;&nbsp; sqr4T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " O " &amp;&amp; sqr8 == " O " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr6T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr6.value = " O "
&nbsp;&nbsp;&nbsp; sqr6T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " O " &amp;&amp; sqr7 == " O " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " O " &amp;&amp; sqr8 == " O " &amp;&amp; sqr2T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr2.value = " O "
&nbsp;&nbsp;&nbsp; sqr2T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr6 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr4 == " O " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " O " &amp;&amp; sqr5 == " O " &amp;&amp; sqr8T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr8.value = " O "
&nbsp;&nbsp;&nbsp; sqr8T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr6 == " O " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " O " &amp;&amp; sqr9 == " O " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " O " &amp;&amp; sqr7 == " O " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else
&nbsp; {
&nbsp;&nbsp;&nbsp; computer()
&nbsp; }
&nbsp; check2()
}
function computer()
{
&nbsp; check2()
&nbsp; if(sqr1 == " X " &amp;&amp; sqr2 == " X " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " X " &amp;&amp; sqr3 == " X " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr6T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr6.value = " O "
&nbsp;&nbsp;&nbsp; sqr6T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " X " &amp;&amp; sqr6 == " X " &amp;&amp; sqr4T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr4.value = " O "
&nbsp;&nbsp;&nbsp; sqr4T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " X " &amp;&amp; sqr8 == " X " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr8 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr3 == " X " &amp;&amp; sqr2T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr2.value = " O "
&nbsp;&nbsp;&nbsp; sqr2T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " X " &amp;&amp; sqr6 == " X " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr7 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr8T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr8.value = " O "
&nbsp;&nbsp;&nbsp; sqr8T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr7 == " X " &amp;&amp; sqr4T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr4.value = " O "
&nbsp;&nbsp;&nbsp; sqr4T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " X " &amp;&amp; sqr8 == " X " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr6T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr6.value = " O "
&nbsp;&nbsp;&nbsp; sqr6T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr4 == " X " &amp;&amp; sqr7 == " X " &amp;&amp; sqr1T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; sqr1T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr5 == " X " &amp;&amp; sqr8 == " X " &amp;&amp; sqr2T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr2.value = " O "
&nbsp;&nbsp;&nbsp; sqr2T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr6 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr3T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; sqr3T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr4 == " X " &amp;&amp; sqr7T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; sqr7T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr2 == " X " &amp;&amp; sqr5 == " X " &amp;&amp; sqr8T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr8.value = " O "
&nbsp;&nbsp;&nbsp; sqr8T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr6 == " X " &amp;&amp; sqr9T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; sqr9T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr1 == " X " &amp;&amp; sqr9 == " X " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else if(sqr3 == " X " &amp;&amp; sqr7 == " X " &amp;&amp; sqr5T == 0 &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; sqr5T = 1;
&nbsp;&nbsp;&nbsp; turn = 0;
&nbsp; }
&nbsp; else
&nbsp; {
&nbsp;&nbsp;&nbsp; AI()
&nbsp; }
&nbsp; check2()
}

function AI()
{
&nbsp; vari()
&nbsp; if(document.tic.sqr5.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr5.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr5T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr1.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr1.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr1T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr9.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr9.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr9T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr6.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr6.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr6T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr2.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr2.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr2T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr8.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr8.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr8T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr3.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr3.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr3T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr7.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr7.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr7T = 1
&nbsp; }
&nbsp; else if(document.tic.sqr4.value == "&nbsp;&nbsp;&nbsp;&nbsp; " &amp;&amp; turn == 1)
&nbsp; {
&nbsp;&nbsp;&nbsp; document.tic.sqr4.value = " O "
&nbsp;&nbsp;&nbsp; turn = 0
&nbsp;&nbsp;&nbsp; sqr4T = 1
&nbsp; }
&nbsp; check2()
}

function reset()
{
&nbsp; document.tic.sqr1.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr2.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr3.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr4.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr5.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr6.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr7.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr8.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; document.tic.sqr9.value = "&nbsp;&nbsp;&nbsp;&nbsp; "
&nbsp; sqr1T = 0
&nbsp; sqr2T = 0
&nbsp; sqr3T = 0
&nbsp; sqr4T = 0
&nbsp; sqr5T = 0
&nbsp; sqr6T = 0
&nbsp; sqr7T = 0
&nbsp; sqr8T = 0
&nbsp; sqr9T = 0
&nbsp; vari()
&nbsp; turn = 0
&nbsp; moveCount = 0
}

function resetter()
{
&nbsp; reset()
}
&lt;/SCRIPT&gt;

&lt;FORM NAME="tic"&gt;
&lt;INPUT TYPE="button" NAME="sqr1" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr1.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr1.value = ' X '; sqr1T = 1; turn = 1; vari(); check();} else if(document.tic.sqr1.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr1.value = ' X '; sqr1T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr1.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr1.value = ' O '; sqr1T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr2" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr2.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr2.value = ' X '; sqr2T = 1; turn = 1; vari(); check();} else if(document.tic.sqr2.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr2.value = ' X '; sqr2T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr2.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr2.value = ' O '; sqr2T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr3" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr3.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr3.value = ' X '; sqr3T = 1; turn = 1; vari(); check();} else if(document.tic.sqr3.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr3.value = ' X '; sqr3T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr3.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr3.value = ' O '; sqr3T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;&lt;br&gt;
&lt;INPUT TYPE="button" NAME="sqr4" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr4.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr4.value = ' X '; sqr4T = 1; turn = 1; vari(); check();} else if(document.tic.sqr4.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr4.value = ' X '; sqr4T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr4.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr4.value = ' O '; sqr4T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr5" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr5.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr5.value = ' X '; sqr5T = 1; turn = 1; vari(); check();} else if(document.tic.sqr5.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr5.value = ' X '; sqr5T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr5.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr5.value = ' O '; sqr5T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr6" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr6.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr6.value = ' X '; sqr6T = 1; turn = 1; vari(); check();} else if(document.tic.sqr6.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr6.value = ' X '; sqr6T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr6.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr6.value = ' O '; sqr6T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;&lt;br&gt;
&lt;INPUT TYPE="button" NAME="sqr7" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr7.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr7.value = ' X '; sqr7T = 1; turn = 1; vari(); check();} else if(document.tic.sqr7.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr7.value = ' X '; sqr7T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr7.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr7.value = ' O '; sqr7T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr8" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr8.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr8.value = ' X '; sqr8T = 1; turn = 1; vari(); check();} else if(document.tic.sqr8.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr8.value = ' X '; sqr8T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr8.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr8.value = ' O '; sqr8T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;INPUT TYPE="button" NAME="sqr9" class="tictac" value="&nbsp;&nbsp;&nbsp;&nbsp; " onClick="if(document.tic.sqr9.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 1) {document.tic.sqr9.value = ' X '; sqr9T = 1; turn = 1; vari(); check();} else if(document.tic.sqr9.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 1 &amp;&amp; mode == 2) {document.tic.sqr9.value = ' X '; sqr9T = 1; turn = 0; vari(); player1Check()} else if(document.tic.sqr9.value == '&nbsp;&nbsp;&nbsp;&nbsp; ' &amp;&amp; turn == 0 &amp;&amp; mode == 2) {document.tic.sqr9.value = ' O '; sqr9T = 1; turn = 1; vari(); player1Check()} drawCheck()"&gt;
&lt;/form&gt;