I know other instructors give this assignment so I'm not posting all my code. (Not to mention I tend to do things the long way and my code is pretty long.) If I need to post the rest of my code, let me know.
Thanks for taking the time to point me in the right direction.
// hiddenBoard is an int array used to determine where the bombs, empty tiles, and number tiles are
// gameBoard is what the player sees
// EMPTY is a final int set to 0 (zero bombs next to it)
// I'm trying to keep from going out of bounds and check all eight tiles (around the tile clicked)
// in the hiddenBoard and if they are 0 set the gameBoard to EMPTY
// I'm repainting gameBoard in another method
public int[][] isNeighborZero(int i, int j)
{
if((i-1 >= 0) && (j-1 >= 0) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i-1][j-1] == EMPTY))
{
gameBoard[i-1][j-1] = EMPTY;
isNeighborZero(i-1, j-1);
}
if((i-1 >= 0) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i-1][j] == EMPTY))
{
gameBoard[i-1][j] = EMPTY;
isNeighborZero(i-1, j);
}
if((i-1 >= 0) && (j+1 < NUMCOLS) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i-1][j+1] == EMPTY))
{
gameBoard[i-1][j+1] = EMPTY;
isNeighborZero(i-1, j+1);
}
if((j-1 >= 0) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i][j-1] == EMPTY))
{
gameBoard[i][j-1] = EMPTY;
isNeighborZero(i, j-1);
}
if((j+1 < NUMCOLS) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i][j+1] == EMPTY))
{
gameBoard[i][j+1] = EMPTY;
isNeighborZero(i, j+1);
}
if((i+1 < NUMROWS) && (j-1 >= 0) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i+1][j-1] == EMPTY))
{
gameBoard[i+1][j-1] = EMPTY;
isNeighborZero(i+1, j-1);
}
if((i+1 < NUMROWS) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i+1][j] == EMPTY))
{
gameBoard[i+1][j] = EMPTY;
isNeighborZero(i+1, j);
}
if((i+1 < NUMROWS) && (j+1 < NUMCOLS) && (hiddenBoard[i][j] == EMPTY) && (hiddenBoard[i+1][j+1] == EMPTY))
{
gameBoard[i+1][j+1] = EMPTY;
isNeighborZero(i+1, j+1);
}
return gameBoard;
}

New Topic/Question
Reply



MultiQuote




|