Create an agent

This commit is contained in:
Petr Baudis 2011-11-26 19:41:03 +01:00
parent a131964cc0
commit 32dc354e60
4 changed files with 29 additions and 2 deletions

View file

@ -1,8 +1,8 @@
CFLAGS=-Wall -O3 -g
OBJS=main.o map.o
OBJS=main.o map.o agent.o
brmlife: main.o map.o
brmlife: main.o map.o agent.o
$(CXX) -o $@ $^

16
agent.cc Normal file
View file

@ -0,0 +1,16 @@
#include <cassert>
#include <cstdlib>
#include <iostream>
#include "agent.h"
#include "map.h"
void
agent::put_at(struct position *pos)
{
class tile *t = &pos->map->tile_at(*pos);
if (!t->on_agent_enter(this)) {
std::cerr << "Collision.";
exit(EXIT_FAILURE);
}
}

View file

@ -7,6 +7,13 @@ class agent {
public:
int id;
class position *pos;
agent(int id_, class position &pos_) : id (id_), pos (&pos_)
{
put_at(pos);
};
void put_at(struct position *pos);
};
#endif

View file

@ -7,6 +7,10 @@ int
main(int argc, char *argv[])
{
class map map(10, 10);
class position agentpos(4, 4, map);
class agent agent(0, agentpos);
map.print_map();
return 0;
}