您的当前位置:首页正文

迷宫小游戏(V2.0)

2024-11-27 来源:个人技术集锦

上一篇文章:迷宫小游戏(V1.0)

V2.0出版了!!!

#include<iostream>
#include<windows.h>
#include<conio.h>
#include<cstdlib>
using namespace std;
char maze[25][25]=
{
	"####################",
	"####################",
	"#####    #       ###",
	"##### #### ##### ###",
	"###        ##  # ###",
	"### # ######## # ###",
	"### #   #  ##  # ###",
	"### # #### #  ## ###",
	"### # #  # # ### ###",	
	"### ###### # # # ###",	
	"###      # # # # ###",	
	"### # ##   #     ###",	
	"##########$#########",	
	"####################"
},keys;
int x,y;
bool color_black=true;
int main(){
	system("title 迷宫");
	Sleep(750);
	x=11,y=12;
	MessageBox(0,
	"请按上、下、左、右键操控i小人!\n按c键切换深浅色主题!\n\n按ESC键退出游戏!",
	"提示",
	MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
	while(maze[x][y]!='$'){
		cout<<"    迷宫    "<<endl;
		cout<<"   ------   "<<endl;
		for(int i=x-2;i<x+2;i++){
			cout<<"   |";
			for(int j=y-2;j<y+2;j++){
				if(i==x&&j==y)	cout<<"i";
				else	cout<<maze[i][j];
			}
			cout<<"|   "<<endl;
		}
		cout<<"   ------   "<<endl<<endl;
		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;
			case 'c':
				if(color_black){
					color_black=false;
					system("color f0");
					MessageBox(0,
					"已切换为:浅色模式。",
					"提示",
					MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
				}
				else{
					color_black=true;
					system("color 07"); 
					MessageBox(0,
					"已切换为:深色模式。",
					"提示",
					MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
				}
				break; 
			case 27:
				MessageBox(0,
				"您已退出游戏。",
				"提示",
				MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
				return 0; 
			default:
				break; 
		}
		system("cls");
	}
	MessageBox(0,
	"恭喜挑战成功!",
	"提示",
	MB_ICONINFORMATION|MB_OK|MB_TOPMOST);
	return 0;
}

 V2.0增加了深浅色切换功能,以及esc键退出、只能看到迷宫的有限区域这些新功能!


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

内容预告:增加道具功能。 

显示全文