Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <string>
- #include <vector>
- class Minesweeper {
- size_t width_ = 0;
- size_t height_ = 0;
- size_t open_cells_count_ = 0;
- size_t mines_count_ = 0;
- time_t start_ = 0;
- time_t finish_ = 0;
- std::vector<int> delta_ = {-1, 0, 1};
- struct Cell {
- size_t x = 0;
- size_t y = 0;
- bool have_mine = false;
- size_t neighbors_mines_count_ = 0;
- std::vector<Cell*> neighbors;
- enum class Status {
- OPEN,
- MARK,
- NOT_OPEN,
- } status;
- bool IsOpen() const;
- bool IsNotOpen() const;
- bool IsMark() const;
- };
- std::vector<std::vector<Cell>> field_;
- void Initialize(size_t width, size_t height);
- void PrecalcCountOfNeighborsMines();
- void StartGame();
- void Victory();
- void GameOver();
- void Open(Cell& cell);
- void Mark(Cell& cell) const;
- bool OutOfRange(size_t x, int dx, size_t width) const;
- public:
- enum class GameStatus {
- NOT_STARTED,
- IN_PROGRESS,
- VICTORY,
- DEFEAT,
- } game_status_;
- using RenderedField = std::vector<std::string>;
- Minesweeper(size_t width, size_t height, size_t mines_count);
- Minesweeper(size_t width, size_t height, const std::vector<Cell>& cells_with_mines);
- void NewGame(size_t width, size_t height, size_t mines_count);
- void NewGame(size_t width, size_t height, const std::vector<Cell>& cells_with_mines);
- void OpenCell(const Cell& cell);
- void MarkCell(const Cell& cell);
- GameStatus GetGameStatus() const;
- time_t GetGameTime() const;
- RenderedField RenderField() const;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement