Beispiel #1
0
/**************************************************************
*	Purpose: This function checks for the two ways to win the gaem.
*           The first is if all mines have been marked, and the 
*           second is if all non-mine spaces have been uncovered.
*
*  	   Entry:  An instance of the Minsweeper class.
*
*  	    Exit:  A bool signifying whether the game was won.
****************************************************************/
bool check_for_win(Minesweeper &game)
{
    bool win = false;
    int num_marked_mines = 0;
    int num_uncovered_not_mines = 0;
    int num_not_mines = (game.getRow() * game.getCol()) - game.getNumMines();//This is all the spaces that aren't mines
    for (int row = 0; row < game.getRow(); ++row)
    {
        for (int col = 0; col < game.getCol(); ++col)
        {
            if (game.getMarked(row, col) && game.getMine(row, col))
            {
                ++num_marked_mines;
            }
            if (!game.getCovered(row, col) && !game.getMine(row, col))
            {
                ++num_uncovered_not_mines;
            }
        }
    }
    if (num_marked_mines == game.getNumMines() || num_uncovered_not_mines == num_not_mines)
    {
        win = true;
    }
    return win;
}
Beispiel #2
0
/**************************************************************
*	Purpose: This function shows the game board by looping 
*            through the rows and calling another function.
*
*  	   Entry:  An instance of the Minesweeper class.
*
*  	    Exit:  None.
****************************************************************/
void showboard(Minesweeper &game)
{
    cout << endl;
    for (int row = 0; row < game.getRow(); ++row)
    {
        showrow(game, row);
        cout << endl;
    }
    cout << endl;
}
Beispiel #3
0
/**************************************************************
*	Purpose: This functions checks for the losing condition (if
*            a space with a mine has been uncovered).
*
*  	   Entry:  An instance of the Minsweeper class.
*
*  	    Exit:  A bool signifying whether the game was lost.
****************************************************************/
bool check_for_explosion(Minesweeper &game)
{
    bool explosion = false;
    for (int row = 0; row < game.getRow(); ++row)
    {
        for (int col = 0; col < game.getCol(); ++col)
        {
            if (!game.getCovered(row, col) && game.getMine(row, col))
            {
                explosion = true;
            }
        }
    }
    return explosion;
}