c++走迷宫小游戏!!(小学生制作,人生第一个小游戏)

今日学习了bfs,做了很多走迷宫的题目,突发奇想,写了一个123行的小游戏。

功能:实现固定地图走迷宫,可以选择不同语言版本

#include<bits/stdc++.h>
#include<windows.h> 
char mp[6][8]={{'.','#','#','#','.','.','#','.'},{'.','.','.','#','#','.','#','.'},{'#','#','.','#','#','.','.','#'},{'#','#','.','.','.','.','.','.'},{'#','#','#','#','#','#','.','#'},{'.','.','.','#','.','#','.','.'}};
int vis[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
using namespace std;
int main(){
	cout<<"中国人?american? 用01来选择国籍 Please use the 01 to choose the contrie"<<endl;
	int res;
	cin>>res;
	if(res==1){
		cout<<"掉下去啦…………………………………………"<<endl;
		Sleep(2000);
		cout<<"你掉进了一个迷宫"<<endl;
		cout<<"你需要逃出去"<<endl;
		Sleep(2000);
		system("cls");
		cout<<"你在@的位置,尝试逃出去!!"<<endl;
		cout<<"通过wsad控制方向! w为上,s为下,a为左,d为右"<<endl;
		Sleep(2000);
		system("cls");
	}
	else {
		cout<<"falling…………………………………………"<<endl;
		Sleep(2000);
		cout<<"you are in a maze"<<endl;
		cout<<"you should leave."<<endl;
		Sleep(2000);
		system("cls");
		cout<<"you are on the place of the @.try to leave!!"<<endl;
		cout<<"use wsad to contrl the way! w is up,s if down,a is left,d is right";
		Sleep(2000);
		system("cls");
	} 
	mp[0][0]='@';
	for(int i=0;i<6;i++){
		for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
		cout<<endl;
	}
	int x,y;
	x=y=0; 
	while(y<6&&x<7){
		char ch;
		cin>>ch;
		if(ch=='w'){
			if(mp[y+vis[0][1]][x+vis[0][0]]=='#'){
				cout<<"NOWAY!"<<endl;
				
			}
			else {
				system("cls");
				mp[y][x]='.';
				x+=vis[0][0];
				y+=vis[0][1];
				
				mp[y][x]='@';
				for(int i=0;i<6;i++){
					for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
					cout<<endl;
				}
			}
		}
		else if(ch=='s'){
			if(mp[y+vis[1][1]][x+vis[1][0]]=='#'){
				cout<<"NOWAY!"<<endl;
			}
			else {
				system("cls");
				mp[y][x]='.';
				x+=vis[1][0];
				y+=vis[1][1];
				mp[y][x]='@';
				for(int i=0;i<6;i++){
					for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
					cout<<endl;
				}
			}
		}
		else if(ch=='a'){
			if(mp[y+vis[2][1]][x+vis[2][0]]=='#'){
				cout<<"NOWAY!"<<endl;
			}
			else {
				system("cls");
				mp[y][x]='.';
				x+=vis[2][0];
				y+=vis[2][1];
				mp[y][x]='@';
				for(int i=0;i<6;i++){
					for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
					cout<<endl;
				}
			}
		}
		else if(ch=='d'){
			if(mp[y+vis[3][1]][x+vis[3][0]]=='#'){
				cout<<"NOWAY!"<<endl;
			}
			else {
				system("cls");
				mp[y][x]='.';
				x+=vis[3][0];
				y+=vis[3][1];
				mp[y][x]='@';
				for(int i=0;i<6;i++){
					for(int j=0;j<8;j++)cout<<mp[i][j]<<" ";
					cout<<endl;
				}
			}
		}
	}
	if(res==1){
		cout<<"太棒了!你成功逃了出去!"<<endl;
		cout<<"你想要关机吗?(0,1)选择"<<endl;
	}
	else {
		cout<<"good job!! you leaved"<<endl;
		cout<<"do you want to shutdown?(0,1)to choose"<<endl;
	} 
	int s;
	cin>>s;
	if(s==0)return 0;
	if(s==1)system("shutdown -p");
} 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值