-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDisplay.cpp
More file actions
113 lines (99 loc) · 2.9 KB
/
Display.cpp
File metadata and controls
113 lines (99 loc) · 2.9 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
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
#include"Drew.h"
void DISPLAY_DESK() {
initgraph(screenWidth, screenHigh);
setbkcolor(WHITE);
cleardevice();
settextcolor(0xFFFF00);
settextstyle(70, 35, L"楷体");
outtextxy(110, 70, L"贪");
outtextxy(386, 70, L"吃");
outtextxy(660, 70, L"蛇");
settextcolor(0xAAAA00);
settextstyle(40, 0, L"楷体");
outtextxy(290, 220, L"A 开始游戏");
outtextxy(290, 300, L"B 观察模式");
outtextxy(290, 380, L"C 游戏帮助");
}
void fnDrawSnakeBody(SnakeMap* map, SnakeRelevant* Data) {
int xh = 0;
int yh = 0;
//清屏
cleardevice();
//铺底色
setfillcolor(none);
solidrectangle(MapBorderA_x, MapBorderA_y, MapBorderB_x, MapBorderB_y);
for (int i = pmapW + 1; i < pmapS - pmapW; i++) {
//跳过边界和空方快的绘画
if (i % pmapW == 0 || i % pmapW == pmapW - 1 || map[i].Attributes == none)
continue;
//更新坐标
xh = DrewStartPoint_x + (i % pmapW) * cellWidth;
yh = DrewStartPoint_y + (i / pmapW) * cellWidth;
//绘画食物
if (i == Data->food) {
setfillcolor(apple);
solidrectangle(xh, yh, xh + cellWidth - cellGap, yh + cellWidth - cellGap);
continue;
}
//绘画蛇头
if (i == Data->head) {
setfillcolor(LIGHTBLUE);
solidrectangle(xh, yh, xh + cellWidth - cellGap, yh + cellWidth - cellGap);
continue;
}
//蛇身
if (i == Data->tail)
setfillcolor(RED);
else
setfillcolor(SnakeBody);
//突起结点以连接个个方块
switch (map[i].Direction)
{
case left:
solidrectangle(xh - cellGap, yh, xh + cellWidth - cellGap, yh + cellWidth - cellGap);
break;
case up:
solidrectangle(xh, yh - cellGap, xh + cellWidth - cellGap, yh + cellWidth - cellGap);
break;
case right:
solidrectangle(xh, yh, xh + cellWidth, yh + cellWidth - cellGap);
break;
case down:
solidrectangle(xh, yh, xh + cellWidth - cellGap, yh + cellWidth);
break;
case unkown:
solidrectangle(xh, yh, xh + cellWidth - cellGap, yh + cellWidth - cellGap);
break;
}
}
}
void fnOutputMessage(SnakeRelevant* Data, bool op)
{
//黑边框
setlinecolor(BLACK);
setlinestyle(PS_SOLID, 2);
rectangle(MapBorderA_x, MapBorderA_y, MapBorderB_x, MapBorderB_y);
setlinecolor(RED);
line(outputMessageA_x, outputMessageAB_y, outputMessageB_x, outputMessageAB_y);
setbkmode(TRANSPARENT);
settextstyle(MessageWidth, MessageWidth / 2, L"微软雅黑");
wchar_t str[50];
if(op)
swprintf_s(str,
L"score%3d|Dir%2d|step%3d|fxy%3d|txy%3d",
(int)(100 * debuggingResults()),
Data->tempdir,
Data->stepNumber,
CheakHtoTFSafety(Data->food, 0),
CheakHtoTFSafety(Data->tail, 0)
);
else
swprintf_s(str,
L"score:%3d|spe:%%%2d|fxy(%3d,%3d)",
Data->score,
(int)(PlayerSpeed - Data->speed) * 100 / PlayerSpeed,
Data->x_FoodHead,
Data->y_FoodHead
);
outtextxy(outputMessage__x, outputMessageAB_y - MessageWidth - 2, str);
}