-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjs_tick_tac_toe.html
183 lines (140 loc) · 4.72 KB
/
js_tick_tac_toe.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
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
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<style type="text/css">
.main{
text-align: center;
margin-left: 520px;
}
.in
{
border: 5px solid black;
width: 50px;
height: 50px;
padding: 50px;
font-size: 70px;
font-family: arial;
font-weight: bolder;
}
.left
{float:left;}
.clear{
clear: both;
}
.notice{
font-size: 40px;
font-family: verdana;
}
.up{border-top: 0px;}.right{border-right: 0px;}.bottom{border-bottom: 0px;}.lft{border-left: 0px;}
.head{
text-align: center;
padding: 20px;
font-family: Goudy Stout;
font-weight: lighter;
color: #6C6C6C;
font-size: 40px;
margin-bottom: 40px;
}
button{
display: ; color: #FFFFFF;
background-color: #107054;
border: none;
padding: 14px;
font-family: verdana;
font-size: 18px;
cursor: pointer;
border-radius: 100px;
}
button:hover{
}
</style>
<script type="text/javascript">
var a="0";
var b="0";
function fn(x)
{
if(x.innerHTML=="" && b==0)
{
if (a%2==0)
{
x.innerHTML="O"
if(a==8){tie.style.display="";
restart.style.display="";}
}
else
{
x.innerHTML="X"
if(a==8){tie.style.display="";
restart.style.display="";}
}
a++;
}
fn2(val0,val1,val2);
fn2(val3,val4,val5);
fn2(val6,val7,val8);
fn2(val0,val3,val6);
fn2(val1,val4,val7);
fn2(val2,val5,val8);
fn2(val8,val4,val0);
fn2(val2,val4,val6);
}
function fn2(p,q,r) {
if (p.innerHTML=="O" && q.innerHTML=="O" && r.innerHTML=="O") {
// alert("sajhsj");
owin.style.display="";
restart.style.display="";
tie.style.display="none";
b++;
}
else if (p.innerHTML=="X" && q.innerHTML=="X" && r.innerHTML=="X") {
awin.style.display="";
restart.style.display="";
tie.style.display="none";
b++;
}
// else if(){
// restart.style.display="";
// }
}
// if(val0.innerHTML=="O" && val1.innerHTML=="O" && val2.innerHTML=="O" || val3.innerHTML=="O" && val4.innerHTML=="O" && val5.innerHTML=="O" || val6.innerHTML=="O" && val7.innerHTML=="O" && val8.innerHTML=="O" || val0.innerHTML=="O" && val3.innerHTML=="O" && val6.innerHTML=="O" ||val1.innerHTML=="O" && val4.innerHTML=="O" && val7.innerHTML=="O" ||val2.innerHTML=="O" && val5.innerHTML=="O" && val8.innerHTML=="O" || val0.innerHTML=="O" && val4.innerHTML=="O" && val8.innerHTML=="O" || val2.innerHTML=="O" && val4.innerHTML=="O" && val6.innerHTML=="O")
// {
// owin.style.display="";
// b++;
// restart.style.display="";
// }
// else if(val0.innerHTML=="X" && val1.innerHTML=="X" && val2.innerHTML=="X" || val3.innerHTML=="X" && val4.innerHTML=="X" && val5.innerHTML=="X" || val6.innerHTML=="X" && val7.innerHTML=="X" && val8.innerHTML=="X" || val0.innerHTML=="X" && val3.innerHTML=="X" && val6.innerHTML=="X" ||val1.innerHTML=="X" && val4.innerHTML=="X" && val7.innerHTML=="X" ||val2.innerHTML=="X" && val5.innerHTML=="X" && val8.innerHTML=="X" || val0.innerHTML=="X" && val4.innerHTML=="X" && val8.innerHTML=="X" || val2.innerHTML=="X" && val4.innerHTML=="X" && val6.innerHTML=="X")
// {
// awin.style.display="";
// b++;
// restart.style.display="";
// }
function fn1()
{
location.reload();
}
</script>
<body style="background: #E4E4E4">
<div class="head">
Tic Tac Toe
</div>
<div class="main left">
<div class="in left up lft" onclick="fn(this)" id="val0"></div>
<div class="in left up" onclick="fn(this)" id="val1"></div>
<div class="in left up right" onclick="fn(this)" id="val2"></div>
<div class="in clear left lft" onclick="fn(this)" id="val3"></div>
<div class="in left" onclick="fn(this)" id="val4"></div>
<div class="in left right" onclick="fn(this)" id="val5"></div>
<div class="in clear left lft bottom" onclick="fn(this)" id="val6"></div>
<div class="in left bottom" onclick="fn(this)" id="val7"></div>
<div class="in left right bottom" onclick="fn(this)" id="val8"></div>
</div>
<div style="text-align: center; " class="car">
<div class="notice right" style="display: none; margin-bottom: 10px; color: #7B00C9;" id="owin" >O WON</div>
<div class="notice right" style="display: none; margin-bottom: 10px; color: #7B00C9;" id="awin" >X WON</div>
<div class="notice right" style="display: none; margin-bottom: 10px; color: #7B00C9;" id="tie" >Match Tied!</div>
<button onclick="fn1()" style="display: none;" id="restart" >Restart</button>
</div>
</body>
</html>