C++实现迷宫小游戏的方法 | 您所在的位置:网站首页 › 迷宫编程游戏 › C++实现迷宫小游戏的方法 |
C++实现迷宫小游戏的方法
发布时间:2021-04-14 10:51:48
来源:亿速云
阅读:585
作者:小新
栏目:编程语言
这篇文章将为大家详细讲解有关C++实现迷宫小游戏的方法,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 介绍 本程序是根据广度优先遍历算法的思想设计的一款迷宫游戏,游戏设计了两种模式一种自动游戏模式,一种手动模式。因为项目在 Linux 开发,需要在 Windows 开发的,请查看源代码中需要修改地方的备注。 截图 代码 #include #include //标准库 #include //延时函数 #include //getchar #include #include //终端设置 #define MAX_X 20 #define MAX_Y 30 bool flag = false; bool slow = false; bool autogame = true; using namespace std; int maze[MAX_X][MAX_Y]; //迷宫 //路线栈 class stack_of_maze{ private: //记录迷宫坐标 struct node { int x; int y; char direction; //上一步路径(如何来的) node* next; }; node* head; public: stack_of_maze(){ head = NULL; } ~stack_of_maze(){ node* p = head; while(head!=NULL){ head = head->next; delete p; p = head; } } //压栈 void push(int xx,int yy,char ddirection){ node* new_node = new node; if(new_node!=NULL){ new_node->x = xx; new_node->y = yy; new_node->direction = ddirection; new_node->next = NULL; if(head==NULL) head = new_node; else{ new_node->next = head; head = new_node; } } else cout |
CopyRight 2018-2019 实验室设备网 版权所有 |