Skip to content
Advertisement

Recursion Showing Adjacent Blank Mines in Minesweeper

I am fairly new to Java and I have been working on a Minesweeper game. I am trying to get the adjacent cells to be revealed recursively when an empty cell is clicked. I do this by calling showCell() shown below:

Cells array declaration and population:

JavaScript

toggleFlag()

JavaScript

showCell()

JavaScript

The problem I am having is when I hit this portion of the code and click an empty cell, it reveals all cells adjacent continuously down a column or a row in one direction. I can’t get my implementation of recursion right, perhaps I am approaching it wrong. My idea was to reveal each adjacent cell according to the grid position.

Advertisement

Answer

I solved my problem by implementing Tail Recursion. Here is my updated showCell() method and tail recursion method:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement