自定义迷宫类以及相关结构体,直接上代码,有空我会把布线问题也更新一下
下面展示一些 maze.h
。
// An highlighted block
#include<iostream>
#include<time.h>
#include<stack>
#include<windows.h>
using namespace std;
class maze
{
public:
maze():Maze(nullptr), size(0),isinit(false){
};
void ramdonint(int=10);
void showmaze() const;
int getSize() const{
return size; };
int* operator[](int row){
return Maze[row]; };
//虽然三五法则,但是这里好像真的不需要拷贝构造和等号重载?
~maze();
private:
int size;
int** Maze;
bool isinit;
};
struct position
{
int row;
int col;
position(int Col=0, int Row=0) :row(Row), col(Col){
};
void operator=(position& p){
row = p.row; col = p.row; };
};
下面展示一些 maze.cpp
。
// An highlighted block
#include"maze.h"
void maze::ramdonint(int Size)
{
size = Size;
srand((int)time(NULL));
if (!isinit)
{
Maze = new int*[Size + 2]{
};
for (int i = 0; i <= Size + 1; i++)
{
Maze[i] = new int[Size + 2]{
};
if (i == 0 || i == size + 1){
continue; }//第一行行为空