-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
69 lines (67 loc) · 1.31 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
#include<Snake_Game.h>
#include<iostream>
#include<string>
int MapLength = 10,MapWidth = 10;//默认地图大小
int GameSpeed = 1;
void MapSizeSet()
{
std::cout << "请设置地图长度:";
std::cin >> MapLength;
std::cout << "请设置地图宽度:";
std::cin >> MapWidth;
}
int main()
{
while(1)
{
std::cout << "<--------欢迎来到贪吃蛇------->\n";
std::cout << "1.开始游戏\n";
std::cout << "2.设置地图大小(默认为10*10)\n";
std::cout << "3. 设置速度\n";
std::cout << "4. 退出\n\n\n";
std::cout << "请输入选项:";
std::string PlayerInput;
std::cin >> PlayerInput;
if (PlayerInput.length() != 1)
{
std::cout << "输入不合法!\n";
continue;
}
char PlayerChoice = PlayerInput[0];
if (!isdigit(PlayerChoice))
{
std::cout << "输入不合法!\n";
continue;
}
switch (PlayerChoice)
{
case '2':
{
MapSizeSet(); break;
}
case '1':
{
Snake_Game* GAME = new Snake_Game(MapLength, MapWidth,GameSpeed);
GAME->GameRun();
delete GAME;
break;
}
case '4':
{
exit(0);
}
case '3':
{
std::cout << "请选择速度等级(1,2,3)(数字越大速度越慢):";
std::cin >> GameSpeed;
break;
}
default:
{
std::cout << "输入不合法!\n";
continue; break;
}
}
}
return 0;
}