@@ -388,43 +388,16 @@ public boolean checkAdjacentSquares(int row, int column, Square[][] grid) {
388
388
* @return true if game is over, false if not
389
389
*/
390
390
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 ;
401
391
// 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 ;
415
397
}
416
398
}
417
399
}
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 ;
429
402
}
430
403
}
0 commit comments