I'm writing code for a minesweeper project for class and one method is numAdjMines, which counts the mines around a cell in the array, each type of cell has a different value, like mines are -2, while mines with a flag on them are -4. I want to just write one if statement, but I end up having to just write the same code twice, with different values at the end.
if (row >= 1 && col >= 1 && boardArray[row - 1][col - 1] == MINE)
{
adjMines = adjMines + 1;
}
if (row >= 1 && col >= 1 &&
boardArray[row - 1][col - 1] == FLAGGED_MINE)
{
adjMines = adjMines + 1;
}
I tried using || for or and writing || boardArray[row-1][col-1] == FLAGGED_MINE at the end of the first one, but that then ignored the beginning with checking the row and column. Is there a short compact way for me to write this code?
So you don't have to write 8 seperate cases. Not a very big deal here, but if you have a 3D mine...