repl.it
@ThinOldGoose/

Tic-Tac-Toe 2 people

HTML, CSS, JS

2 people tic tac toe

fork
loading
Files
  • index.html
  • script.js
  • style.css
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
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <title>repl.it</title>
    <link href="style.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <script src="script.js"></script>

<center>
<SCRIPT name = "JavaScript">
function variables(){
    t = 1;
    change = 1;    
    empty1 = -1;
    empty2 = -1;
    empty3 = -1;
    empty4 = -1;
    empty5 = -1;
    empty6 = -1;
    empty7 = -1;
    empty8 = -1;
    empty9 = -1;
    return;
    whogoesnow = "PLAYER 1"
}

function win(){
  if   (empty1==empty2 && empty2==empty3 && empty3==0 ||
empty4==empty5 && empty5==empty6 && empty6==0 ||    
        empty7==empty8 && empty8==empty9 && empty9==0 ||
        empty1==empty4 && empty4==empty7 && empty7==0 ||
        empty2==empty5 && empty5==empty8 && empty8==0 ||
        empty3==empty6 && empty6==empty9 && empty9==0 ||
        empty1==empty5 && empty5==empty9 && empty9==0 ||
        empty3==empty5 && empty5==empty7 && empty7==0 ){
        alert ("PLAYER 1: YOU WIN !!!");          
        history.go(0)  
  }
  if   (empty1==empty2 && empty2==empty3 && empty3==1 ||
empty4==empty5 && empty5==empty6 && empty6==1 ||    
        empty7==empty8 && empty8==empty9 && empty9==1 ||
        empty1==empty4 && empty4==empty7 && empty7==1 ||
        empty2==empty5 && empty5==empty8 && empty8==1 ||
        empty3==empty6 && empty6==empty9 && empty9==1 ||
        empty1==empty5 && empty5==empty9 && empty9==1 ||
        empty3==empty5 && empty5==empty7 && empty7==1 ){
        alert ("PLAYER 2: YOU WIN !!!");
	history.go(0)
  }
}

function turnchange(t){
  if (change == 1)  {
    if (t == 0){
        t = 1;
        whogoesnow = "PLAY : PLAYER " + 1
    }
    else {
        t = 0;
	whogoesnow = "PLAY : PLAYER " + 2
    }
    
  }
  else {
    t = t;
  }
  change = 1  
  return (t); 
}

function changing(clicked){
if (clicked == 1){            
   spot = empty1 ;}
if (clicked == 2){
   spot = empty2 ;}
if (clicked == 3){
   spot = empty3 ;}
if (clicked == 4){
   spot = empty4 ;}
if (clicked == 5){
   spot = empty5 ;}
if (clicked == 6){
   spot = empty6 ;}
if (clicked == 7){
   spot = empty7 ;}
if (clicked == 8){
   spot = empty8 ;}
if (clicked == 9){
   spot = empty9 ;}

if (spot == -1){
   if (t == 0){
      xo = "  O  " ;	       	          
      spot = 0             
   }
   else {
      xo = "  X  "  ;              
      spot = 1	     
   }                              
   if (clicked == 1){            
      empty1 = spot;}
   if (clicked == 2){
      empty2 = spot ;}
   if (clicked == 3){
      empty3 = spot ;}
   if (clicked == 4){
      empty4 = spot ;}
   if (clicked == 5){
      empty5 = spot ;}
   if (clicked == 6){
      empty6 = spot ;}
   if (clicked == 7){
      empty7 = spot ;}
   if (clicked == 8){
      empty8 = spot ;}
   if (clicked == 9){
      empty9 = spot ;}
} 
else {
   if (spot == 0){
       xo = "  O  ";}
   if (spot == 1){
       xo = "  X  ";}
   change = 0
}
return (xo) ;
}

function change_b1(form){	
    clicked = 1;    
    changing(clicked) ;     
    t = turnchange(t) ;  
    form.b1.value = xo; 
    form.whoseturn.value = whogoesnow        
    win(); 
   return;
}
function change_b2(form){	
    clicked = 2;
    changing(clicked) ;   
    form.b2.value = xo;    
    t = turnchange(t) ;
    form.whoseturn.value = whogoesnow      
    win();
    return;
}

function change_b3(form){	
    clicked = 3;
    changing(clicked) ;
    form.b3.value = xo;         
    t = turnchange(t) ;    
    form.whoseturn.value = whogoesnow 
    win();
    return;   
}

function change_b4(form){	
    clicked = 4;
    changing(clicked) ;
    form.b4.value = xo;    
    t = turnchange(t) ;    
    form.whoseturn.value = whogoesnow     
    win();
    return;
}

function change_b5(form){	
    clicked = 5;
    changing(clicked) ;
    form.b5.value = xo;    
    t = turnchange(t) ;
    form.whoseturn.value = whogoesnow     
    win();     
    return;
}

function change_b6(form){	
    clicked = 6;
    changing(clicked) ;
    form.b6.value = xo;    
    t = turnchange(t) ;
    form.whoseturn.value = whogoesnow     
    win();
    return;
}

function change_b7(form){	
    clicked = 7;
    changing(clicked) ;
    form.b7.value = xo;    
    t = turnchange(t) ; 
    form.whoseturn.value = whogoesnow    
    win();
    return;
}

function change_b8(form){	
    clicked = 8;
    changing(clicked) ;    
    form.b8.value = xo;    
    t = turnchange(t) ;
    form.whoseturn.value = whogoesnow 
    win();    
    return;
}

function change_b9(form){	
    clicked = 9;
    changing(clicked) ;
    form.b9.value = xo;    
    t = turnchange(t) ;
    form.whoseturn.value = whogoesnow  
    win();
    return;
}
</SCRIPT>


<SCRIPT name = "JavaScript">
variables();
</SCRIPT>

<FORM>
<input type = "button" name = "whoseturn" 
 value = "PLAY: PLAYER  1">	 
<br><br><br><br>
<table>
<tr><td><input type = "button" name = "b1" value = "      "		 onClick =
change_b1(this.form)>  
    <td><input type = "button" name = "b2" value = "      "		 onClick = change_b2(this.form)> 
    <td><input type = "button" name = "b3" value = "      "		 onClick =
change_b3(this.form)> 
<tr><td><input type = "button" name = "b4" value = "      "		 onClick =
change_b4(this.form)> 
    <td><input type = "button" name = "b5" value = "      "		 onClick = change_b5(this.form)> 
    <td><input type = "button" name = "b6" value = "      "		 onClick =
change_b6(this.form)> 
<tr><td><input type = "button" name = "b7" value = "      "		 onClick =
change_b7(this.form)> 
    <td><input type = "button" name = "b8" value = "      "		 onClick = change_b8(this.form)>   
    <td><input type = "button" name = "b9" value = "      "
onClick = change_b9(this.form)> 
</table>
<br><br>

<INPUT TYPE="button" VALUE="New Round" onClick="history.go(0)">
</center>
  </body>
</html>
result
console