previous

page 28

next
square_clicked() with check(), g_misses and g_ships added
function square_clicked(image) {
if (g_shape=='') {
alert('please choose a shape');
} else {
var v=g_shape.getAttribute('v');
var answer=image.getAttribute('a');
if (v==answer || v==8) {
image.src=g_shape.src;
} else {
image.src='images/wrong/'+v+'.png';
g_misses++;
}
image.setAttribute('v',v);
check();
if (g_ships==8) alert('All ships found. Number of misses: '+g_misses+'.');
}
}
fill() with g_misses added
function fill(row,col) {
var id=rc2id(row,col);
var el=document.getElementById(id);
var v=el.getAttribute('v');
if (v==0) {
var a=get_a(row,col);
if (a==7) {
el.src='images/right/7.png';
} else {
el.src='images/wrong/7.png';
g_misses++;
}
}
}

And that's as far as I plan to go but I'm sure you can see where there's still room for improvement!

previous
next