Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // Created by domin on 09.03.2019.
- //
- #include <iostream>
- #include "MinesweeperBoard.h"
- #include <time.h>
- #include <stdlib.h>
- using namespace std;
- MinesweeperBoard::MinesweeperBoard()
- {
- width = 10;
- height = 10;
- set_board();
- }
- void MinesweeperBoard::set_board()
- {
- for (int y = 0; y <height; y++)
- {
- for (int x = 0; x <width; x++)
- {
- board[x][y].hasFlag = 0;
- board[x][y].hasMine = 0;
- board[x][y].isRevealed = 0;
- }
- }
- }
- void MinesweeperBoard::gamemode(GameMode mode)
- {
- srand(time(NULL));
- if (mode == GameMode::EASY)
- {
- for (int x = 0; x < 10;)
- {
- int iks = (rand() % 10) + 0; // losowanie współrzędnych
- int igrek = (rand() % 10) + 0;
- if (board[iks][igrek].hasMine == 1)
- {
- continue;
- }
- else
- {
- board[iks][igrek].hasMine = 1;
- x++;
- }
- board[iks][igrek].hasMine = 1;
- }
- }
- if(mode == GameMode::NORMAL)
- {
- for (int x = 0; x < 20;)
- {
- int iks = (rand() % 10) + 0; // losowanie współrzędnych
- int igrek = (rand() % 10) + 0;
- if (board[iks][igrek].hasMine == 1)
- {
- continue;
- } else
- {
- board[iks][igrek].hasMine = 1;
- x++;
- }
- board[iks][igrek].hasMine = 1;
- }
- }
- if (mode == GameMode::HARD)
- {
- for (int x = 0; x < 30;)
- {
- int iks = (rand() % 10) + 0; // losowanie współrzędnych
- int igrek = (rand() % 10) + 0;
- if (board[iks][igrek].hasMine == 1)
- {
- continue;
- } else
- {
- board[iks][igrek].hasMine = 1;
- x++;
- }
- board[iks][igrek].hasMine = 1;
- }
- }
- }
- void MinesweeperBoard::debug_display()
- {
- for (int y = 0;y<height;y++)
- {
- for (int x = 0;x<width;x++)
- {
- cout << '[';
- if (board[x][y].hasMine == true)
- {
- cout << 'M';
- }
- else
- {
- cout << '.';
- }
- if (board[x][y].
- isRevealed == true
- )
- {
- cout << 'o';
- }
- else
- {
- cout << '.';
- }
- if (board[x][y].
- hasFlag == true
- )
- {
- cout << 'f';
- }
- else
- {
- cout << '.';
- }
- cout << ']';
- }
- cout <<endl;
- }
- }
- void MinesweeperBoard::countMines(int x, int y)
- {
- Minecount=0;
- if (board[x][y + 1].hasMine == true)
- Minecount++;
- if (board[x][y - 1].hasMine == true)
- Minecount++;
- if (board[x + 1][y].hasMine == true)
- Minecount++;
- if (board[x - 1][y].hasMine == true)
- Minecount++;
- if (board[x - 1][y - 1].hasMine == true)
- Minecount++;
- if (board[x + 1][y + 1].hasMine == true)
- Minecount++;
- if (board[x + 1][y - 1].hasMine == true)
- Minecount++;
- if (board[x - 1][y + 1].hasMine == true)
- Minecount++;
- cout << Minecount;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement