I'm currently learning JavaScript, remaking games from scratch, and my current project is Minesweeper. When trying to create a recursive function that shows spaces around the clicked space, I ran into the problem that it ends too soon, apparently for no reason.
You can read all the code (for now) here: pastebin.com
or refer to only standalone function below:
function showAdjacent(block) {
if(block.minesNextTo != 0)
return;
console.log(block.row+','+block.col);
block.uncovered = true;
block.hidden = false;
console.log(block.adjacentBlocks.length);
for(i = 0; i < block.adjacentBlocks.length; i++)
block.adjacentBlocks[i].hidden = false;
for(i = 0; i < block.adjacentBlocks.length; i++) {
if(!block.adjacentBlocks[i].uncovered)
showAdjacent(block.adjacentBlocks[i]);
}
}
(and yes, I know that this function should be launched not only if the block has zero mines next to it, it is easier to test)
source
share