-
Notifications
You must be signed in to change notification settings - Fork 0
/
Block.h
136 lines (117 loc) · 4.23 KB
/
Block.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#pragma once
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QGraphicsItemGroup>
#include <QPoint>
#include <QColor>
#include <array>
#include "EnumArray.h"
namespace Block{
enum class Type{
Empty,
//■ ■ ■
//■
J,
//■
//■ ■ ■
L,
// ■ ■
//■ ■
S,
//■ ■
// ■ ■
Z,
// ■
//■ ■ ■
T,
//■ ■ ■ ■
I,
//■ ■
//■ ■
O,
Preview,
Garbage
};
using enum Type;
enum class SpinDirection : bool{
Clockwise,
CounterClockwise,
};
enum class SpinType : char{
OriginalLeft,
OriginalRight,
AfterSpinLeft,
AfterSpinRight
};
enum class ISpinType : char{
SpawnToRight,
RightToSpawnUpSideDown,
SpawnUpSideDownToLeft,
LeftToSpawn
};
using TetrominoesCoord = std::array<QPoint, 4>;
constexpr auto coordinate{ []() constexpr{
enumArray<Type, TetrominoesCoord> coordinate;
coordinate[Type::Empty] = {{{0, 0}, {0, 0}, {0, 0}, {0, 0} }};
coordinate[Type::J] = {{{0, 0}, {0, 1}, {1, 1}, {2, 1} }};
coordinate[Type::L] = {{{2, 0}, {0, 1}, {1, 1}, {2, 1} }};
coordinate[Type::S] = {{{1, 0}, {2, 0}, {0, 1}, {1, 1} }};
coordinate[Type::Z] = {{{0, 0}, {1, 0}, {1, 1}, {2, 1} }};
coordinate[Type::T] = {{{1, 0}, {0, 1}, {1, 1}, {2, 1} }};
coordinate[Type::I] = {{{0, 1}, {1, 1}, {2, 1}, {3, 1} }};
coordinate[Type::O] = {{{0, 0}, {0, 1}, {1, 0}, {1, 1} }};
return coordinate;
}()};
constexpr auto color{ []() constexpr{
enumArray<Type, QColor> color;
color[Type::Empty] = QColor( 0, 0, 0, 0); //transparent
color[Type::J] = QColor( 0, 0, 255);
color[Type::L] = QColor(250, 170, 0);
color[Type::S] = QColor( 0, 255, 0);
color[Type::Z] = QColor(255, 0, 0);
color[Type::T] = QColor(153, 0, 255);
color[Type::I] = QColor( 0, 255, 255);
color[Type::O] = QColor(250, 255, 0);
color[Type::Preview] = QColor( 63, 63, 63 );
color[Type::Garbage] = QColor(150, 150, 150);
return color;
}()};
using coordinateArray = std::array<QPoint, 5>;
//Spin Table
/*
Test 1 Test 2 Test 3 Test 4 Test 5
0->R ( 0, 0) (-1, 0) (-1,+1) ( 0,-2) (-1,-2)
2->R ( 0, 0) (-1, 0) (-1,+1) ( 0,-2) (-1,-2)
L->2 ( 0, 0) (-1, 0) (-1,-1) ( 0,+2) (-1,+2)
L->0 ( 0, 0) (-1, 0) (-1,-1) ( 0,+2) (-1,+2)
R->0 ( 0, 0) (+1, 0) (+1,-1) ( 0,+2) (+1,+2)
R->2 ( 0, 0) (+1, 0) (+1,-1) ( 0,+2) (+1,+2)
0->L ( 0, 0) (+1, 0) (+1,+1) ( 0,-2) (+1,-2)
2->L ( 0, 0) (+1, 0) (+1,+1) ( 0,-2) (+1,-2)
*/
constexpr auto normalSpinTable{ []() constexpr {
enumArray<SpinType,coordinateArray> spinTable;
spinTable[SpinType::OriginalLeft ] = {{{ 0, 0}, {-1, 0}, {-1, 1}, { 0,-2}, {-1,-2}}};
spinTable[SpinType::OriginalRight ] = {{{ 0, 0}, { 1, 0}, { 1, 1}, { 0,-2}, { 1,-2}}};
spinTable[SpinType::AfterSpinLeft ] = {{{ 0, 0}, { 1, 0}, { 1,-1}, { 0, 2}, { 1, 2}}};
spinTable[SpinType::AfterSpinRight] = {{{ 0, 0}, {-1, 0}, {-1,-1}, { 0, 2}, {-1, 2}}};
return spinTable;
}()};
constexpr auto ISpinTable{ []()constexpr{
enumArray<ISpinType,coordinateArray> spinTable;
spinTable[ISpinType::SpawnToRight ] = {{{ 0, 0}, {-2, 0}, { 1, 0}, {-2, 1}, { 1,-2}}};
spinTable[ISpinType::RightToSpawnUpSideDown] = {{{ 0, 0}, {-1, 0}, { 2, 0}, {-1,-2}, { 2, 1}}};
spinTable[ISpinType::SpawnUpSideDownToLeft ] = {{{ 0, 0}, { 2, 0}, {-1, 0}, { 2,-1}, {-1, 2}}};
spinTable[ISpinType::LeftToSpawn ] = {{{ 0, 0}, { 1, 0}, {-2, 0}, { 1, 2}, {-2,-1}}};
return spinTable;
}()};
class Tetrominoes : public QGraphicsItemGroup{
std::array<QGraphicsRectItem*,4> m_block;
enum Type m_currentBlock{ Type::Empty };
const float m_unitSize;
public:
Tetrominoes(float unitSize);
void setBlock(enum Type type);
enum Type getType() const;
};
}