-
Notifications
You must be signed in to change notification settings - Fork 0
/
practice.js
57 lines (57 loc) · 2.5 KB
/
practice.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var temp=2;
var click_check=true;
document.getElementById("0").onclick=function(){if(click_check){play("0");}}
document.getElementById("1").onclick=function(){if(click_check){play("1");}}
document.getElementById("2").onclick=function(){if(click_check){play("2");}}
document.getElementById("3").onclick=function(){if(click_check){play("3");}}
document.getElementById("4").onclick=function(){if(click_check){play("4");}}
document.getElementById("5").onclick=function(){if(click_check){play("5");}}
document.getElementById("6").onclick=function(){if(click_check){play("6");}}
document.getElementById("7").onclick=function(){if(click_check){play("7");}}
document.getElementById("8").onclick=function(){if(click_check){play("8");}}
function play(identity){
turn();
if(temp%2==0){document.getElementById(identity).innerHTML="X";
temp=2;
check();
}
else{document.getElementById(identity).innerHTML="O";
check();}
temp++;
}
function turn(){
if(temp%2==0){document.getElementById("status").innerHTML="Its O's turn";}
else{document.getElementById("status").innerHTML="Its X's turn";}}
function check(){
var a=document.getElementById("0").innerHTML;
var b=document.getElementById("1").innerHTML;
var c=document.getElementById("2").innerHTML;
var d=document.getElementById("3").innerHTML;
var e=document.getElementById("4").innerHTML;
var f=document.getElementById("5").innerHTML;
var g=document.getElementById("6").innerHTML;
var h=document.getElementById("7").innerHTML;
var i=document.getElementById("8").innerHTML;
if((a==b&&b==c&&a!="")||(d==e&&e==f&&d!="")||(g==h&&h==i&&g!="")||(a==d&&d==g&&a!="")||(b==e&&e==h&&b!="")||(c==f&&f==i&&c!="")||(a==e&&e==i&&a!="")||(c==e&&e==g&&c!="")){
document.getElementById("status").innerHTML="Game over";
click_check=false;
}
if(a!=""&&b!=""&&c!=""&&d!=""&&e!=""&&f!=""&&g!=""&&h!=""&&i!=""){
document.getElementById("status").innerHTML="Game tie";
click_check=false;
}
}
function restart(){
temp=2;
click_check=true;
document.getElementById("status").innerHTML="Player 1 start with X";
var a=document.getElementById("0").innerHTML="";
var b=document.getElementById("1").innerHTML="";
var c=document.getElementById("2").innerHTML="";
var d=document.getElementById("3").innerHTML="";
var e=document.getElementById("4").innerHTML="";
var f=document.getElementById("5").innerHTML="";
var g=document.getElementById("6").innerHTML="";
var h=document.getElementById("7").innerHTML="";
var i=document.getElementById("8").innerHTML="";
}