Спасибо, но я не интересовался логикой решения задачи.
Код:
|
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;
} |
На каждую кнопку по функции, на каждый клик по условии. Разве это не является неграмотным решением или такое допустимо?