-
Notifications
You must be signed in to change notification settings - Fork 0
/
primmaze.h
63 lines (58 loc) · 1.5 KB
/
primmaze.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#ifndef PRIMMAZE_H
#define PRIMMAZE_H
#include <iostream>
#include <vector>
#include <queue>
#include <time.h>
#include <string.h>
using namespace std;
struct point
{
int x;
int y;
int dir = 0;
point* parent = NULL;//上一步的坐标
};
class pointNode
{
public:
pointNode();
pointNode(int x, int y) : x(x), y(y) {}
int getX() { return x; }
int getY() { return y; }
private:
int x;
int y;
};
class PrimMaze
{
public:
PrimMaze(int sideLength);
~PrimMaze();
void printmap();
void createwall();
void createmaze();
void setStart(int x, int y);
void calculationEnd();
bool canGo(int x, int y);
void BFScalculation();
void print();
int** returnmaze() { return maze; }
int** returnpathmaze() {return pathmap;}
point *bfspathnode;
point* returnpathnode() {return bfspathnode;}
int returnmazelength(){return mazeLength;}
int returnendX() {return endX;}
int returnendY() {return endY;}
private:
int sideLength, mazeLength, startX, startY, endX, endY;
int** map = NULL; //生成指针的指针数组
int** maze = NULL, ** pathmap = NULL;
point* p, * newnode, * start;
int dx[4] = { 1, 0, -1, 0 };
int dy[4] = { 0, 1, 0, -1 };
int dir[4] = { 1, 2, 3, 4 };//1右,2下,3左,4上
vector<pointNode> pathvector;
queue<point*>shortqueue;
};
#endif // PRIMMAZE_H