Esempio n. 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;
}
Esempio n. 2
0
/**************************************************************
*	Purpose: This function prints a specified row of the board on 
*            the screen, giving each cell's state a symbol.
*
*  	   Entry:  An instance of the Minesweeper class and a row to show.
*
*  	    Exit:  None.
****************************************************************/
void showrow(Minesweeper &game, int row)
{
    for (int col = 0; col < game.getCol(); ++col)
    {
        if (col == 0) cout << ' ';
        if (game.getCovered(row, col))
        {
            cout << "? ";
        }
        else if (game.getMarked(row, col))
        {
            cout << "M ";
        }
        else if (game.getMine(row, col))
        {
            cout << char(178) << ' ';
        }
        else if (game.getSurround(row, col) > 0)
        {
            cout << game.getSurround(row, col) << ' ';
        }
        else
        {
            cout << "O ";
        }
    }
}
Esempio n. 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;
}