-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminesweeper.hpp
40 lines (30 loc) · 980 Bytes
/
minesweeper.hpp
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
#pragma once
#include <vector>
class Minesweeper{
private:
int numRows;
int numColumns;
int numMines;
struct location{
int rowIndex;
int columnIndex;
bool isMine;
bool isOpen;
bool isMarkedDoubt;
bool isMarkedBomb;
};
std::vector<location> locations;
public:
Minesweeper(int numRows, int numColumns, int numMines);
void displayBoard() const;
void displayAll() const;
void openLocation(location &loc);
void openLocation(const int x, const int y) { openLocation(locations[x*numRows + y]); }
void markAsDoubt(const int x, const int y);
void markAsBomb(const int x, const int y);
void unmarkLocation(const int x, const int y);
int countMinesAround(const location &loc) const;
bool onlyMinesLeft() const;
bool locationIsMine(int x, int y) const{ return locations[x*numRows + y].isMine; }
bool isValidLocation(int x, int y) const { return ((x < numRows) && (x >= 0) && (y < numColumns) && (y >= 0)) ? true : false; }
};