So, im at the point of counting the number of nearby mines ASSUMING if the spot chosen had no mines and this is what I came up with:
public static int numNearbyMines( boolean [][]mines, int row, int col) {
int nearbyMines = 0;
if (mines[row - 1][col] == true) { nearbyMines += 1; }
if (mines[row - 1][col - 1] == true) { nearbyMines += 1; }
if (mines[row - 1][col + 1] == true) { nearbyMines += 1; }
if (mines[row][col + 1] == true) { nearbyMines += 1; }
if (mines[row][col - 1] == true) { nearbyMines += 1; }
if (mines[row + 1][col] == true) { nearbyMines += 1; }
if (mines[row + 1][col - 1] == true) { nearbyMines += 1; }
if (mines[row + 1][col + 1] == true) { nearbyMines += 1; }
return nearbyMines;
}
However, I realized that this method would not work because if I chose a place such as a corner, it would be "reading" outside of the array, hence not working. How would I change this so that even if I picked a corner, it would only read inside the array?