-
Notifications
You must be signed in to change notification settings - Fork 0
/
minesfield.h
77 lines (59 loc) · 1.73 KB
/
minesfield.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef MINESFIELD_H
#define MINESFIELD_H
#include "cell.h"
#include "point.h"
#include <QObject>
#include <atomic>
#include <thread>
#include <vector>
class MinesField : public QObject {
Q_OBJECT
public:
MinesField(unsigned rows, unsigned cols, unsigned char minesPercents);
virtual ~MinesField();
void lazyOpenCells(const Point& point);
void tryToOpenCell(const Point& point);
void markCell(const Point& point, Cell::CellState markAs = Cell::CellState::MarkedAsBomb);
void unmarkCell(const Point& point);
unsigned getMinesCount() const;
unsigned getRows() const;
unsigned getCols() const;
double getMinesPercents() const;
std::vector<Cell>& getCells();
unsigned getCellIndex(const Point& cell) const;
Point getCellPoint(unsigned index) const;
Cell* getCell(const Point& cell);
Cell* getCell(unsigned index);
bool isCellIndexValid(long index) const
{
return index >= 0 && index < long(cells.size());
}
bool isCellPointValid(const Point& point) const
{
return point.x() >= 0 && point.x() < long(cols)
&& point.y() >= 0 && point.y() < long(rows);
}
inline std::vector<Point> getAroundCells(const Point& cell) const;
bool getCreated() const;
unsigned getMarkedCells() const;
signals:
void userLost();
void userWon();
void markedCellsCountChanged();
public slots:
private:
std::vector<Cell> cells;
unsigned minesCount = 0;
int minesLeft = 0;
unsigned markedCells = 0;
unsigned rows;
unsigned cols;
double minesPercents = 0;
bool lost = false;
bool won = false;
void loseGame();
bool isUserWon();
void checkForWin();
std::atomic<bool> created;
};
#endif // MINESFIELD_H