private void flaggedMinesCheck() throws IllegalStateException {
        if (flaggedMines < 0)
            throw new IllegalStateException("The number of flagged mines is below 0.");
        if (flaggedMines > mineCount)
            throw new IllegalStateException("The number of flagged mines is above the maximum, "+mineCount+".");
        
        // If the player has flagged all of the mines, check to see if they have over-flagged.
        if (flaggedMines == mineCount) {
            int flaggedSquares = 0;
            for (int y = 0; y < gridSize; y++) {
                for (int x = 0; x < gridSize; x++) {
                    if (squares[x][y].isFlagged()) { flaggedSquares++; }
                }
            }
            // The player has found all of the mines and won the game.
            if (flaggedSquares == mineCount) {
                hasEnded = true;
                hasSucceeded = true;

                // Reveal any remaining squares.
                for (int y = 0; y < gridSize; y++) {
                    for (int x = 0; x < gridSize; x++) {
                        squares[x][y].revealNotMine();
                    }
                }
            }
        }
    }