forked from jqx123/CodeCrusader-Tetris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathblock.cpp
91 lines (85 loc) · 1.8 KB
/
block.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
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
#include "block.h"
#include "cubePoint.h"
#define DOWN 0
#define LEFT 1
#define RIGHT 2
// 画出block
void AbstractBlock::showblock()
{
int i,j;
CubePoint p;
//int size = 16;//图片大小
for(i = 0; i < 4; i++)
for(j = 0; j < 4; j++)
{
if(bk[i][j] == 1)
{
p.setLocate(xbase+ (y + j) * cube_size,ybase+ (x + i) * cube_size);
p.setColor(BLACK);
p.printPoint();
}
}
}
// 画出block
void AbstractBlock::shownextblock()
{
int i, j;
CubePoint p;
//int size = 16;//图片大小
for (i = 0; i < 4; i++)
for (j = 0; j < 4; j++)
{
if (bk[i][j] == 1)
{
p.setLocate(301 + (y + j) * cube_size, 290 + (x + i) * cube_size);
p.setColor(BLACK);
p.printPoint();
}
else {
p.setLocate(301 + (y + j) * cube_size, 290 + (x + i) * cube_size);
p.setColor(CLEAR);
p.printPoint();
}
}
}
// 移动block
int AbstractBlock::move(int dir)
{
switch (dir)
{
case DOWN:
x++;
break;
case LEFT:
y--;
break;
case RIGHT:
y++;
break;
default:
break;
}
return 0;
}
// 旋转block
void AbstractBlock::rotate()
{
int i,j;
int temp[4][4] = { 0 };
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
{
temp[j][2 - i] = bk[i][j];
}
for(i = 0; i < 3; i++)
for(j = 0; j < 3; j++)
{
bk[i][j] = temp[i][j];
}
}
// int main(){
// BlockFactory *block = new BlockFactory("LongBlock");
// block->shape();
// int *num = (int*)block->getArray();
// printf("%d",num[3]);
// }