-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell.cpp
More file actions
55 lines (42 loc) · 885 Bytes
/
cell.cpp
File metadata and controls
55 lines (42 loc) · 885 Bytes
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
#include "cell.h"
cell_t::cell_t() {
sprite = new sf::Sprite();
}
cell_t::~cell_t() {
delete sprite;
}
void cell_t::place_mine() {
is_mine = true;
}
bool cell_t::reveal() {
if (is_flagged) return false;
is_revealed = true;
return is_mine;
}
void cell_t::toggle_flag() {
is_flagged = !is_flagged;
}
void cell_t::unflag() {
is_flagged = false;
}
void cell_t::increment_adjacent_mines() {
++adjacent_mines;
}
bool cell_t::auto_reveal() {
return !is_mine;
}
bool cell_t::auto_reveal_neighbors() {
return !is_mine && adjacent_mines == 0;
}
char cell_t::get_display_value() {
if (is_flagged) return 'f';
if (!is_revealed) return 'n';
if (is_mine) return 'b';
return (char) (adjacent_mines + '0');
}
void cell_t::reset() {
adjacent_mines = 0;
is_flagged = false;
is_revealed = false;
is_mine = false;
}