-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
264 lines (205 loc) · 6.6 KB
/
index.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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="css/tictactoe.css">
<title>Tic-tac-toe</title>
<script type="text/javascript">
//var for boxes
var a=0;
var b=0;
var c=0;
var d=0;
var e=0;
var f=0;
var g=0;
var h=0;
var i=0;
//var for whos turn
var whose_move=1;
//for id of block cliked
var temp='';
//for ok move
var ok=0;
var who_won=0;
var count_player1_win=0;
var count_player2_win=0;
var count_ties=0;
//functions
function Move(c){
temp=c;
ok=0;
//for p1
if(whose_move==1){
check_space();
if(ok==1)
{ document.getElementById(c).src="o.jpg";
whose_move=2;
process();
}
else
{
alert("Box is already occupied .For help click How to play?");}
}//if ends
//for p2
else
{check_space();
if(ok==1)
{ document.getElementById(c).src="x.png";
whose_move=1;
process();
}
else
{
alert("Box is already occupied .For help click How to play?");}
}//else ends
}//whose_move ends
//fun checkspace
function check_space(){
if((temp=='A') && (a==0)){
ok=1;
if(whose_move==1) a=1;
if(whose_move==2) a=2;
}
if((temp=='B') && (b==0)){
ok=1;
if(whose_move==1) b=1;
if(whose_move==2) b=2;
}
if((temp=='C') && (c==0)){
ok=1;
if(whose_move==1) c=1;
if(whose_move==2) c=2;
}
if((temp=='D') && (d==0)){
ok=1;
if(whose_move==1) d=1;
if(whose_move==2) d=2;
}
if((temp=='E') && (e==0)){
ok=1;
if(whose_move==1) e=1;
if(whose_move==2) e=2;
}
if((temp=='F') && (f==0)){
ok=1;
if(whose_move==1) f=1;
if(whose_move==2) f=2;
}
if((temp=='G') && (g==0)){
ok=1;
if(whose_move==1) g=1;
if(whose_move==2) g=2;
}
if((temp=='H') && (h==0)){
ok=1;
if(whose_move==1) h=1;
if(whose_move==2) h=2;
}
if((temp=='I') && (i==0)){
ok=1;
if(whose_move==1) i=1;
if(whose_move==2) i=2;
}
}//checkspace ends
function process()
{ check_win();
if (who_won==1)
{ alert("Cheers!! Player 1 wins this game! click on play again to try again!!");
count_player1_win ++;
document.getElementById('player1').value=count_player1_win;
}
else if(who_won==2)
{ alert("Cheers!! Player 2 wins this game! click on play again to try again!!");
count_player2_win ++;
document.getElementById('player2').value=count_player2_win;
}
else if(who_won==3)
{ alert("Oh! Its a tie!! click on play again to try again!");
count_ties ++;
document.getElementById('ties').value=count_ties;
}
}//process ends
function check_win(){
if((a==1)&&(b==1)&&(c==1)) who_won=1;
if((d==1)&&(e==1)&&(f==1)) who_won=1;
if((g==1)&&(h==1)&&(i==1)) who_won=1;
if((a==1)&&(d==1)&&(g==1)) who_won=1;
if((e==1)&&(b==1)&&(h==1)) who_won=1;
if((c==1)&&(f==1)&&(i==1)) who_won=1;
if((i==1)&&(e==1)&&(a==1)) who_won=1;
if((c==1)&&(g==1)&&(e==1)) who_won=1;
if((a==2)&&(b==2)&&(c==2)) who_won=2;
if((d==2)&&(e==2)&&(f==2)) who_won=2;
if((g==2)&&(h==2)&&(i==2)) who_won=2;
if((a==2)&&(d==2)&&(g==2)) who_won=2;
if((e==2)&&(b==2)&&(h==2)) who_won=2;
if((c==2)&&(f==2)&&(i==2)) who_won=2;
if((i==2)&&(e==2)&&(a==2)) who_won=2;
if((c==2)&&(g==2)&&(e==2)) who_won=2;
if((a!=0)&&(b!=0)&&(c!=0)&&(d!=0)&&(e!=0)&&(f!=0)&&(g!=0)&&(h!=0)&&(i!=0)&&who_won==0) who_won=3;
}//check winn end
//play again
function playAgain(){
whose_move=1;
a=0;
b=0;
c=0;
d=0;
e=0;
f=0;
g=0;
i=0;
h=0;
temp='';
ok=0;
who_won=0;
document.getElementById('A').src="";
document.getElementById('B').src="";
document.getElementById('C').src="";
document.getElementById('D').src="";
document.getElementById('E').src="";
document.getElementById('F').src="";
document.getElementById('G').src="";
document.getElementById('H').src="";
document.getElementById('I').src="";
} //play againends
function help(){
alert("Welcome to Tic-tac-toe! player1 plays as O's and player2 as X's. Select the square you want to put your variable into by clicking them. Any square can be occupied once. The first player to get 3 adjacent variables in a row coloumn or diagonal Wins!!.So watch out others move as well!! AND LET THE GAME BEGIN ");
}
</script>
<div id="head">Let the game begin!!</div>
</head>
<body>
<!--table for game-->
<table align="center" id="game_table">
<tr>
<td style="background-color:#97CBFF;"><a href="javascript:Move('A')"><img src="" width="100px" height="100px" id="A"/></a></td>
<td ><a href="javascript:Move('B')"><img src="" width="100px" height="100px" id="B"/></a></td>
<td style="background-color:#97CBFF;"><a href="javascript:Move('C')"><img src="" width="100px" height="100px" id="C"/></a></td>
</tr>
<tr>
<td ><a href="javascript:Move('D')"><img src="" width="100px" height="100px" id="D"/></a></td>
<td style="background-color:#97CBFF;"><a href="javascript:Move('E')"><img src="" width="100px" height="100px" id="E"/></a></td>
<td ><a href="javascript:Move('F')"><img src="" width="100px" height="100px" id="F"/></a></td>
</tr>
<tr>
<td style="background-color:#97CBFF;"><a href="javascript:Move('G')"><img src="" width="100px" height="100px" id="G"/></a></td>
<td ><a href="javascript:Move('H')"><img src="" width="100px" height="100px" id="H"/></a></td>
<td style="background-color:#97CBFF;"><a href="javascript:Move('I')"><img src="" width="100px" height="100px" id="I"/></a></td>
</tr>
<!--showing status-->
<table id="wins" align="center">
<center> <a style="font-family:'Comic Sans MS', cursive; color:#06F;">No of wins of player 1,2 and ties!</a></center>
<tr><td><input type="text" size="5" id="player1" value="0" ></td><td>Player1</td></tr>
<tr><td><input type="text" size="5" id="player2" value="0" ></td><td>Player2</td></tr>
<tr><td><input type="text" size="5" id="ties" value="0" ></td><td>Tie</td></tr>
</table>
</table>
<!--button for help and restore-->
<center>
<input type="button" value="How to play?" id="help" style="color:#903; width:100px; height:40px; margin-top:20px;" onClick="help();">
<input type="button" value="Play Again" id="reset" style="color:#30C; width:100px; height:40px;" onClick="playAgain();"/>
</center>
</body>
</html>