-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMaze.cpp
More file actions
113 lines (99 loc) · 2.53 KB
/
Copy pathMaze.cpp
File metadata and controls
113 lines (99 loc) · 2.53 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
#include "Maze.h"
#include "Obstacle.h"
#include "Person.h"
//If map height and width are greater than zero, allocates memory for 2D map
//else, returns dimensionless map
Maze::Maze(int height,int width, int astartY, int astartX) {
if (height >0 && width>0 && astartY > 0 && astartX >0) {
mapHeight=height;
mapWidth=width;
startX = astartX;
startY = astartY;
dynMap = new Obstacle**[mapHeight];
for (int i = 0; i < mapHeight; ++i)
{
dynMap[i] = new Obstacle*[mapWidth];
}
} else {
mapHeight=0;
mapWidth=0;
}
}
//sets the maze to the inputted map
bool Maze::setMap(Obstacle*** aDynMap) {
if (mapHeight >0 && mapWidth>0) {
int row, column;
for (row=0; row < mapHeight; row++ ){
for (column=0; column < mapWidth ;column++) {
dynMap[row][column] = aDynMap[row][column];
}
}
return 1;
} else {
return 0;
}
}
//draws the map using curses
bool Maze::drawMap(Person* person){
if (mapHeight < 1 || mapWidth < 1)
{
return 0;
}
int row,column;
for (row = 0; row < mapHeight; row++ ){
for (column = 0; column < mapWidth; column++) {
mvaddch(row, column, dynMap[row][column]->getSprite());
}
}
mvprintw(mapHeight+1,0,"Reach the end zone (X) to complete the game");
mvprintw(mapHeight+2,0,"Press q to quit game");
mvprintw(mapHeight+3,0,"Username: ");
mvprintw(mapHeight+3,10,person->getName().c_str());
return 1;
}
Obstacle*** Maze::getMap() {
return dynMap;
}
int Maze::getMapHeight() {
return mapHeight;
}
int Maze::getMapWidth() {
return mapWidth;
}
//returns the obstacle next to a person object in the direction of keyPress
Obstacle* Maze::getNextObstacle(Person* person, int keyPress) {
switch (keyPress) {
case KEY_UP :
return dynMap[person->getyPos()-1][person->getxPos()];
break;
case KEY_DOWN :
return dynMap[person->getyPos()+1][person->getxPos()];
break;
case KEY_LEFT :
return dynMap[person->getyPos()][person->getxPos()-1];
break;
case KEY_RIGHT :
return dynMap[person->getyPos()][person->getxPos()+1];
break;
default:
return NULL;
}
}
Obstacle* Maze::getCurrentObstacle(Person* person) {
return dynMap[person->getyPos()][person->getxPos()];
}
int Maze::getStartY() {
return startY;
}
int Maze::getStartX() {
return startX;
}
Maze::~Maze() {
if (mapHeight > 0 ) {
for (int i = 0; i < mapHeight; ++i)
{
delete[] dynMap[i];
}
delete[] dynMap;
}
}