-
Notifications
You must be signed in to change notification settings - Fork 0
/
cell.cpp
90 lines (80 loc) · 2.06 KB
/
cell.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
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
77
78
79
80
81
82
83
84
85
86
87
88
89
#include "cell.h"
#include <utility>
using namespace std;
Cell::Cell(int xcor, int ycor, shared_ptr<Xwindow> w, bool showWindow, bool player) :
storedBlock{nullptr}, x{xcor+1}, y{ycor+5}, w{w}, star(false),
blind{false}, width{20}, height{20}, showWindow{showWindow}, player{player} {}
bool Cell::filled() {
if (storedBlock == nullptr && star == false) {
return false;
} else {
return true;
}
}
void Cell::clear() {
shared_ptr<Block> temp = nullptr;
swap(temp, storedBlock);
star = false;
blind = false;
undraw();
}
void Cell::update(shared_ptr<Cell> other) {
swap(storedBlock, other->storedBlock);
swap(blind, other->blind);
swap(star, other->star);
draw();
other -> draw();
}
void Cell::draw() {
if (showWindow) {
int xcor = x * width;
int ycor = y * height;
if (!player) xcor += 13 * width;
int col;
if (blind) col = Xwindow::Black;
else if (star) col = Xwindow::Brown;
else if (storedBlock == nullptr) col = Xwindow::White;
else {
string bType = storedBlock -> getType();
if (bType == "I") {
col = Xwindow::Red;
} else if (bType == "J") {
col = Xwindow::Orange;
} else if (bType == "L") {
col = Xwindow::Yellow;
} else if (bType == "T") {
col = Xwindow::Purple;
} else if (bType == "S") {
col = Xwindow::Green;
} else if (bType == "Z") {
col = Xwindow::Pink;
} else { //O
col = Xwindow::Blue;
}
}
w -> fillRectangle(xcor, ycor, width, height, col);
} else return;
}
void Cell::undraw() {
if (showWindow) {
int xcor = x * width;
int ycor = y * height;
if (!player) xcor += 13 * width;
w->fillRectangle(xcor, ycor, width, height, Xwindow::White);
} else return;
}
void Cell::setBlind() {
blind = true;
if (showWindow) {
int xcor = x * width;
int ycor = y * height;
if (!player) xcor += 13 * width;
w->fillRectangle(xcor, ycor, width, height, Xwindow::Black);
}
}
void Cell::unsetBlind() {
if (blind) {
blind = false;
if (showWindow) draw();
} else return;
}