没有合适的资源?快使用搜索试试~ 我知道了~
C++自动生成迷宫游戏
10 下载量 37 浏览量
2020-08-19
11:48:12
上传
评论 2
收藏 45KB PDF 举报
温馨提示
试读
3页
主要为大家详细介绍了C++自动生成迷宫游戏,运用并查集自动生成迷宫地图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
资源推荐
资源详情
资源评论
C++自动生成迷宫游戏自动生成迷宫游戏
主要为大家详细介绍了C++自动生成迷宫游戏,运用并查集自动生成迷宫地图,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴
们可以参考一下
本文实例为大家分享了C++实现迷宫游戏的具体代码,供大家参考,具体内容如下
运用并查集自动生成迷宫地图,并运用队列和栈寻找迷宫通路并打印出来
#include<stdlib.h>
#include<iostream>
#include<time.h>
#include<queue>
#include<stack>
using namespace std;
using std::queue;
using std::stack;
typedef struct Point
{
int x;
int y;
int d;//方向 若方向为-1,则表示起点
}Point;
queue<Point> mqueue;
stack<Point> mstack;
Point pos, pos1;
int m, n;//迷宫行(tm-1)/2和列(tn-1)/2
int tm, tn;//实际作图
int x, y, tx1, tx2, ty1, ty2;//点坐标
int d;
int s[10000000];
int maze[1000][1000], mark[1000][1000];//最大迷宫
int sign[4][2] = { { -1,0 },{ 1,0 },{ 0,-1 },{ 0,1 } };//上下左右四个方向 0上 1下 2上 3下
Point start;
int Find_x(int x);
void unionSets(int node1, int node2);
void Init();
int getAdd(int x, int y);
void foundpath();
void fixmaze();
int connected(int node1, int node2);
void Findpath();
void changemaze();
int main()
{
Init();
cout << "请输入迷宫规模2x-1,2y-1:(x y)" << endl;
cin >> m >> n;
tm = m * 2 + 1;
tn = n * 2 + 1;
start.x = 1;
start.y = 1;
start.d = -1;
mqueue.push(start);
for (int i = 0; i < tm; i++)
{
for (int j = 0; j < tn; j++)
{
maze[i][j] = 1;
mark[i][j] = 0;
}
}
for (int i = 1; i < tm - 1; i += 2)
{
for (int j = 1; j < tn - 1; j += 2)
maze[i][j] = 0;
}
srand(time(NULL));
foundpath();
fixmaze();
cout << "迷宫全图:" << endl;
for (int i = 0; i < tm; i++)
{
for (int j = 0; j < tn; j++)
{
if (maze[i][j] == 1)
cout << "▇";
else if (maze[i][j] == 0) cout << "□";
}
cout << endl;
}
Findpath();
changemaze();
cout << "找到的通路:“..”表示:" << endl;
for (int i = 0; i < tm; i++)
{
for (int j = 0; j < tn; j++)
{
if (maze[i][j] == 1)
cout << "▇";
else if (maze[i][j] == 0) cout << "□";
else if (maze[i][j] == -1) cout << "..";
}
cout << endl;
}
system("pause");
return 0;
}
int connected(int node1, int node2)
{
return Find_x(node1) == Find_x(node2);
}
int Find_x(int x)
{
if (s[x] < 0)
return x;
资源评论
weixin_38506182
- 粉丝: 3
- 资源: 942
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 基于c++的个人收支管理系统设计
- docker一键安装包
- Screenshot_20240430_144340_com.ss.android.ugc.live.jpg
- 回到山沟沟.mp3
- 基于matlab实现自适应波束形成RLS及LMS算法仿真源程序1.rar
- 基于matlab实现自己编写的基于卡尔曼滤波的利用加速度传感器的计步器,测试数据是传感器放在腰部和手臂 .rar
- 基于matlab实现阵列信号处理,波束形成.rar
- 111111111111111111
- 基于matlab实现计步器编程;对当前的计步器装置的数值算法模拟 .rar
- Mdb学习查看PW;access;mdb;pw;password;patch
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功