agent::move_dir(): Implement

This commit is contained in:
Petr Baudis 2011-11-26 20:40:22 +01:00
parent 56726a6c05
commit b305a41cfc
3 changed files with 24 additions and 0 deletions

View file

@ -13,3 +13,15 @@ agent::put_at(class tile &t)
exit(EXIT_FAILURE);
}
}
bool
agent::move_dir(int dir_x, int dir_y)
{
class tile *t2 = &tile->tile_in_dir(dir_x, dir_y);
if (!t2->on_agent_enter(*this))
return false;
tile->on_agent_leave(*this);
tile = t2;
return true;
}

View file

@ -13,6 +13,8 @@ public:
put_at(tile_);
};
bool move_dir(int dir_x, int dir_y);
private:
/* Just for initial placement. */
void put_at(class tile &tile);

10
main.cc
View file

@ -12,5 +12,15 @@ main(int argc, char *argv[])
class agent agent(0, agentpos);
map.print_map();
std::cout << '\n';
agent.move_dir(1, 0);
map.print_map();
std::cout << '\n';
agent.move_dir(0, -1);
map.print_map();
std::cout << '\n';
return 0;
}