简单的迷宫(c++)

本人自制的小游戏

废话不多说,直接上代码

#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <windows.h>
#include <conio.h>
#include <fstream>
#include <ctime>
#include <time.h>
#include <stdio.h>
using namespace std;
char a[20][20]={
	"##################",
	"    #### #   ### #",
	"###    ##  ##### #",
	"## ## #### ##    #",
	"#####   ## ### ###",
	"#  #### #     # ##",
	"                  ",
	" ## #  ##   ######",
	" ##  # ## # #    #",
	" ###  # ####   # #",
	"# ### #  ### ##o #",
	"###   ##  #  ### #",
	"##### #### #   ###",
	"##     # # ### ###",
	"## #   #######  ##",
	"# ####  # ##### ##",
	"# ## ## ## ###  ##",
	"#  #  #  #  #  ###",
	"## ##### ###  ####",
	"########     #####",
};
//地图
int main() {
    a[0][0]='*';
    int z=0,x=0;
    while(1) {//无限循环
        system("cls");//清屏
        for(int i=0; i<20; i++) {
            for(int j=0; j<20; j++) {
                cout<<a[i][j];
            }
            cout<<endl;
        }
//输出数组
        cout<<z<<' '<<x<<endl<<endl;
//坐标
        int b;
        b = _getch();
        if(b=='s') {
        	if(a[z+1][x]=='o'){
        		cout<<"YOU WIN!!!";
        		return 0;
			}
            if(z+1<0||z+1>19||a[z+1][x]=='#')continue;
            a[z+1][x]='*';
            a[z][x]=' ';
            z++;
//向下
        } else if(b=='w') {
        	if(a[z-1][x]=='o'){
        		cout<<"YOU WIN!!!";
        		return 0;
			}
            if(z-1<0||z-1>19||a[z-1][x]=='#')continue;
            a[z-1][x]='*';
            a[z][x]=' ';
            z--;
//向上
        } else if(b=='a') {
        	if(a[z][x-1]=='o'){
        		cout<<"YOU WIN!!!";
        		return 0;
			}
            if(x-1<0||x-1>19||a[z][x-1]=='#')continue;
            a[z][x-1]='*';
            a[z][x]=' ';
            x--;;
//向左
        } else if(b=='d') {
        	if(a[z][x+1]=='o'){
        		cout<<"YOU WIN!!!";
        		return 0;
			}
            if(x+1<0||x+1>19||a[z][x+1]=='#')continue;
            a[z][x+1]='*';
            a[z][x]=' ';
            x++;
        }
//向右
    }
    return 0;
}

w s a d 分别指上 下 左 右

(做的不好,大佬们多多指教)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值