-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPiece.cpp
executable file
·47 lines (40 loc) · 1.08 KB
/
Piece.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
#include <algorithm>
#include "Piece.h"
using namespace std;
void Piece::SetShape(PieceShape shape)
{
for (int i = 0; i < 4; i++)
for (int j = 0; j < 2; j++)
coords[i][j] = pieceCoords[shape][i][j];
pieceShape = shape;
}
int Piece::MaxX() const {
int element = coords[0][0];
for (int i = 0; i < 4; i++) element = max(element, coords[i][0]);
return element;
}
int Piece::MaxY() const {
int element = coords[0][1];
for (int i = 0; i < 4; i++) element = max(element, coords[i][1]);
return element;
}
int Piece::MinX() const {
int element = coords[0][0];
for (int i = 0; i < 4; i++) element = min(element, coords[i][0]);
return element;
}
int Piece::MinY() const {
int element = coords[0][1];
for (int i = 0; i < 4; i++) element = min(element, coords[i][1]);
return element;
}
Piece Piece::Rotation() const {
if (pieceShape == O_bloc) return *this;
Piece result;
result.pieceShape = pieceShape;
for (int i = 0; i<4; i++) {
result.SetX(i, -y(i));
result.SetY(i, x(i));
}
return result;
}