-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTetromino.h
More file actions
69 lines (54 loc) · 1.27 KB
/
Tetromino.h
File metadata and controls
69 lines (54 loc) · 1.27 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
#ifndef TETROMINO_H
#define TETROMINO_H
#include <SDL2/SDL.h>
#include <array>
#include <string>
#include <map>
enum class TetrominoType {
F,
I,
L,
N,
P,
T,
U,
V,
W,
X,
Y,
Z,
None
};
struct PieceDefinition {
std::array<std::array<int, 5>, 5> shape;
SDL_Color color;
};
class Tetromino {
public:
Tetromino();
explicit Tetromino(TetrominoType type);
void setType(TetrominoType type);
TetrominoType getType() const { return m_type; }
void rotate();
void move(int dx, int dy);
int getX() const { return m_x; }
int getY() const { return m_y; }
void setX(int x) { m_x = x; }
void setY(int y) { m_y = y; }
const std::array<std::array<int, 5>, 5>& getShape() const { return m_shape; }
SDL_Color getColor() const;
static TetrominoType randomType();
// Config file loading
static bool loadConfig(const std::string& filename);
static bool loadDefaultConfig();
static void useDefaultShapes();
private:
TetrominoType m_type;
std::array<std::array<int, 5>, 5> m_shape;
int m_x;
int m_y;
void initializeShape(TetrominoType type);
static std::map<TetrominoType, PieceDefinition> s_customPieces;
static bool s_useCustom;
};
#endif // TETROMINO_H