-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tile.cpp
45 lines (40 loc) · 1.19 KB
/
Tile.cpp
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
#include "Tile.h"
// For å sette labelfarge i henhold til hvor mange miner som er rundt
const map<int, Color> minesToColor{ {1, Color::blue},
{2, Color::red},
{3,Color::dark_green},
{4, Color::dark_magenta},
{5, Color::dark_blue},
{6, Color::dark_cyan},
{7, Color::dark_red},
{8, Color::dark_yellow} };
// For å sette Tilelabel i henhold til state
const map<Cell, string> cellToSymbol{ {Cell::closed, ""},
{Cell::open, ""},
{Cell::flagged, "@<"} };
void Tile::open()
{
if(state == Cell::flagged){
return;
}
static_cast<Fl_Button*>(pw)->set();//Setter en button som trykket p�, tilsvarer �pnet rute
state = Cell::open;
if(isMine){
set_label("X");
set_label_color(minesToColor.at(2));
redraw();
}
}
void Tile::flag(){
if(state == Cell::flagged){
state = Cell::closed;
set_label(cellToSymbol.at(state));
return;
}
state = Cell::flagged;
set_label(cellToSymbol.at(state));
}
void Tile::setAdjMines(int n){
set_label(to_string(n));
set_label_color(minesToColor.at(n));
}