src/MapGenerator/randomMine.cpp
/**
 * Use random library to generate some mines.
 * Write a totally initialize map to Controller::minefield
 *
 * @param emptyField
 * A pointer of MField which just initialize map size.
 * */
Use random library to generate some mines.
Write a totally initialize map to Controller::minefield

@param emptyField
A pointer of MField which just initialize map size.
Use random library to generate some mines . Write a totally initialize map to Controller :: minefield @param emptyField A pointer of MField which just initialize map size .
void MapGenerator::generateMine(MinefieldPtr emptyField) {
    std::default_random_engine generator(static_cast<uint_fast32_t>(time(nullptr)));
    std::uniform_int_distribution<uint16_t> forRow(0, emptyField->GetRow() - 1);
    std::uniform_int_distribution<uint16_t> forLine(0, emptyField->GetLine() - 1);
    uint16_t mines = emptyField->GetMines();
    uint16_t generated = 0;
    MapGenerator::MField::Map *map = emptyField->GetMap();
    while (generated < mines) {
        uint16_t row = forRow(generator);
        uint16_t line = forLine(generator);
        if ((*map)[row][line] != 0)
            continue;
        (*map)[row][line] = 99;
        generated++;
    }
    for (int i = 0; i < emptyField->GetRow(); ++i) {
        for (int j = 0; j < emptyField->GetLine(); ++j) {
            if ((*map)[i][j] != 99)
                (*map)[i][j] = typeAround(i, j, emptyField, BLOCKTYPE::MINE);
        }
    }
}
void MapGenerator :: generateMine ( MinefieldPtr emptyField ) { std :: default_random_engine generator ( static_cast < uint_fast32_t > ( time ( nullptr ) ) ) ; std :: uniform_int_distribution < uint16_t > forRow ( 0 , emptyField -> GetRow ( ) - 1 ) ; std :: uniform_int_distribution < uint16_t > forLine ( 0 , emptyField -> GetLine ( ) - 1 ) ; uint16_t mines = emptyField -> GetMines ( ) ; uint16_t generated = 0 ; MapGenerator :: MField :: Map * map = emptyField -> GetMap ( ) ; while ( generated < mines ) { uint16_t row = forRow ( generator ) ; uint16_t line = forLine ( generator ) ; if ( ( * map ) [ row ] [ line ] != 0 ) continue ; ( * map ) [ row ] [ line ] = 99 ; generated ++ ; } for ( int i = 0 ; i < emptyField -> GetRow ( ) ; ++ i ) { for ( int j = 0 ; j < emptyField -> GetLine ( ) ; ++ j ) { if ( ( * map ) [ i ] [ j ] != 99 ) ( * map ) [ i ] [ j ] = typeAround ( i , j , emptyField , BLOCKTYPE :: MINE ) ; } } }
Use random library to generate some mines.
Use random library to generate some mines .