您的当前位置:首页正文

迷宫小游戏(V1.0)

2024-11-27 来源:个人技术集锦
#include<iostream>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
using namespace std;
//创建迷宫
char maze[15][15]=
{
	"############",	//0
	"#          #",	//1
	"# ###### ###",	//2
	"# #        #",	//3
	"# ######## #",	//4
	"#      ##  #",	//5
	"# #### #  ##",	//6
	"#    # # ###",	//7
	"#### # # # #",	//8
	"#    # # # #",	//9
	"# ##   #   #",	//10
	"######$#####"	//11
},keys;
int x,y;
int main(){
	Sleep(750);//暂停750毫秒
	x=10,y=8;
    //提示语
	MessageBox(0,
	"请按上、下、左、右键操控i小人!",
	"提示",
	MB_ICONINFORMATION|MB_OK|/*置顶窗口*/MB_TOPMOST);
	while(maze[x][y]!='$'){//一直判断直到到达终点
        //输出迷宫
		for(int i=0;i<12;i++){
			for(int j=0;j<12;j++){
				if(i==x&&j==y)	cout<<"i";
				else	cout<<maze[i][j];
			}
			cout<<endl;
		}
        //判断按键
		keys=getch();
		switch(keys){
			case 72:
				if(maze[x-1][y]!='#')
					x-=1;
				break;
			case 80:
				if(maze[x+1][y]!='#')
					x+=1;
				break;
			case 75:
				if(maze[x][y-1]!='#')
					y-=1;
				break;
			case 77:
				if(maze[x][y+1]!='#')
					y+=1;
				break;
			default:
		}
		system("cls");
	}
	MessageBox(0,
	"恭喜挑战成功!",
	"提示",
	MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
	return 0;
}

有点low的迷宫,将就着用一下吧!

即将出品:迷宫小游戏(V2.0)

显示全文