-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMap.cpp
63 lines (53 loc) · 1.13 KB
/
Map.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
//
// Created by vojta on 1/12/20.
//
#include "Map.h"
Map::Map() = default;
bool Map::HasBlock(int x, int y) {
return mapData[x][y].hasBlock;
}
void Map::ClearMap() {
for (auto &x : mapData) {
for (auto &y : x) {
y.hasBlock = false;
}
}
}
bool Map::CheckLost() {
for (auto &i : mapData) {
if (i[0].hasBlock) {
ClearMap();
return true;
}
}
return false;
}
void Map::AddBlock(Shape *shape) {
for (auto &point : shape->GetBlocks()) {
mapData[shape->position.x + point.x][shape->position.y + point.y].set(shape->color);
}
}
int Map::CheckRows() {
int fullRowsDeleted= 0;
for (int y = 19; y >= 0; y--) {
if (CheckRow(y)) {
EraseRow(y);
fullRowsDeleted++;
y = 19; // reset search
}
}
return fullRowsDeleted;
}
bool Map::CheckRow(int y) {
for (auto &x : mapData) {
if (!x[y].hasBlock) return false;
}
return true;
}
void Map::EraseRow(int y) {
for (int i = y; i > 0; i--) {
for (auto &x : mapData) {
x[i] = x[i - 1];
}
}
}