-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaze.cpp
More file actions
120 lines (113 loc) · 2 KB
/
Copy pathmaze.cpp
File metadata and controls
120 lines (113 loc) · 2 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// David Rozmajzl dmr121@zips.uakron.edu
#include "maze.h"
#include <iostream>
using std::cout;
using std::endl;
maze::maze(int r, int c)
{
row = r;
col = c;
// Creating the first cell
theMaze.push_back(mazeCell(false, true, false, true));
// Creating all the in between cells
for (int i = 1; i < (r * c) - 1; ++i)
{
theMaze.push_back(mazeCell());
}
// Creating the last cell
theMaze.push_back(mazeCell(true, false, true, false));
}
bool maze::neighbors(int cell, int neigh) const
{
if (cell == neigh + 1 && 0 != cell % col)
{
return true;
}
else if (cell == neigh - 1 && (col - 1) != cell % col)
{
return true;
}
else if (col == cell - neigh || col == neigh - cell)
{
return true;
}
else
{
return false;
}
}
void maze::smashWall(int cell, int neigh)
{
if (cell == neigh + 1 && 0 != cell % col)
{
theMaze[cell].setLeft(false);
theMaze[neigh].setRight(false);
}
else if (cell == neigh - 1 && (col - 1) != cell % col)
{
theMaze[neigh].setLeft(false);
theMaze[cell].setRight(false);
}
else if (col == cell - neigh)
{
theMaze[cell].setTop(false);
theMaze[neigh].setBot(false);
}
else if (col == neigh - cell)
{
theMaze[cell].setBot(false);
theMaze[neigh].setTop(false);
}
}
void maze::printMaze()
{
// Print top row of lines
cout << " ";
for (int i = 1; i < col; ++i)
{
cout << " _";
}
cout << endl;
// Handle the printing of the first cell
if (theMaze[0].getBot() == 1)
{
cout << " _";
}
else
{
cout << " ";
}
// Printing the middle cells
for (int i = 1; i < theMaze.size() - 1; ++i)
{
if (i % col == 0)
{
cout << "|";
cout << endl;
}
if (theMaze[i].getLeft() == 1)
{
cout << "|";
}
else
{
cout << " ";
}
if (theMaze[i].getBot() == 1)
{
cout << "_";
}
else
{
cout << " ";
}
}
if (theMaze[theMaze.size() - 1].getLeft() == 1)
{
cout << "|";
}
else
{
cout << " ";
}
}