Get rid of class position

This commit is contained in:
Petr Baudis 2011-11-26 20:40:05 +01:00
parent f622f79283
commit 56726a6c05
5 changed files with 40 additions and 43 deletions

43
map.h
View file

@ -6,34 +6,29 @@ class map;
class tile {
public:
int x, y;
class map ↦
class agent *agent;
virtual bool on_agent_enter(class agent *);
virtual void on_agent_leave(class agent *);
virtual void on_tick(void);
tile(int x_, int y_, class map &map_) : x(x_), y(y_), map(map_), agent(NULL) {};
char symbol(void);
virtual char type_symbol(void) = 0;
class tile &tile_in_dir(int dir_x, int dir_y);
virtual bool on_agent_enter(class agent &);
virtual void on_agent_leave(class agent &);
virtual void on_tick(void);
};
class tile_ground : public tile {
char type_symbol(void);
};
class position {
public:
int x, y;
class map *map;
position(int x_, int y_, class map &map_)
{
x = x_;
y = y_;
map = &map_;
};
class position *next_in(int dir_x, int dir_y);
tile_ground(int x_, int y_, struct map &map_) : tile(x_, y_, map_) {};
private:
char type_symbol(void);
};
class map {
@ -47,14 +42,16 @@ public:
h = h_;
tiles = new class tile * [w * h];
for (int i = 0; i < w * h; i++) {
tiles[i] = new tile_ground;
for (int y = 0; y < h; y++) {
for (int x = 0; x < w; x++) {
tiles[y * h + x] = new tile_ground(x, y, *this);
}
}
};
class tile &tile_at(class position &pos)
class tile &tile_at(int x, int y)
{
return *tiles[pos.y * h + pos.x];
return *tiles[y * h + x];
};
void print_map(void);