I am trying to build a simple minesweeper game. The game gets stuck in an infinite recursion whenever a user clicks on a tile which is not a mine...
I have used the following function code for the click event..
When a user clicks on a tile which is not a mine, its adjacent tiles are to be checked for a mine and the process repeats.... I have used a recursive function which disables the tiles for which adjacent tile is not a mine...
protected void set_text_of_button(Button btn)
{
//all these objects specify the location of adjacent tiles
Block Top, Top_Left, Top_Right, Left, Right, Bottom, Bottom_Left, Bottom_Right;
//code to specify the location of adjacent tiles...
//if adjacent tile is a mine then display the total number of tiles....
//recursive function should end in this if part..
else
{
//recursive calls for all the adjacent tiles..
if (Top != null && !Top.Mine)
set_text_of_button(Top.btn); //recursive call
if (Top_Left != null && !Top_Left.Mine)
set_text_of_button(Top_Left.btn);
if (Top_Right != null && !Top_Right.Mine)
set_text_of_button(Top_Right.btn);
if (Left != null && !Left.Mine)
set_text_of_button(Left.btn);
if (Right != null && !Right.Mine)
set_text_of_button(Right.btn);
if (Bottom.btn != null)
set_text_of_button(Bottom.btn);
if (Bottom_Left.btn != null)
set_text_of_button(Bottom_Left.btn);
if (Bottom_Right.btn != null)
set_text_of_button(Bottom_Right.btn);
}
}
can the following code be implemented or is there a better algorithm to perform the task...