c++简易迷宫

帖主用一点小基础做了一个小迷宫......其实都说不上是迷宫吧......反正,你可以用WASD键去控制“H”

废话不多说,上代码!

#include<iostream>
#include<conio.h>
#include<string> 
using namespace std;
int main(){
	char keybox;
	int x = 2;
	int y = 2;
	int no1_y = 2;
	int no1_x = 3;
	int no2_y = 3;
	int no2_x = 5;
	int no3_y = 4;
	int no3_x = 3;
	/*
	地图:
	******
	*H*--*
	*---**
	*-*--*
	******
	*/ 
	cout<<"******"<<endl;
	cout<<"*H*--*"<<endl;
	cout<<"*---**"<<endl;
	cout<<"*-*--*"<<endl;
	cout<<"******"<<endl;
	while(true){
		keybox = getch();
		if (keybox == 'a' || keybox == 'A') x --; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| x < 2?x++:x = x;
		if (keybox == 's' || keybox == 'S') y ++; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| y > 4?y--:y = y;
		if (keybox == 'd' || keybox == 'D') x ++; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| x > 5?x--:x = x;
		if (keybox == 'w' || keybox == 'W') y --; x == no1_x && y == no1_y || x == no2_x && y == no2_y|| x == no3_x && y == no3_y|| y < 2?y++:y = y;
		system("cls");
		cout<<"******"<<endl;
		if (x == 2 && y == 2){
			cout<<"*H*--*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 2 && y == 3){
			cout<<"*-*--*"<<endl;
			cout<<"*H--**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 2 && y == 4){
			cout<<"*-*--*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*H*--*"<<endl;
		}
		else if (x == 3 && y == 3){
			cout<<"*-*--*"<<endl;
			cout<<"*-H-**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 4 && y == 3){
			cout<<"*-*--*"<<endl;
			cout<<"*--H**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 4 && y == 2){
			cout<<"*-*H-*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 5 && y == 2){
			cout<<"*-*-H*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*-*--*"<<endl;
		}
		else if (x == 4 && y == 4){
			cout<<"*-*--*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*-*H-*"<<endl;
		}
		else if (x == 5 && y == 4){
			cout<<"*-*--*"<<endl;
			cout<<"*---**"<<endl;
			cout<<"*-*-H*"<<endl;
		}
		cout<<"******"<<endl;
		cout<<x<<','<<y; 
	}
} 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值