This repository was archived by the owner on Sep 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtetrixcube.cpp
More file actions
93 lines (82 loc) · 2.07 KB
/
tetrixcube.cpp
File metadata and controls
93 lines (82 loc) · 2.07 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
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
#include <QtCore>
#include <QDebug>
#include "tetrixcube.h"
void TetrixCube::setRandShape()
{
int randShape = QRandomGenerator::global()->bounded(7) + 1;
setShape(TetrixShape(randShape));
}
void TetrixCube::setShape(TetrixShape shape)
{
static const int coordsTable[8][4][2] =
{
{ { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } },
{ { 0, -1 }, { 0, 0 }, { 0, 1 }, { 0, 2 } },
{ { 0, 0 }, { 1, 0 }, { 0, 1 }, { 1, 1 } },
{ { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } },
{ { 1, -1 }, { 0, -1 }, { 0, 0 }, { 0, 1 } },
{ { 0, -1 }, { 0, 0 }, { -1, 0 }, { -1, 1 } },
{ { 0, -1 }, { 0, 0 }, { 1, 0 }, { 1, 1 } },
{ { -1, 0 }, { 0, 0 }, { 1, 0 }, { 0, 1 } }
};
for (int i = 0; i < 4; i++)
{
for (int j = 0; j < 2; ++j)
key_points[i][j] = coordsTable[shape][i][j];
}
cubeShape = shape;
}
int TetrixCube::minX() const
{
int min = key_points[0][0];
for (int i = 1; i < 4; ++i)
min = qMin(min, key_points[i][0]);
return min;
}
int TetrixCube::maxX() const
{
int max = key_points[0][0];
for (int i = 1; i < 4; ++i)
max = qMax(max, key_points[i][0]);
return max;
}
int TetrixCube::minY() const
{
int min = key_points[0][1];
for (int i = 1; i < 4; ++i)
min = qMin(min, key_points[i][1]);
return min;
}
int TetrixCube::maxY() const
{
int max = key_points[0][1];
for (int i = 1; i < 4; ++i)
max = qMax(max, key_points[i][1]);
return max;
}
TetrixCube TetrixCube::rotateLeft() const
{
if (cubeShape == SquareShape)
return *this;
TetrixCube t;
t.cubeShape = cubeShape;
for (int i = 0; i < 4; ++i)
{
t.setX(i, key_point_y(i));
t.setY(i, -key_point_x(i));
}
return t;
}
TetrixCube TetrixCube::rotateRight() const
{
if (cubeShape == SquareShape)
return *this;
TetrixCube t;
t.cubeShape = cubeShape;
for (int i = 0; i < 4; ++i)
{
t.setX(i, -key_point_y(i));
t.setY(i, key_point_x(i));
}
return t;
}