Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public void click(int row, int column) { Stack stack2 = new Stack(); if (board[r

ID: 3531638 • Letter: P

Question

public void click(int row, int column) {
Stack stack2 = new Stack();

if (board[row][column].isVisible) {
return;
}

else if (board[row][column].isMine) {
board[row][column].isVisible = true;
lost();
return;
} else if (board[row][column].mineNeighbors >= 1) {
board[row][column].isVisible = true;
}


else {

stack2.push(board[row][column]);
while (!stack2.isEmpty()) {
GameSquare gameSquare2 = (GameSquare) stack2.pop();

if (gameSquare2.mineNeighbors == 0) {
for (int i = gameSquare2.row - 1; i < gameSquare2.row + 2; i++) {
for (int j = gameSquare2.col - 1; j < gameSquare2.col + 2; j++) {
if (i == gameSquare2.row && j == gameSquare2.col) {

}
else if (i >= 0 && j >= 0 && i < board.length
&& j < board[i].length
&& (board[i][j].isVisible == true
|| board[i][j].isFlagged == true))

{

} else if (i >= 0 && j >= 0 && i < board.length
&& j < board[i].length) {
stack2.push(board[i][j]);
board[i][j].isVisible = true;
}

}

}

}// IF and ELSE ~END~

}// END WHILE STACK!NOT EMPTY
}// END LAST ELSE
} // END CLICK

Explanation / Answer

public void showSafeTile(int row,int column){

if(board[row][column].mineNeighbors ==0){

for(int i=row-1;i<row+2;i++){

for(int j=column-1;j<column+2;j++){

if(i==row&&j==column){

}else if(i>=0&&j>=0&&i<board.length&&j<board[i].length&&(board[i][j].isVisible == true|| board[i][j].isFlagged == true)){

}else if(i >= 0 && j >= 0 && i < board.length&& j < board[i].length){

board[i][j].isVisible = true;

showSafeTile(row,column);

}

}

}

}

}

public void click(int row, int column) {

if (board[row][column].isVisible) {

return;

}

else if (board[row][column].isMine) {

board[row][column].isVisible = true;

lost();

return;

} else if (board[row][column].mineNeighbors >= 1) {

board[row][column].isVisible = true;

return;

}else {

showSafeTile(row,column);

}

}