Nico è... 0 Newbie Poster

Instructions:
Add a close_calls(int row, int col) method.
1. If the space contains an 'X', modify a private variable to indicate this and return from the method.
2. If the space does not contain an 'X', add up how many X's are next to the current space.
3. Add a recursive method to clear an area.
4. Put the number of close calls in the current space. If the number equals zero, uncover adjacent spaces by making a recursive call for every one of them.

I can't wrap my head around how to write the recursive function which checks neighboring cells of the chosen array. The array is 10 by 10. I have gotten it to look in one direction at a time, placing a 1 next to the bomb location, however we are supposed to mark off sections, not rows. so my recursion needs to check all 8 sides of the chosen array. I am having a hard time implementing this.

Here's what i have so far:

int MineSweeper::close_calls (int row, int col)
{	
	if(col > 9)			// check if off board
		return array[row][col];	
	
	if(array[row][col] == 'X')			// looks to right
	{
		array[row][col-1] = 1 + '0';
		return array[row][col];
	}
	else
	{
		revealed[row][col] = true;
		array[row][col] ='0';
		return close_calls(row, col+1);  // recursive part
	}	
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.