-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTetrimino.h
111 lines (91 loc) · 2.61 KB
/
Tetrimino.h
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
#include "Brick.h"
#include <SDL2/SDL.h>
#include <memory>
#ifndef TETRIMINO_H
#define TETRIMINO_H
#define TETRIMINO_SIZE 4
enum Tetrimino_t{
I_TETRIMINO,
J_TETRIMINO,
L_TETRIMINO,
O_TETRIMINO,
S_TETRIMINO,
T_TETRIMINO,
Z_TETRIMINO,
TETRIMINO_T_END
};
const int I_TETRIMINO_NUM_VERSIONS=2;
const int I_TETRIMINO_VER[I_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,2,1,2,2,2,3,2,
2,0,2,1,2,2,2,3
};
const int O_TETRIMINO_NUM_VERSIONS=1;
const int O_TETRIMINO_VER[O_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
1,1,2,1,1,2,2,2
};
const int L_TETRIMINO_NUM_VERSIONS=4;
const int L_TETRIMINO_VER[L_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,1,1,1,2,1,0,2,
0,0,1,0,1,1,1,2,
0,1,1,1,2,1,2,0,
1,0,1,1,1,2,2,2
};
const int J_TETRIMINO_NUM_VERSIONS=4;
const int J_TETRIMINO_VER[J_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,1,1,1,2,1,2,2,
1,0,1,1,1,2,0,2,
0,0,0,1,1,1,2,1,
1,0,1,1,1,2,2,0
};
const int S_TETRIMINO_NUM_VERSIONS=2;
const int S_TETRIMINO_VER[S_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,2,1,2,1,1,2,1,
1,0,1,1,2,1,2,2
};
const int T_TETRIMINO_NUM_VERSIONS=4;
const int T_TETRIMINO_VER[T_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,1,1,1,2,1,1,2,
0,1,1,1,1,0,1,2,
0,1,1,1,2,1,1,0,
1,0,1,1,1,2,2,1
};
const int Z_TETRIMINO_NUM_VERSIONS=2;
const int Z_TETRIMINO_VER[Z_TETRIMINO_NUM_VERSIONS * TETRIMINO_SIZE * 2] = {
0,1,1,1,1,2,2,2,
1,1,1,2,2,1,2,0
};
class Tetrimino;
typedef std::shared_ptr<Tetrimino> pTetrimino;
class Tetrimino{
protected:
pBrick m_bricks[TETRIMINO_SIZE];
SDL_Point m_pos;
Tetrimino_t m_type;
//size of the bricks, number of rotations of curent tetrimino type
//and current version(aka rotation) of the current type
int m_sz, m_num_versions, m_version;
//points to the relative position data of the current tetrimino type and for the current version
int* m_type_start, *m_ver_start;
Color m_color;
//update the m_ver_pos pointer according to the current version of tetrimino type
//must call when we change m_version
void updateBricks();
void makeIPiece(int version=0);
void makeJPiece(int version=0);
void makeLPiece(int version=0);
void makeOPiece(int version=0);
void makeSPiece(int version=0);
void makeTPiece(int version=0);
void makeZPiece(int version=0);
void makeBricks();
void placeBricks();
public:
Tetrimino(int x, int y,int brick_sz,Tetrimino_t type);
pBrick* getBricks() {return m_bricks; }
void show(SDL_Renderer*) const;
void move(int x, int y);
Tetrimino_t getType() const { return m_type; }
SDL_Point getPos() const {return m_pos; }
void rotate(bool forward=true);
};
#endif //TETRIMINO_H