fix bomb graphic on first click bomb being moved in setBombIfFirstTileIsBomb

This commit is contained in:
Tyler 2024-05-26 13:32:48 +01:00
parent 7323fa8fb8
commit ffaa310dbe
2 changed files with 9 additions and 3 deletions

View File

@ -36,7 +36,6 @@ public class Controller {
gridHandler = new Grid();
wrapper = gridHandler.grid;
expandedTiles = new boolean[30][16];
}
private void setupGrid() {
@ -82,11 +81,12 @@ public class Controller {
handlePrimaryClick(clicked, column, row);
}
private void setBombIfFirstTileIsBomb() {
private void setBombIfFirstTileIsBomb(int column, int row) {
for (int c = 0; c < 30; ++c) {
for (int r = 0; r < 16; ++r) {
if (!wrapper.atColumn(c).atRow(r).isBomb()) {
wrapper.setBomb();
wrapper.updateGrid(column, row, c, r);
System.out.println("erm");
return;
}
@ -99,7 +99,8 @@ public class Controller {
gameOver(clicked);
return;
} else if (wrapper.isBomb() && isFirstClick) {
setBombIfFirstTileIsBomb();
isFirstClick = false;
setBombIfFirstTileIsBomb(column, row);
}
int adjacentBombs = wrapper.adjacentBombCount();
setAdjacentCount(clicked, adjacentBombs);

View File

@ -62,6 +62,11 @@ public class GridWrapper {
return count;
}
public void updateGrid(int oldColumn, int oldRow, int newColumn, int newRow) {
grid[oldColumn][oldRow] = false;
grid[newColumn][newRow] = true;
}
private boolean isBombAt(int column, int row) {
return isValid(column, row) && grid[column][row];
}