c++迷宫小游戏

关于我的姐姐的小游戏

代码如下:

#include<bits/stdc++.h>
#include<windows.h>
#include"conio.h" 
using namespace std;
int main()
{
	int a[10][20]{
		{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
		{2,0,2,9,2,1,2,2,1,2,1,1,1,2,1,1,1,6,1,2},
		{2,1,1,1,1,1,2,1,2,1,1,1,1,2,1,2,1,2,1,2},
		{2,1,2,1,2,2,2,1,1,2,1,2,1,2,3,2,1,1,1,2},
		{2,1,2,1,1,1,2,1,1,1,1,1,1,2,1,2,2,1,1,2},
		{2,1,2,1,2,1,2,2,2,2,1,2,1,2,1,2,9,2,1,2},
		{2,1,2,1,2,1,1,1,1,1,1,2,1,2,1,2,1,1,1,2},
		{2,1,2,2,2,2,2,1,2,2,1,2,1,2,1,2,1,2,1,2},
		{2,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,2},
		{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2},
	},x=1,y=1,bu=0,t=0;
	char n;
	for(;;)
	{
		system("cls");
		cout<<"                   w"<<endl;
		cout<<"                  asd 控制'蛛'移动 '门'传送门 '墙'墙 '死'陷阱 '星'通关 你走了:"<<bu<<"步"<<endl<<endl;
		for(int i=0;i<=9;i++)
		{
			cout<<"                    ";
			for(int y=0;y<=19;y++)
			{
				if(a[i][y]==0)cout<<"蛛"; 
				else if(a[i][y]==2)cout<<"墙";
				else if(a[i][y]==6)cout<<"星";
				else if(a[i][y]==9)cout<<"门";
				else if(a[i][y]==3)cout<<"死";
				else cout<<"  ";
			}
			cout<<endl;
		}
		n=getch();
		bu++;
		if(n=='w')
		{
			if(y-1==1&&x==3)
			{
				a[y][x]=1;
				a[7][16]=0;
				y=7;
				x=16;
			}
			else if(y-1==5&&x==16)
			{
				a[y][x]=1;
				a[3][3]=0;
				y=3;
				x=3;
			}
			else if(y-1==3&&x==14)
			{
				break;
			}
			if(a[y-1][x]!=2&&a[y-1][x]!=6)
			{
				a[y-1][x]=0;
				a[y][x]=1;
				y--;
			}
		}
		if(n=='s')
		{
			if(y+1==3&&x==14)
			{
				break;
			}else if(a[y+1][x]!=2&&a[y+1][x]!=6)
			{
				a[y+1][x]=0;
				a[y][x]=1;
				y++;
			}
		}
		if(n=='a')
		{
			if(a[y][x-1]==6)
			{
				t=1;
				break;
			}
			else if(a[y][x-1]!=2&&a[y][x-1]!=6)
			{
				a[y][x-1]=0;
				a[y][x]=1;
				x--;
			}
		}
		if(n=='d')
		{
			if(a[y][x+1]!=2&&a[y][x+1]!=6)
			{
				a[y][x+1]=0;
				a[y][x]=1;
				x++;
			}
		}
	} 
	system("cls");
	if(t==0)
	{
		system("color 4");
		cout<<"                              你死了"<<endl;
		Sleep(1000);
		cout<<"你总共走了"<<bu<<"歩"<<endl;	 
		Sleep(1000);
		cout<<"感谢您的游玩"; 
		Sleep(1000);
		return 0;
	}
	
} 

第一个游戏作品

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值