-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze.cpp
More file actions
77 lines (67 loc) · 1.34 KB
/
Maze.cpp
File metadata and controls
77 lines (67 loc) · 1.34 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include "Maze.h"
#include "Cell.h"
Maze::Maze(){
initWalls();
initCells();
floodFill();
}
void Maze::initCells(){
// for(int i = 0; i < 8; i++){
// for(int j = 0; j < 8; j++){
// cells[i][j] = new Cell(i,j);
// }
// }
// cells[8/2][8/2].setDistance(0);
// cells[8/2 - 1][8/2].setDistance(0);
// cells[8/2][8/2 - 1].setDistance(0);
// cells[8/2 - 1][8/2 - 1].setDistance(0);
}
void Maze::initWalls(){
for(int i=0; i < 9; i++){
for(int j = 0 ; j < 9; j++){
wallsH[i][j] = false; //maze has no walls, if see wall set to true
wallsV[i][j] = false;
}
}
}
void Maze::floodFill(){
int counter = 0;
int ocounter = 8-2;
for(int i = 0; i < 8; i++){
counter = ocounter;
for(int j = 0; j < 8; j++){
cells[i][j].setDistance(counter);
if(j < (8/2)-1){
counter--;
}
else if(j == (8/2)-1){
}
else{
counter++;
}
}
if(i < (8/2)-1){
ocounter--;
}
else if(i == (8/2)-1){
}
else{
ocounter++;
}
}
}
void Maze::setWallNorth(int x, int y){
wallsH[y+1][x] = true;
}
void Maze::setWallSouth(int x, int y){
wallsH[y][x] = true;
}
void Maze::setWallEast(int x, int y){
wallsH[y][x+1] = true;
}
void Maze::setWallWest(int x, int y){
wallsH[y][x] = true;
}
Cell Maze::getCell(int x, int y){
return cells[x][y];
}