forked from hBuzzy/TetrisTask
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfigure.cpp
More file actions
62 lines (54 loc) · 1.83 KB
/
Copy pathfigure.cpp
File metadata and controls
62 lines (54 loc) · 1.83 KB
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
#include "figure.h"
#include <time.h>
Figure::Figure() {}
void Figure::generateFigure() {
QVector<QVector<QVector<int>>> figures;
figures.append( { {0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0} } );
figures.append( { {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 0, 1, 0} } );
figures.append( { {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 1, 0}, {0, 0, 0, 0} } );
figures.append( { {0, 1, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0} } );
figures.append( { {0, 0, 1, 0}, {0, 0, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0} } );
figures.append( { {0, 1, 1, 0}, {0, 1, 1, 0}, {0, 0, 0, 0}, {0, 0, 0, 0} } );
srand(time(NULL));
int index = rand() % figures.size();
figure_ = figures[index];
}
int Figure::getXPoints() const {
return figure_.size();
}
int Figure::getYPoints() const {
return figure_[0].size();
}
int Figure::getFigureAt(QPoint point) const {
if (point.y() >= 0 && point.y() < getYPoints() && point.x() >= 0 && point.x() < getXPoints())
return figure_[point.y()][point.x()];
return 0;
}
QVector<QVector<int>> Figure::getFigure() {
return figure_;
}
void Figure::rotate() {
int xPoints = getXPoints();
int yPoints = getYPoints();
QVector<QVector<int>> rotated(xPoints, QVector<int> (yPoints));
for (int i = 0; i < yPoints; i++) {
for (int j = 0; j < xPoints; j++) {
rotated[j][yPoints - 1 - i] = figure_[i][j];
}
}
figure_ = rotated;
}
void Figure::generateColor() {
QVector<QColor> colors;
colors.append( QColor(255, 135, 50));
colors.append( QColor(168, 50, 168));
colors.append( QColor(0, 255, 0));
colors.append( QColor(0, 255, 255));
colors.append( QColor(127, 0, 255));
srand(time(NULL));
int index = rand() % colors.size();
color_ = colors[index];
}
QColor Figure::getColor() {
return color_;
}