-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplay.cpp
272 lines (249 loc) · 11.9 KB
/
Display.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
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
262
263
264
265
266
267
268
269
270
271
272
#pragma warning(disable:4996)
#include "Display.h"
#include "Snake.h"
#include <iostream>
#include <windows.h>
#include <iomanip>
#include <conio.h>
#include <math.h>
#define N 200
using namespace std;
//首页
void Display::front_page()
{
Sleep(N);
cout << " " << endl; set_color(10);
cout << "/~~~~~~~~~~~~~~~\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "\\ ■■■■■ /" << endl;
cout << "/■■■■■■■ \\" << endl;
cout << "\\■■■ ■■■ /" << endl;
cout << "/■■■ \\" << endl;
cout << "\\ ■■■■ /" << endl;
cout << "/ ■■■■■ \\" << endl;
cout << "\\ ■■■ /" << endl;
cout << "/■■■ ■■■ \\" << endl;
cout << "\\■■■■■■■ /" << endl;
cout << "/ ■■■■■ \\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "~~~~~~~~~~~~~~~~~" << endl;
Sleep(N);
system("cls");
cout << " " << endl; set_color(11);
cout << "/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "\\ ■■■■■ ■■■ ■■ /" << endl;
cout << "/■■■■■■■ ■■■■ ■■ \\" << endl;
cout << "\\■■■ ■■■ ■■ ■■ ■■ /" << endl;
cout << "/■■■ ■■ ■■ ■■ \\" << endl;
cout << "\\ ■■■■ ■■ ■■ ■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ \\" << endl;
cout << "\\ ■■■ ■■ ■■ ■■ /" << endl;
cout << "/■■■ ■■■ ■■ ■■■■ \\" << endl;
cout << "\\■■■■■■■ ■■ ■■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ \\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
Sleep(N);
system("cls");
cout << " " << endl; set_color(12);
cout << "/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "\\ ■■■■■ ■■■ ■■ ■■■ /" << endl;
cout << "/■■■■■■■ ■■■■ ■■ ■■■■■ \\" << endl;
cout << "\\■■■ ■■■ ■■ ■■ ■■ ■■ ■■ /" << endl;
cout << "/■■■ ■■ ■■ ■■ ■■ ■■ \\" << endl;
cout << "\\ ■■■■ ■■ ■■ ■■ ■■ ■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■■■■■■ \\" << endl;
cout << "\\ ■■■ ■■ ■■ ■■ ■■■■■■■ /" << endl;
cout << "/■■■ ■■■ ■■ ■■■■ ■■ ■■ \\" << endl;
cout << "\\■■■■■■■ ■■ ■■■ ■■ ■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■ \\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
Sleep(N);
system("cls");
cout << " " << endl; set_color(13);
cout << "/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "\\ ■■■■■ ■■■ ■■ ■■■ ■■ ■ /" << endl;
cout << "/■■■■■■■ ■■■■ ■■ ■■■■■ ■■ ■ \\" << endl;
cout << "\\■■■ ■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ /" << endl;
cout << "/■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ \\" << endl;
cout << "\\ ■■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■■■■■■ ■■■ \\" << endl;
cout << "\\ ■■■ ■■ ■■ ■■ ■■■■■■■ ■■ ■ /" << endl;
cout << "/■■■ ■■■ ■■ ■■■■ ■■ ■■ ■■ ■ \\" << endl;
cout << "\\■■■■■■■ ■■ ■■■ ■■ ■■ ■■ ■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■ ■■ ■■\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl;
Sleep(N);
system("cls");
cout << " " << endl; set_color(14);
cout << "/~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\\" << endl;
cout << "\\ /" << endl;
cout << "/ \\" << endl;
cout << "\\ ■■■■■ ■■■ ■■ ■■■ ■■ ■ ■■■■■■ /" << endl;
cout << "/■■■■■■■ ■■■■ ■■ ■■■■■ ■■ ■ ■■■■■■ \\" << endl;
cout << "\\■■■ ■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ /" << endl;
cout << "/■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■ \\" << endl;
cout << "\\ ■■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■ ■■■■■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■■■■■■ ■■■ ■■■■■■ \\" << endl;
cout << "\\ ■■■ ■■ ■■ ■■ ■■■■■■■ ■■ ■ ■■ /" << endl;
cout << "/■■■ ■■■ ■■ ■■■■ ■■ ■■ ■■ ■ ■■ \\" << endl;
cout << "\\■■■■■■■ ■■ ■■■ ■■ ■■ ■■ ■ ■■■■■■ /" << endl;
cout << "/ ■■■■■ ■■ ■■ ■■ ■■ ■■ ■■ ■■■■■■ \\" << endl;
cout << "\\ /" << endl;
cout << "/ @Roc\\" << endl;
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; set_color(10);
Sleep(N);
cout << "使用 ↑ ↓ ← → 键或 W A S D 控制,按P暂停或继续,按Esc退出" << endl;
cout << "按Enter键进入" << endl;
while( _getch() != 13);
system("cls");
}
void Display::set_page()
{
system("cls");
cout << " " << endl; set_color(14);
cout << " ★==============================★" << endl;
cout << " || *----------* ||" << endl;
cout << " || | 贪吃蛇 | ||" << endl;
cout << " || *----------* ||" << endl;
cout << " || ||" << endl;
cout << " || *------------------------* ||" << endl;
cout << " || | 1.开始游戏 | ||" << endl;
cout << " || | 2.修改速度 | ||" << endl;
cout << " || | 3.修改障碍物 | ||" << endl;
cout << " || | 4.修改围墙设置 | ||" << endl;
cout << " || | 5.操作说明 | ||" << endl;
cout << " || | 6.查看排行榜 | ||" << endl;
cout << " || | 7.退出 | ||" << endl;
cout << " || *------------------------* ||" << endl;
cout << " || ||" << endl;
cout << " ★==============================★" << endl;
cout << " " << endl;
}
void Display::end_page(const char* name, int score, int ranking)
{
system("cls");
cout << " " << endl; set_color(14);
cout << " ★==============================★" << endl;
cout << " || *-----------* ||" << endl;
cout << " || | GameOver! | ||" << endl;
cout << " || *-----------* ||" << endl;
cout << " || ||" << endl;
cout << " || *------------------------* ||" << endl;
cout << " || |用户:" << setw(18) << left << name << "| ||" << endl;
cout << " || |得分:" << setw(18) << left << score << "| ||" << endl;
cout << " || *------------------------* ||" << endl;
cout << " || ||" << endl;
cout << " ★==============================★" << endl;
cout << " " << endl;
cout << "按Enter键继续" << endl;
while(_getch() != 13);
return;
}
//设置颜色
void Display::set_color(int a)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), a);
}
void Display::readme()
{
cout << "使用 ↑ ↓ ← → 或 w a s d 键控制,按p暂停或继续,按Esc退出\n按Enter键继续" << endl;
while(_getch() != 13);
return;
}
void Display::leaderboard()
{
FILE* pfile = fopen("users.txt", "r");
if (pfile == NULL)
{
cout << "查询失败!" << endl;
cout << "按Enter键继续" << endl;
while(_getch() != 13);
return;
}
struct User
{
char name[100] = { '\0' };
char score[10] = { '\0' };
char ranking[3] = { '\0' };
};
User users[10];
int num = 0;
if(fscanf(pfile, "%s%s%s", users[0].name, &users[0].score, &users[0].ranking) > 0)
num++;
for (int i = 1; i < 10; i++)
{
if (feof(pfile))
break;
if (fscanf(pfile, "%s%s%s", users[i].name, &users[i].score, &users[i].ranking) > 0)
num++;
else
break;
}
system("cls");
cout << " " << endl; set_color(12);
cout << " ★================================================================★" << endl;
cout << " || *------------* ||" << endl;
cout << " || | 排行榜 | ||" << endl;
cout << " || *------------* ||" << endl;
cout << " || ||" << endl;
cout << " || *----------------------------------------------------------* ||" << endl;
if (num == 0)
cout << " || | 暂无用户! | ||" << endl;
else
{
cout << " || | 排名 | 用户 |历史最高得分| ||" << endl;
cout << " || *----------------------------------------------------------* ||" << endl;
}
for (int i = 0; i < num; i++)
cout << " || |"<< center(users[i].ranking, 6) << "|" << center(users[i].name, 38) << "|" << center(users[i].score, 12) << "| ||" << endl;
cout << " || *----------------------------------------------------------* ||" << endl;
cout << " || ||" << endl;
cout << " ★================================================================★" << endl;
cout << " " << endl;
fclose(pfile);
cout << "按Enter键继续" << endl;
while(_getch() != 13);
return;
}
string Display::center(const char* s, int w)
{
int l = strlen(s);
float n = (w - l) / 2.0;
int left = floorf(n);
int right = ceilf(n);
string str = s;
for (int i = 0; i < left; i++)
str = " " + str;
for (int i = 0; i < right; i++)
str += " ";
return str;
}
void Display::set_position(int x, int y) //设定输出位置
{
COORD coordinate;
coordinate.X = x - 1;
coordinate.Y = y - 1;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coordinate);
}
void Display::hide_cursor()
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
CONSOLE_CURSOR_INFO CursorInfo;
GetConsoleCursorInfo(handle, &CursorInfo);
CursorInfo.bVisible = false;
SetConsoleCursorInfo(handle, &CursorInfo);
}