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
|
#include <iostream>
#include <string.h>
using namespace std;
class Entity {
public:
char interpretation = 0;
bool walkable = true;
};
class Empty: public Entity {
public:
char interpretation = 'w';
bool walkable = true;
};
class KaraWorld {
void _preset(size_t, size_t);
size_t _rows{};
size_t _columns{};
Entity **_map = (Entity **) new Entity*[_rows];
public:
KaraWorld(): _map{(Entity **) new Entity*[10]}, _rows{10}, _columns{10} { _preset(10, 10); };
KaraWorld(size_t row_s, size_t column_s): _map{(Entity **) new Entity*[row_s]}, _rows{row_s}, _columns{column_s} { _preset(row_s, column_s); }
KaraWorld(size_t row_s): _map{(Entity **) new Entity*[row_s]}, _rows{row_s}, _columns{row_s} { _preset(row_s, row_s); }
KaraWorld(const KaraWorld& cp): _map{cp._map}, _columns{cp._columns}, _rows{cp._rows} {}
KaraWorld(KaraWorld&& other) {std::swap(_map, other._map); std::swap(_rows, other._rows); std::swap(_columns, other._columns);}
~KaraWorld() {for (size_t i = 0; i < _rows; i++) {delete[] _map[i];} delete[] _map;}
const size_t rows() const {return _rows;}
const size_t columns() const {return _columns;}
Entity **map() {return _map; }
};
void KaraWorld::_preset(size_t r, size_t c) {
for (size_t i = 0; i < r; i++) {
_map[i] = new Empty[c]{};
}
}
ostream& operator<<(ostream& os, KaraWorld& k) {
for (size_t m = 0; m < k.columns() * 2 + 1; m++)
os << "_";
os << "\n";
for (size_t i = 0; i < k.rows(); i++) {
for (size_t j = 0; j < k.columns(); j++) {
os << "|";
os << k.map()[i][j].interpretation << ((j + 1) == k.columns() ? "|\n":"");
}
}
for (size_t m = 0; m < k.columns() * 2 + 1; m++)
os << "_";
os << "\n";
return os;
}
| |