-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cell.h
76 lines (59 loc) · 1.43 KB
/
Cell.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
#ifndef _CELL_H
#define _CELL_H
#include <string>
/*!
* \class Cell
* \brief Represents a single MineField element
*/
class Cell
{
public:
enum
{
// for value
MINE = -1
};
enum
{
// for state
FLAGGED = 1,
UNKNOWN = 2,
KNOWN = 3
};
Cell(int value = 0, int state = UNKNOWN);
bool operator==(const Cell& c) const;
bool operator!=(const Cell& c) const;
bool isValidState(int state) const;
bool isValidValue(int value) const;
int getValue() const;
void setValue(int new_value);
int getState() const;
void setState(int new_state);
// returns true if cell state is known and
// and has at least one mine next to it
bool isNextToBombs() const;
// format cell state/value as a textal string
std::string toString() const;
// parse Cell state/value from textual string
bool fromString(const std::string& str);
private:
int _value; // value of the cell, can be 0-8, or -1=mine
int _state; // state value, can be FLAGGED, KNOWN or UNKNOWN
};
//--- inline method declarations ----------------------------------------------
inline int Cell::getValue() const
{
return _value;
}
inline int Cell::getState() const
{
return _state;
}
inline bool Cell::isNextToBombs() const
{
if (_state == KNOWN && _value > 0)
return true;
else
return false;
}
#endif // _CELL_H