From 32dc354e60459b50f68718143209dd0125833ba9 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Sat, 26 Nov 2011 19:41:03 +0100 Subject: [PATCH] Create an agent --- Makefile | 4 ++-- agent.cc | 16 ++++++++++++++++ agent.h | 7 +++++++ main.cc | 4 ++++ 4 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 agent.cc diff --git a/Makefile b/Makefile index 11b5055..e5e7b19 100644 --- a/Makefile +++ b/Makefile @@ -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 $@ $^ diff --git a/agent.cc b/agent.cc new file mode 100644 index 0000000..f0a944e --- /dev/null +++ b/agent.cc @@ -0,0 +1,16 @@ +#include +#include +#include + +#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); + } +} diff --git a/agent.h b/agent.h index 4a2cf52..4e5b8fc 100644 --- a/agent.h +++ b/agent.h @@ -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 diff --git a/main.cc b/main.cc index 8c72cf3..5dc4b32 100644 --- a/main.cc +++ b/main.cc @@ -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; }