Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void MinesweeperBoard::revealField(int x, int y) {
- if(isOutside(x, y) || (this->state==FINISHED_LOSS) || (this->state==FINISHED_WIN) || isRevealed(x, y) || hasFlag(x, y))
- return;
- if( (moveCount != 0 && this->mode != DEBUG) || this->mode == DEBUG ) {
- if (this->board.at(x).at(y).hasMine == true) {
- this->board.at(x).at(y).isRevealed = true;
- this->moveCount++;
- this->state = FINISHED_LOSS;
- return;
- }
- }
- srand( time(nullptr) );
- int newMinePositionX=rand()%(this->width);
- int newMinePositionY=rand()%(this->height);
- if(moveCount == 0) {
- // Changing position of first revealed mine
- while(this->board.at(newMinePositionX).at(newMinePositionY).hasMine==true) {
- newMinePositionX = rand() % (this->width);
- newMinePositionY = rand() % (this->height);
- }
- this->board.at(x).at(y).hasMine = false;
- this->board.at(newMinePositionX).at(newMinePositionY).hasMine = true;
- }
- floodReveal(x, y);
- this->moveCount++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement