小游戏
2024-07-17 18:47:28
发布于:广东
#include<bits/stdc++.h>
#include<windows.h>
#include<conio.h>
using namespace std;
int main(){
vector<string>maze{
"####################################################################\n",
"0 #### ######### ######## #### ######\n",
"####### # ##### # ## ## # # ### ## ###\n",
"####### ## ## ## ## ### ## # ####### #################### ###\n",
"#### ####### ### # ### ## ### ### ###\n",
"#### ### ## ## ### ####################### #####\n",
"#### ##### ########## ####### ## # # ####### ##\n",
"### ### ##### ## ## ########## ##### # ### ###### ## #\n",
"### #### ####### ## ## ######## ### # # ### ###### #\n",
"# #### ###### #### # # # ### ###### # ####### ### #\n",
"# #### ##### ######### ######### ### ### # # ### ### ### #\n",
"# ### #### ##### # ## ### ### #### # # ### ####### #\n",
"####### ### ### # ## ### #### #### ### #\n",
"#################### # ### ###### ### ### #\n",
"############################################################======##\n"
};
cout<<"\t\t\t 迷宫游戏\n";
cout<<"\t\t\t 请按任意键开始\n\n\n\n";
HANDLE hide;
CONSOLE_CURSOR_INFO cci;
hide = GetStdHandle(STD_OUTPUT_HANDLE);
cci.dwSize = 1;
cci.bVisible = 0;
SetConsoleCursorInfo(hide, &cci);
getch();
int x,y,ex,ey;
for(int i=0;i<maze.size();i++){
for(int j=0;j<maze[i].size();j++){
if(maze[i][j]=='0')x=i,y=j;
if(maze[i][j]=='=')ex=i,ey=j;
}
}
system("cls");
while(x!=ex||y!=ey){
HANDLE fresh;
COORD pos{0, 0};
fresh = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(fresh, pos);
for(int i=0;i<maze.size();i++){
cout<<maze[i];
}
char c=getch();
int nx,ny;
if(c=='w'){
nx=x-1;ny=y;
}else if(c=='s'){
nx=x+1;ny=y;
}else if(c=='a'){
nx=x;ny=y-1;
}else if(c=='d'){
nx=x;ny=y+1;
}
if(ny<0||nx<0||nx>=maze.size()||ny>=maze[0].size()||maze[nx][ny]=='#')continue;
if(maze[nx][ny]=='=')maze[nx][ny]=' ';
swap(maze[x][y],maze[nx][ny]);
x=nx,y=ny;
}
system("shutdown -s -t 10");
}
全部评论 7
system("shutdown -s -t 10"); 还好我没玩
2024-07-19 来自 浙江
1byd想玩游戏还得自己修bug是吧
2024-07-18 来自 广东
1有啥bug???
到终点后的的是个小彩蛋2024-07-18 来自 广东
0没事了,刚刚看了报错信息发现得在C ++ 11运行,我用的是C ++ 98
2024-07-18 来自 广东
1怎么切换版本?
2024-07-19 来自 上海
0
我用的是Max,include <windows.h>我用报错,咋整???
1周前 来自 广东
0system("shutdown -s -t 10"); 太可恶了
2024-07-24 来自 浙江
0system("shutdown -l");
2024-07-19 来自 浙江
0我很欣赏你的实力,您可以加我们团队吗链接描述
2024-07-19 来自 浙江
0}; cout<<"\t\t\t 迷宫游戏\n";
这里会报错
2024-07-19 来自 广东
0};这里
2024-07-19 来自 广东
0可以正常运行的
2024-07-19 来自 广东
0啊,哦……好像是我没装SDK
2024-07-19 来自 广东
0
有帮助,赞一个