Skip to content

Commit c267d63

Browse files
committed
Update Game.java
1 parent 436772f commit c267d63

File tree

1 file changed

+7
-34
lines changed
  • minesweeper/src/gr/hmu/tp4768/Models

1 file changed

+7
-34
lines changed

minesweeper/src/gr/hmu/tp4768/Models/Game.java

Lines changed: 7 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -388,43 +388,16 @@ public boolean checkAdjacentSquares(int row, int column, Square[][] grid) {
388388
* @return true if game is over, false if not
389389
*/
390390
public boolean checkGameOver(Square[][] grid) {
391-
// set max number of rows
392-
int maxRows = grid.length;
393-
// set max number of columns
394-
int maxColumns = grid[0].length;
395-
// set number of mines
396-
int mines = 0;
397-
// set number of revealed squares
398-
int revealedSquares = 0;
399-
// set number of flagged squares
400-
int flaggedSquares = 0;
401391
// loop through the grid
402-
for (int i = 0; i < maxRows; i++) {
403-
for (int j = 0; j < maxColumns; j++) {
404-
// check if the square is a mine
405-
if (grid[i][j].isMine()) {
406-
mines++;
407-
}
408-
// check if the square is revealed
409-
if (grid[i][j].isRevealed()) {
410-
revealedSquares++;
411-
}
412-
// check if the square is flagged
413-
if (grid[i][j].isFlagged()) {
414-
flaggedSquares++;
392+
for (int i = 0; i < grid.length; i++) {
393+
for (int j = 0; j < grid[0].length; j++) {
394+
// check if the square is not revealed or flagged
395+
if (!grid[i][j].isRevealed() && !grid[i][j].isFlagged()) {
396+
return false;
415397
}
416398
}
417399
}
418-
// check if the number of mines equals the number of flagged squares
419-
if (mines == flaggedSquares) {
420-
// check if the number of revealed squares equals the number of squares
421-
// minus the number of mines
422-
if (revealedSquares == (maxRows * maxColumns) - mines) {
423-
this.isGameOver = true;
424-
return true;
425-
}
426-
}
427-
this.isGameOver = false;
428-
return false;
400+
this.isGameOver = true;
401+
return true;
429402
}
430403
}

0 commit comments

Comments
 (0)