-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
101 lines (97 loc) · 2.88 KB
/
main.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
92
93
94
95
96
97
98
99
100
101
#include <ctime>
#include "Block.h"
#include "Move.h"
#define RUNNING 1
#define MOVE_DELAY 500 // Block下落延迟
#define INPUT_DELAY 100 // 输入延迟
#define LEVEL 10 // 难度系数
void myTest();
int Score = 0; /** 分数 */
int main() {
// myTest();
srand(time(NULL));
Block curBlock(BLOCK_EMPTY, 0, PointStart);
InitGrid();
curBlock = GenNextBlock();
int waitTime = 0;
initgraph(GRID_WIDTH * SLIDER_PX, (GRID_HEIGHT - LOAD_HEIGHT) * SLIDER_PX);
BeginBatchDraw();
while (RUNNING){
if(GetAsyncKeyState(VK_DOWN)){
if(TryMove(curBlock, MOVE_DOWN)){}
else{
if(GoOver(curBlock)){
break;
}
int curRow = CaptureBlock(curBlock);
ClearLine(curRow);
curBlock = GenNextBlock();
}
}else if(GetAsyncKeyState(VK_LEFT)){
if(TryMove(curBlock, MOVE_LEFT)){}
}else if(GetAsyncKeyState(VK_RIGHT)){
if(TryMove(curBlock, MOVE_RIGHT)){}
}else if(GetAsyncKeyState(VK_UP)){
if(TryTurn(curBlock)){}
Sleep(100);
}else if(GetAsyncKeyState(VK_SPACE)){
while(TryMove(curBlock, MOVE_DOWN)){}
Sleep(100);
if(GoOver(curBlock)){
break;
}
int curRow = CaptureBlock(curBlock);
ClearLine(curRow);
curBlock = GenNextBlock();
}
else if(GetAsyncKeyState(VK_ESCAPE)){
break;
}
if(waitTime >= MOVE_DELAY - Score * LEVEL){
waitTime = 0;
if(TryMove(curBlock, MOVE_DOWN)){}
else{
if(GoOver(curBlock)){
break;
}
int curRow = CaptureBlock(curBlock);
ClearLine(curRow);
curBlock = GenNextBlock();
}
}
DrawGrid();
DrawBlock(curBlock);
DrawInfo();
FlushBatchDraw();
Sleep(INPUT_DELAY);
waitTime += INPUT_DELAY;
}
cleardevice();
settextcolor(RGB(255, 255, 255));
int xStart = (GRID_WIDTH * SLIDER_PX - 100)/2;
int yStart = ((GRID_HEIGHT - LOAD_HEIGHT) * SLIDER_PX - 70)/2;
outtextxy(xStart, yStart, _T("GAME OVER!"));
outtextxy(xStart-20, yStart+50, _T("SCORE:"));
char *score = new char[10];
_itoa(Score, score, 10);
outtextxy(xStart+90, yStart+50, score);
FlushBatchDraw();
Sleep(2000);
EndBatchDraw();
closegraph();
return 0;
}
void myTest(){
IMAGE img,c1,c2;
loadimage(&img, _T("background.jpg"));
loadimage(&c1, _T("Mimikyu1.png"));
loadimage(&c2, _T("!Mimikyu1.png"));
initgraph(1023,682);
BeginBatchDraw();
putimage(0, 0, &img);
while(1){
putimage(500, 500, &c2, SRCAND);
putimage(500, 500, &c1, SRCINVERT);
FlushBatchDraw();
}
}