I’m making a jquery minesweeper and am currently working on the revealing function for when you click a block with 0 adjacent mines. The intended result is to loop through all 8 adjacent blocks reveal those blocks, if they are also ‘0‘ blocks, it recurs for that block:
function reveal(block) {
block.removeClass('hide');
var thex = getXY(block)[0];
var they = getXY(block)[1];
if (blockNumber(block) == '0') {
alert('test');
--they;
--thex;
var nearmines = 0;
for (mody=0;mody<3;mody++){
for (modx=0;modx<3;modx++){
var newx = thex + modx;
var newy = they + mody;
reveal(bl(newx,newy));
}
}
}
}
Currently this function is stopping after the first block checked for each time the function iterates. It seems as though the call is breaking the for loops.
I’m pretty sure you have an infinite recursion – both directly and indirectly. Calling
reveal(bl(2,2))will callreveal(bl(2,2))in the loop. In addition, ifbl(1,2)is also0, it will also callreveal(bl(2,2))when searching for each neighbor.You should check for the “base case” in the first line: