<html>
<head>
</head>
<body>
<input type="button" id="b1" value=" " onclick="func(this)">
<input type="button" id="b2" value=" " onclick="func(this)" >
<input type="button" id="b3" value=" " onclick="func(this)">
<br>
<input type="button" id="b4" value=" " onclick="func(this)">
<input type="button" id="b5" value=" " onclick="func(this)">
<input type="button" id="b6" value=" " onclick="func(this)">
<br>
<input type="button" id="b7" value=" " onclick="func(this)">
<input type="button" id="b8" value=" " onclick="func(this)">
<input type="button" id="b9" value=" " onclick="func(this)">
<br>
<script>
var click = 10;
var state = 0;
function func(i)
{
var el_1 = document.getElementById("b1");
var el_2 = document.getElementById("b2");
var el_3 = document.getElementById("b3");
var el_4 = document.getElementById("b4");
var el_5 = document.getElementById("b5");
var el_6 = document.getElementById("b6");
var el_7 = document.getElementById("b7");
var el_8 = document.getElementById("b8");
var el_9 = document.getElementById("b9");
if (i.value == " " && click == 10)
{
i.value="X";
click = 20;
}
if (i.value == " " && click == 20)
{
i.value="O";
click = 10;
}
if (el_1.value == "X" && el_2.value == "X" && el_3.value == "X") state =1;
if (el_4.value == "X" && el_5.value == "X" && el_6.value == "X") state =1;
if (el_7.value == "X" && el_8.value == "X" && el_9.value == "X") state =1;
if (el_1.value == "X" && el_4.value == "X" && el_7.value == "X") state=1;
if (el_2.value == "X" && el_5.value == "X" && el_8.value == "X") state =1;
if (el_3.value == "X" && el_6.value == "X" && el_9.value == "X") state =1;
if (el_1.value == "X" && el_5.value == "X" && el_9.value == "X") state =1;
if (el_3.value == "X" && el_5.value == "X" && el_7.value == "X") state=1;
if (el_1.value == "O" && el_2.value == "O" && el_3.value == "O") state = 2;
if (el_4.value == "O" && el_5.value == "O" && el_6.value == "O") state = 2;
if (el_7.value == "O" && el_8.value == "O" && el_9.value == "O") state = 2;
if (el_1.value == "O" && el_4.value == "O" && el_7.value == "O") state = 2;
if (el_2.value == "O" && el_5.value == "O" && el_8.value == "O") state = 2;
if (el_3.value == "O" && el_6.value == "O" && el_9.value == "O") state = 2;
if (el_1.value == "O" && el_5.value == "O" && el_9.value == "O") state = 2;
if (el_3.value == "O" && el_5.value == "O" && el_7.value == "O") state = 2;
if (state == 1)
{
alert("Крестики выиграли");
location.reload();
}
if (state == 2)
{
alert("Нолики выиграли");
location.reload();
}
}
</script>
</body>
</html>
|