栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > C/C++/C#

简单的迷宫(c++)

C/C++/C# 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

简单的迷宫(c++)

本人自制的小游戏

废话不多说,直接上代码

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
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<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 分别指上 下 左 右

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

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/983360.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号