class MyShape protected static const int CUBE_SIDE 30 static const int

 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
class MyShape
{
protected:
static const int CUBE_SIDE = 30;
static const int HALF_CUBE_SIDE = 15;
QPoint center_canvas;
QPoint center_field;
QList<QPoint> coordinates_field;
QRect **rects;
Qt::GlobalColor color;
public:
MyShape(const QPoint &center_canvas = {0,0},const QPoint &center_field = {0,0}, const Qt::GlobalColor &color = Qt::red);
virtual ~MyShape()
{
for(int i = 0; i < 4; i++)
delete rects[i];
delete rects;
}
bool isColission(bool **field);
bool isAllowedToFall(bool **field);
void fillCanvasCoordinatesByField();
void fillFieldCoordinatesByCanvas();
virtual void move(const QPoint &vector)
{
for(int i = 0; i < 4; i++)
{
coordinates_field[i].setX(coordinates_field[i].x() + vector.x());
coordinates_field[i].setY(coordinates_field[i].y() + vector.y());
rects[i]->moveTo(rects[i]->x() + vector.x() * CUBE_SIDE, rects[i]->y() + vector.y() * CUBE_SIDE);
}
center_field.setX(center_field.x() + vector.x());
center_field.setY(center_field.y() + vector.y());
center_canvas.setX(center_field.x() * CUBE_SIDE);
center_canvas.setY(center_field.y() * CUBE_SIDE);
}
QList<QPoint>* getNewCoordinates(const QPoint &vect);
QList<QPoint>* getNewCoordinates();
virtual void rotate()
{
int xPrev;
for(int i = 0; i < 4; i++)
{
xPrev = coordinates_field[i].x();
coordinates_field[i].setX(center_field.x() - ( coordinates_field[i].y() - center_field.y()));
coordinates_field[i].setY(center_field.y() + ( xPrev - center_field.x()));
// -1 так как смещение -30
rects[i]->moveTo((coordinates_field[i].x() )* MyShape::CUBE_SIDE,coordinates_field[i].y() * MyShape::CUBE_SIDE);
}
}
static int round(double x)
{
return (x >= 0) ? static_cast<int>(x + 0.5) : static_cast<int>(x - 0.5);
}
friend class Tetris;
};