Hot answers tagged minesweeper
10
Imagine the following setup:
1 1 1 1 1 1
1 0 0 0 0 1
1 0 0 0 0 1
1 0 0 0 0 1
1 0 0 0 0 1
1 1 1 1 1 1
As a side note, I refer to squares in the matrix like this: (row, column). I've represented mines with "1" and empty spaces with "0". Assume the user clicks on the empty space at (2, 2) (the corner at the top-left is (0, 0)).
This is what would happen:
...
7
I can't tell from your (lack of) code, but you are probably just missing a stop to make sure that you don't handle tiles which have already been handled. At the top of the function you should put something like:
if(thistile.hasbeenhandled){
return;
}
else{
thistile.hasbeenhandled=true;
}
Otherwise any two adjacent tiles that are to display empty ...
4
eBuisiness's answer is correct. But you're setting the HasBeenHandled flag after trying to update all the neighbors which then causes a stack overflow. You should instead set the flag before doing anything else.
EDIT:
You've also made typos in the if statements.
if (Bottom.btn != null)
set_text_of_button(Bottom.btn);
if (Bottom_Left.btn != null)
...
Only top voted, non community-wiki answers of a minimum length are eligible