-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcell.cpp
More file actions
45 lines (36 loc) · 860 Bytes
/
cell.cpp
File metadata and controls
45 lines (36 loc) · 860 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
#include "cell.h"
#include "figures.h"
#include "constants.h"
using namespace Graph_lib;
Cell::Cell(Point xy, Callback cb, Type t, int number, int symbol)
: Button{xy, size, size, "", cb}, type{t}, number{number}, symbol{symbol} {
/* All done */
}
void Cell::attach(Graph_lib::Window &win) {
Button::attach(win);
reset_color();
}
void Cell::reset_color() {
if (!pw)
error("Cell is not attached to a window");
if (is_black())
pw->color(chess_green);
else
pw->color(chess_white);
}
void Cell::attach_figure(Figure &f) {
f.attach(*this);
figure = &f;
}
Figure &Cell::detach_figure() {
Figure *f = figure;
figure = nullptr;
f->detach();
return *f;
}
void Cell::eat_figure() {
if (figure) {
figure = nullptr;
}
}
Figure &Cell::get_figure() { return *figure; }