Advertisement
Guest User

Untitled

a guest
Mar 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. void MinesweeperBoard::revealField(int x, int y) {
  2. if(isOutside(x, y) || (this->state==FINISHED_LOSS) || (this->state==FINISHED_WIN) || isRevealed(x, y) || hasFlag(x, y))
  3. return;
  4.  
  5. if( (moveCount != 0 && this->mode != DEBUG) || this->mode == DEBUG ) {
  6. if (this->board.at(x).at(y).hasMine == true) {
  7. this->board.at(x).at(y).isRevealed = true;
  8. this->moveCount++;
  9. this->state = FINISHED_LOSS;
  10. return;
  11. }
  12. }
  13.  
  14. srand( time(nullptr) );
  15. int newMinePositionX=rand()%(this->width);
  16. int newMinePositionY=rand()%(this->height);
  17. if(moveCount == 0) {
  18. // Changing position of first revealed mine
  19. while(this->board.at(newMinePositionX).at(newMinePositionY).hasMine==true) {
  20. newMinePositionX = rand() % (this->width);
  21. newMinePositionY = rand() % (this->height);
  22. }
  23. this->board.at(x).at(y).hasMine = false;
  24. this->board.at(newMinePositionX).at(newMinePositionY).hasMine = true;
  25. }
  26. floodReveal(x, y);
  27. this->moveCount++;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement