-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLiftMap.cpp
More file actions
41 lines (36 loc) · 1.08 KB
/
LiftMap.cpp
File metadata and controls
41 lines (36 loc) · 1.08 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
#include "LiftMap.h"
LiftMap::LiftMap(int width, int height) : width(width), height(height) {
map = new LiftNode**[height];
for (int i = 0; i < height; ++i) {
map[i] = new LiftNode*[width];
for (int j = 0; j < width; ++j) {
map[i][j] = nullptr;
}
}
}
LiftMap::~LiftMap() {
for (int i = 0; i < height; ++i) {
for (int j = 0; j < width; ++j) {
LiftNode* current = map[i][j];
while (current) {
LiftNode* toDelete = current;
current = current->next;
delete toDelete;
}
}
delete[] map[i];
}
delete[] map;
}
void LiftMap::addLift(const Lift& lift) {
if (lift.startX >= 0 && lift.startX < width && lift.startY >= 0 && lift.startY < height) {
LiftNode* newNode = new LiftNode{lift, map[lift.startY][lift.startX]};
map[lift.startY][lift.startX] = newNode;
}
}
LiftNode* LiftMap::getLiftsAt(int x, int y) const {
if (x >= 0 && x < width && y >= 0 && y < height) {
return map[y][x];
}
return nullptr;
}