-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathttc.js
193 lines (185 loc) · 9.85 KB
/
ttc.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*Author:Mahbubul Hasan Sakib*/
var c = 1;
var flag=0;
function fun(s)
{
document.getElementById(s).style.margin = "0px";
if (flag == 0) {
if (c % 2 != 0) {
if (document.getElementById(s).innerText!='O'){
document.getElementById(s).innerHTML = "<b>X</b>";
c++;
}
}
else {
if(document.getElementById(s).innerText!='X'){
document.getElementById(s).innerHTML = "<b>O</b>";
c++;
}
}
findres(c - 1);
}
}
function findres(r)
{
if(flag==0){
if(document.getElementById('b1').innerText=="X"&& document.getElementById('b2').innerText=="X" &&document.getElementById('b3').innerText=="X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b2').style.backgroundColor = "grey";
document.getElementById('b3').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b4').innerText == "X" && document.getElementById('b5').innerText == "X" && document.getElementById('b6').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b4').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b6').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b7').innerText == "X" && document.getElementById('b8').innerText == "X" && document.getElementById('b9').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b7').style.backgroundColor = "grey";
document.getElementById('b8').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b1').innerText == "X" && document.getElementById('b4').innerText == "X" && document.getElementById('b7').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b4').style.backgroundColor = "grey";
document.getElementById('b7').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b2').innerText == "X" && document.getElementById('b5').innerText == "X" && document.getElementById('b8').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b2').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b8').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b3').innerText == "X" && document.getElementById('b6').innerText == "X" && document.getElementById('b9').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b3').style.backgroundColor = "grey";
document.getElementById('b6').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b1').innerText == "X" && document.getElementById('b5').innerText == "X" && document.getElementById('b9').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b3').innerText == "X" && document.getElementById('b5').innerText == "X" && document.getElementById('b7').innerText == "X")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! X is winner☻</b>";
document.getElementById('b3').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b7').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b1').innerText == "O" && document.getElementById('b2').innerText == "O" && document.getElementById('b3').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b2').style.backgroundColor = "grey";
document.getElementById('b3').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b4').innerText == "O" && document.getElementById('b5').innerText == "O" && document.getElementById('b6').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b4').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b6').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b7').innerText == "O" && document.getElementById('b8').innerText == "O" && document.getElementById('b9').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b7').style.backgroundColor = "grey";
document.getElementById('b8').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b1').innerText == "O" && document.getElementById('b4').innerText == "O" && document.getElementById('b7').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b4').style.backgroundColor = "grey";
document.getElementById('b7').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b2').innerText == "O" && document.getElementById('b5').innerText == "O" && document.getElementById('b8').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b2').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b8').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b3').innerText == "O" && document.getElementById('b6').innerText == "O" && document.getElementById('b9').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b3').style.backgroundColor = "grey";
document.getElementById('b6').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b1').innerText == "O" && document.getElementById('b5').innerText == "O" && document.getElementById('b9').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b1').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b9').style.backgroundColor = "grey";
flag=1;
}
else if (document.getElementById('b3').innerText == "O" && document.getElementById('b5').innerText == "O" && document.getElementById('b7').innerText == "O")
{
document.getElementsByTagName("p")[0].innerHTML = "<b>Congrats! O is winner☻</b>";
document.getElementById('b3').style.backgroundColor = "grey";
document.getElementById('b5').style.backgroundColor = "grey";
document.getElementById('b7').style.backgroundColor = "grey";
flag=1;
}
}
if (flag == 1) {
//document.getElementsByTagName("p")[1].innerHTML = "Reload page to start new game";//applause.mp3
document.getElementById("load").style.visibility = "visible";
document.getElementById("load").style.textAlign="center";
var audio = new Audio('applause.mp3');
audio.play();
}
else
if (r == 9 && flag == 0) {
//oh_no.mp3
var audio = new Audio('Wrong.mp3');
audio.play();
document.getElementsByTagName("p")[0].innerHTML = "Match Draw☹";
document.getElementById("load").style.visibility = "visible";
document.getElementById("load").style.textAlign = "center";
document.getElementById('b1').style.backgroundColor = "red";
document.getElementById('b2').style.backgroundColor = "red";
document.getElementById('b3').style.backgroundColor = "red";
document.getElementById('b4').style.backgroundColor = "red";
document.getElementById('b5').style.backgroundColor = "red";
document.getElementById('b6').style.backgroundColor = "red";
document.getElementById('b7').style.backgroundColor = "red";
document.getElementById('b8').style.backgroundColor = "red";
document.getElementById('b9').style.backgroundColor = "red";
//document.getElementsByTagName("p")[1].innerHTML = "Reload page to start new game";
}
}
function reload()
{
location.reload();
}