-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBoard.h
46 lines (40 loc) · 1.05 KB
/
Board.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
#ifndef BOARD_H
#define BOARD_H
#include <QObject>
#include <QVector>
// Internal representation of the Minesweeper board
class Board : public QObject
{
Q_OBJECT
public:
explicit Board(QObject *parent = nullptr);
void initialize(int rows, int cols, int numMines);
bool hasMine(int row, int col);
int mineCount(int row, int col);
void toggleFlag(int row, int col);
void clearCell(int row, int col);
bool isFlagged(int row, int col);
bool isCleared(int row, int col);
bool mineTriggered();
bool allCellsCleared();
int numSurroundingFlags(int row, int col);
private:
bool isValidCell(int row, int col);
void setMines(int numMines);
void setMine(int row, int col);
void calcMineCounts();
int numSurroundingMines(int row, int col);
private:
struct CellStruct {
bool flagged;
bool cleared;
bool hasMine;
int numNeighboringMines;
};
QVector<CellStruct> m_cells;
int m_rows;
int m_cols;
int m_numLeftToClear;
bool m_mineTriggered;
};
#endif // BOARD_H