-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBlock.h
261 lines (230 loc) · 6.14 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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#pragma once
#include <iostream>
#include <vector>
#include "Console.h"
using namespace std;
#define BLACK 0
#define D_BLUE 1
#define D_GREEN 2
#define D_SKYBLUE 3
#define D_RED 4
#define D_VIOLET 5
#define D_YELLOW 6
#define GRAY 7
#define D_GRAY 8
#define BLUE 9
#define GREEN 10
#define SKYBLUE 11
#define RED 12
#define VIOLET 13
#define YELLOW 14
#define WHITE 15
class Block : public Console {
private:
vector<vector<vector<short>>> block;
int rotation = 0;
bool bomb = false;
char background = BLACK;
char foreground;
public:
Block(int i) {
if (i == 0) { // で, た, ぬ, っ
block = { {{0,1,0,0},{1,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,0,0},{0,1,1,0},{0,1,0,0},{0,0,0,0}},
{{0,0,0,0},{1,1,1,0},{0,1,0,0},{0,0,0,0}},
{{0,1,0,0},{1,1,0,0},{0,1,0,0},{0,0,0,0}}
};
}
if (i == 1) { // け
block = { {{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
{{0,1,1,0},{0,1,1,0},{0,0,0,0},{0,0,0,0}},
};
}
if (i == 2) { // ぱ び
block = { {{0,1,0,0},{0,1,0,0},{0,1,0,0},{0,1,0,0}},
{{0,0,0,0},{0,0,0,0},{1,1,1,1},{0,0,0,0}},
{{0,1,0,0}, {0,1,0,0},{0,1,0,0},{0,1,0,0}},
{{0,0,0,0}, {0,0,0,0},{1,1,1,1},{0,0,0,0}}
};
}
if (i == 3) { // ぉ
block = { { { 0,1,0,0 },{ 0,1,1,0 },{ 0,0,1,0 },{ 0,0,0,0 }},
{ { 0,1,1,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 }},
{ { 0,1,0,0 },{ 0,1,1,0 },{ 0,0,1,0 },{ 0,0,0,0 }},
{ { 0,1,1,0 },{ 1,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 }}
};
}
if (i == 4) { // ぉ 鋼企
block = { { { 0,0,1,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 0,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 1,1,0,0 },{ 0,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } }
};
}
if (i == 5) { // ぁ
block = { { { 0,1,0,0 },{ 0,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,1,0 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 0,1,1,1 },{ 0,0,0,1 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 0,0,1,0 },{ 0,1,1,0 },{ 0,0,0,0 } }
};
}
if (i == 6) { // ぁ 鋼企
block = { { { 0,0,0,1 },{ 0,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 0,1,0,0 },{ 0,1,1,0 },{ 0,0,0,0 } },
{ { 0,1,1,1 },{ 0,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,1,0 },{ 0,0,1,0 },{ 0,0,1,0 },{ 0,0,0,0 } }
};
}
// 蓄亜 鷺系
if (i == 7) { // ぁ
block = { { { 0,1,1,1 },{ 0,0,0,1 },{ 0,0,0,1 },{ 0,0,0,0 } },
{ { 0,0,0,1 },{ 0,0,0,1 },{ 0,1,1,1 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 0,1,0,0 },{ 0,1,1,1 },{ 0,0,0,0 } },
{ { 0,1,1,1 },{ 0,1,0,0 },{ 0,1,0,0 },{ 0,0,0,0 } }
};
}
if (i == 8) { // T
block = { { { 0,1,1,1 },{ 0,0,1,0 },{ 0,0,1,0 },{ 0,0,0,0 } },
{ { 0,0,0,1 },{ 0,1,1,1 },{ 0,0,0,1 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 0,0,1,0 },{ 0,1,1,1 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 0,1,1,1 },{ 0,1,0,0 },{ 0,0,0,0 } }
};
}
if (i == 9) { // +
block = { { { 0,1,0,0 },{ 1,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 1,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } }
};
}
if (i == 10) { // -け
block = { { { 0,0,1,0 },{ 0,1,1,0 },{ 0,1,1,0 },{ 0,0,0,0 } },
{ { 0,1,1,0 },{ 0,1,1,1 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,1,0 },{ 0,1,1,0 },{ 0,1,0,0 },{ 0,0,0,0 } },
{ { 1,1,1,0 },{ 0,1,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } }
};
}
if (i == 11) { // -_
block = { { { 0,1,0,0 },{ 0,0,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 0,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,1,0,0 },{ 0,0,1,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,1,0 },{ 0,1,0,0 },{ 0,0,0,0 },{ 0,0,0,0 } }
};
}
if (i == 12) { // -_
block = { { { 1,1,1,0 },{ 1,0,1,0 },{ 1,0,1,0 },{ 0,0,0,0 } },
{ { 1,1,1,0 },{ 0,0,1,0 },{ 1,1,1,0 },{ 0,0,0,0 } },
{ { 1,0,1,0 },{ 1,0,1,0 },{ 1,1,1,0 },{ 0,0,0,0 } },
{ { 1,1,1,0 },{ 1,0,0,0 },{ 1,1,1,0 },{ 0,0,0,0 } }
};
}
if (i == 777) {
block = { { { 0,0,0,0 },{ 0,0,2,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,0,0 },{ 0,0,2,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,0,0 },{ 0,0,2,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
{ { 0,0,0,0 },{ 0,0,2,0 },{ 0,0,0,0 },{ 0,0,0,0 } },
};
bomb = true;
}
foreground = i + 1;
}
void printBlock() {
for (int i = 0; i < block[rotation].size(); i++) {
setColor(foreground, background);
gotoXY(x, y + i);
int tmp_x = x;
for (int j = 0; j < block[rotation][i].size(); j++) {
if (block[rotation][i][j] == 1) {
cout << "=";
tmp_x += 2;
}
else if (block[rotation][i][j] == 2) {
cout << "【";
tmp_x += 2;
}else {
tmp_x += 2;
gotoXY(tmp_x, y+i);
}
}
}
setColor(WHITE, background);
}
bool isBomb() {
return this->bomb;
}
int getX() {
return this->x;
}
int getY() {
return this->y;
}
int getMaxX(int y) {
for (int i = 3; i >= 0; i--) {
if (block[rotation][y][i] != 0)
return i;
}
return -999;
}
int getMinX(int y) {
for (int i = 0; i < 4; i++) {
if (block[rotation][y][i] != 0)
return i;
}
return -999;
}
int getMaxY(int x) {
for (int i = 3; i >= 0; i--) {
if (block[rotation][i][x] != 0)
return i;
}
return -999;
}
int getMaxX_rotation(int y) {
for (int i = 3; i >= 0; i--) {
if (isFilled_rotation(i, y))
return i;
}
return -999;
}
int getMinX_rotation(int y) {
for (int i = 0; i < 4; i++) {
if (isFilled_rotation(i, y))
return i;
}
return -999;
}
int getMaxY_rotation(int x) {
for (int i = 3; i >= 0; i--) {
if (isFilled_rotation(x, i) == 1)
return i;
}
return -999;
}
int isFilled(int x, int y) {
if (block[rotation][y][x] == 1)
return 1;
return 0;
}
void rotate() {
rotation++;
if (rotation >= 4)
rotation = 0;
}
int isFilled_rotation(int x, int y) {
int r = getNextRotation();
if (block[r][y][x] == 1)
return 1;
return 0;
}
int getNextRotation() {
int ret = rotation + 1;
if (ret >= 4)
ret = 0;
return ret;
}
void setColor(char color, char backGround) {
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), (backGround << 4) + color);
}
};