-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
71 lines (57 loc) · 1.29 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
#include "def.h"
#include "player.h"
#include "enemy.h"
#include "map.h"
#include "camera.h"
#include "input_handler.h"
#include "game.h"
int main()
{
#ifdef __linux__
initscr(); // 初始化ncurses
start_color();
cbreak(); // 禁用行缓冲
noecho(); // 不在屏幕上显示按键
nodelay(stdscr, TRUE); // 设置非阻塞模式
keypad(stdscr, TRUE); // 启用键盘特殊按键(如方向键)
#endif
InitAllcolor();
bool playAgain = true;
Game game;
while (playAgain)
{
CLEARWINDOW;
MOVECURSOR(0, 0);
#ifdef _WIN32
HideConsoleCursor(); // 隐藏光标
#elif __linux__
nodelay(stdscr, TRUE); // 设置非阻塞模式
#endif
game.run();
gamestatus = 1;
iswin = -1;
#ifdef _WIN32
ShowConsoleCursor(); // 显示光标
FlushConsoleInputBuffer(GetStdHandle(STD_INPUT_HANDLE)); // 清空输入缓冲区
#endif
char choice = 0;
#ifdef _WIN32
scanf(" %c", &choice); //%c前面加空格以跳过制表符、空格和换行符等空白字符,确保scanf只读取有效的字符
#elif __linux__
nodelay(stdscr, FALSE); // 设置阻塞模式
choice = getch();
#endif
if (choice == 'N' || choice == 'n')
{
playAgain = false;
}
else if (choice == 'Y' || choice == 'y')
{
playAgain = true;
}
}
#ifdef __linux__
endwin();
#endif
return 0;
}