Fix bombs on initial click

Fix bombs on initial click
This commit is contained in:
Tyler 2024-05-26 12:31:33 +01:00 committed by Tyler
parent d5fc28d743
commit d25cd93736
3 changed files with 23 additions and 18 deletions

7
.gitignore vendored
View File

@ -41,4 +41,9 @@ bin/
### Mac OS ###
.DS_Store
.idea
lib
lib
target
.mvn
src/main/resources/META-INF
mvnw
mvnw.cmd

16
.idea/gradle.xml generated
View File

@ -1,16 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="GradleMigrationSettings" migrationVersion="1" />
<component name="GradleSettings">
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />
</set>
</option>
</GradleProjectSettings>
</option>
</component>
</project>

View File

@ -28,6 +28,7 @@ public class Controller {
private long startTime;
private int bombCount = 99;
private boolean[][] expandedTiles;
private boolean isFirstClick = true;
@FXML
private void initialize() {
@ -81,10 +82,24 @@ public class Controller {
handlePrimaryClick(clicked, column, row);
}
private void setBombIfFirstTileIsBomb() {
for (int c = 0; c < 30; ++c) {
for (int r = 0; r < 16; ++r) {
if (!wrapper.atColumn(c).atRow(r).isBomb()) {
wrapper.setBomb();
System.out.println("erm");
return;
}
}
}
}
private void handlePrimaryClick(Button clicked, int column, int row) {
if (wrapper.atColumn(column).atRow(row).isBomb()) {
if (wrapper.atColumn(column).atRow(row).isBomb() && !isFirstClick) {
gameOver(clicked);
return;
} else if (wrapper.isBomb() && isFirstClick) {
setBombIfFirstTileIsBomb();
}
int adjacentBombs = wrapper.adjacentBombCount();
setAdjacentCount(clicked, adjacentBombs);
@ -145,6 +160,7 @@ public class Controller {
gridHandler = new Grid();
wrapper = gridHandler.grid;
expandedTiles = new boolean[30][16];
isFirstClick = true;
}
private void resetTimer() {