previous

page 15

next
square_clicked(el)
function square_clicked(el) {
if (g_player && g_squares[el.id]==0) {
g_player=false;
do_x(el.id);
if (check()) {
show_result();
g_message_el.textContent='computer wins';
g_computer_count++;
var el=document.getElementById('computer');
el.textContent=g_computer_count;
} else {
setTimeout(computer,2000);
}
}
}
computer()
...
// no good move found - make id_loser move & lose
do_x(id_loser);
check();
show_result();
g_message_el.textContent='you win';
g_player_count++;
var el=document.getElementById('player');
el.textContent=g_player_count;
}
previous
next