previous

page 26

next
check()
function check() {
var parts=[0,1,1,2,2,3,3,4,4];
var counts=[];
for (var i=0;i<9;i++) counts[i]=0;
for (var id=0;id<100;id++) {
var el=document.getElementById(id);
var sn=el.getAttribute('sn');
if (sn>0) {
var a=el.getAttribute('a');
var v=el.getAttribute('v');
if (a==v) counts[sn]++;
}
}
for (var i=1;i<9;i++) {
if (counts[i]==parts[i]) {
var el=document.getElementById('s'+i);
el.style.opacity=1;
}
}
}

To keep track of progress, we need two new globals:

globals.js
var g_shape='';
var g_ships=0;
var g_misses=0;

When g_ships reaches 8, the game is complete.

previous
next