-
Notifications
You must be signed in to change notification settings - Fork 0
/
ZBlock.cpp
124 lines (105 loc) · 2.32 KB
/
ZBlock.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#include <iostream>
#include <string>
#include "ZBlock.h"
#include <vector>
using namespace std;
ZBlock::ZBlock(int deLevel) : deLevel{deLevel}, count{4} {}
ZBlock::~ZBlock() {
coordFill.clear();
coords.clear();
coordsCpy.clear();
}
void ZBlock::left() {
int len = coordsCpy.size();
for(int i = 0; i < len; ++i) {
--coordsCpy[i][0];
}
}
void ZBlock::right() {
int len = coordsCpy.size();
for(int i = 0; i < len; ++i) {
++coordsCpy[i][0];
}
}
void ZBlock::down() {
int len = coordsCpy.size();
for(int i = 0; i < len; ++i) {
--coordsCpy[i][1];
}
}
int ZBlock::getLevel() {
return deLevel;
}
bool ZBlock::modifyCount() {
count--;
if (count != 0) {
return false;
} else {
return true;
}
}
void ZBlock::clockwise() {
// find the bottom left
int minX = 10;
int minY = 0;
// find the top right
int maxX = 0;
int maxY = -17;
int len = coordsCpy.size();
for (int i = 0; i < len; ++i) {
int curX = coordsCpy[i][0];
int curY = coordsCpy[i][1];
if (curX <= minX && curY <= minY) {
minX = curX;
minY = curY;
}
if (curX >= maxX && curY >= maxY) {
maxX = curX;
maxY = curY;
}
}
// rotate
for (int i = 0; i < len; ++i) {
int curX = coordsCpy[i][0];
int curY = coordsCpy[i][1];
int newX = minX + minY - curY;
int newY = curX + minY - minX;
coordsCpy[i][0] = newX;
coordsCpy[i][1] = newY;
}
// move right by (maxY - minY) cells
for (int i = 0; i < (maxY - minY); ++i) {
right();
}
}
void ZBlock::changeContent(bool check) {
int len = coords.size();
if (check == false) {
// copy coords into coordsCpy
for (int i = 0; i < len; ++i) {
int tempX = coords[i][0];
int tempY = coords[i][1];
coordsCpy[i][0] = tempX;
coordsCpy[i][1] = tempY;
}
} else {
// copy coordsCpy into coords
for (int i = 0; i < len; ++i) {
int tempX = coordsCpy[i][0];
int tempY = coordsCpy[i][1];
coords[i][0] = tempX;
coords[i][1] = tempY;
}
}
}
void ZBlock::counterClockwise() {
for (int i = 0; i < 3; ++i) {
clockwise();
}
}
string ZBlock::getType() {
return "Z";
}
vector<bool>& ZBlock::getCoordFill() { return coordFill; }
vector<vector<int>>& ZBlock::getCoords() { return coords; }
vector<vector<int>>& ZBlock::getCoordsCpy() { return coordsCpy; }