forked from starrohan999/Hacktoberfest-Accepted
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTicTacToe-Game.html
100 lines (91 loc) · 3.57 KB
/
TicTacToe-Game.html
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
<html>
<head><title>game</title>
</head>
<body>
<center>
<h1 >TIC-TAC-TOE</h1>
<table><tr>
<td id="X" onclick = change(this.id)>X</td>
<td id="O" onclick = change(this.id)>O</td>
<td id="lbl"> You have Selected:-</td>
<td id="sel" onclick = change()>selected</td>
</tr>
</table>
<table onclick = won() >
<tr>
<td id="00" onclick = change(this.id)>00</td>
<td id="01" onclick = change(this.id)>01</td>
<td id="02" onclick = change(this.id)>02</td>
</tr>
<tr>
<td id="10" onclick = change(this.id)>10</td>
<td id="11" onclick = change(this.id)>11</td>
<td id="12" onclick = change(this.id)>12</td>
</tr>
<tr>
<td id="20" onclick = change(this.id)>20</td>
<td id="21" onclick = change(this.id)>21</td>
<td id="22" onclick = change(this.id)>22</td>
</tr>
</table>
</center>
<style>
body{background-color:darkolivegreen; color:lawngreen;}
td{border-style: solid; padding: 50; border-color: lawngreen; }
td:hover{background-color: darkblue;}
table{border-style:dashed ; border-width: 10; border-color:lawngreen;}
</style>
<script>
d = "tes";
function change(clicked_id){
var e = document.getElementById(clicked_id);
if(clicked_id=="X" || clicked_id=="O"){
d = e.innerText;
document.getElementById("sel").innerHTML=d;
}
else{
e.innerText=d;
}
}
function won(){
var val = [];
for (let i=0; i<3; i++){
val[i]=[];
for (let j=0; j<3; j++){
i = String(i);
x = i+j;
var e = document.getElementById(x)
i = parseInt(i);
console.log(i.j);
val[i][j] = e.innerHTML;
console.log(val[i][j]);
}
}
if(val[0][0]==val[0][1] && val[0][1]==val[0][2] ){
alert(val[0][0]+" "+" won");
}
if(val[0][0]==val[1][0] && val[1][0]==val[2][0] ){
alert(val[0][0]+" "+" won");
}
if(val[0][0]==val[1][1] && val[1][1]==val[2][2] ){
alert(val[0][0]+" "+" won");
}
if(val[0][1]==val[1][1] && val[1][1]==val[2][1] ){
alert(val[0][1]+" "+" won");
}
if(val[0][2]==val[1][2] && val[1][2]==val[2][2] ){
alert(val[0][2]+" "+" won");
}
if(val[0][2]==val[1][1] && val[1][1]==val[2][0] ){
alert(val[0][2]+" "+" won");
}
if(val[1][0]==val[1][1] && val[1][1]==val[1][2] ){
alert(val[1][0]+" "+" won");
}
if(val[2][0]==val[2][1] && val[2][1]==val[2][2] ){
alert(val[2][0]+" "+" won");
}
}
</script>
</body>
</html>