-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMap.cpp
More file actions
51 lines (43 loc) · 976 Bytes
/
Copy pathMap.cpp
File metadata and controls
51 lines (43 loc) · 976 Bytes
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
#include <stdexcept>
#include "Map.hh"
Map::Map(const std::string map, const int sizeX, const int sizeY)
: _name("Map")
{
initialize(map, sizeX, sizeY);
}
Map::~Map()
{
}
std::string const &Map::getName() const
{
return (this->_name);
}
void Map::update(Subject *sub)
{
GameElement *elem = dynamic_cast<GameElement *>(sub);
std::cerr << this->_name << ": update()" << std::endl;
if (_map[elem->getPosy() * _sizeX + elem->getPosx()] == '#') {
std::cerr << elem->getName() <<": is inside a wall !" << std::endl;
throw std::logic_error("Invalid position");
}
}
void Map::initialize(const std::string map, const int sizeX, const int sizeY) {
_map = std::string(map);
_sizeX = sizeX;
_sizeY = sizeY;
}
/*
* GETTERS
*/
const std::string Map::getMap() const {
return (_map);
}
char Map::getCell(int x, int y) const {
return (_map[y * _sizeX + x]);
}
int Map::getWidth() const {
return (_sizeX);
}
int Map::getHeight() const {
return (_sizeY);
}