mirror of
https://github.com/brmlab/brmlife.git
synced 2025-08-02 18:03:37 +02:00
brmlife: Initial version
Can draw 10x10 field of dots.
This commit is contained in:
commit
ce6f46ef1c
5 changed files with 163 additions and 0 deletions
49
map.cc
Normal file
49
map.cc
Normal file
|
@ -0,0 +1,49 @@
|
|||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#include "map.h"
|
||||
|
||||
void
|
||||
tile::on_agent_enter(class agent *a)
|
||||
{
|
||||
agent = a;
|
||||
}
|
||||
|
||||
void
|
||||
tile::on_agent_leave(class agent *a)
|
||||
{
|
||||
assert(a == agent);
|
||||
agent = NULL;
|
||||
}
|
||||
|
||||
void
|
||||
tile::on_tick(void)
|
||||
{
|
||||
}
|
||||
|
||||
char
|
||||
tile_ground::symbol(void)
|
||||
{
|
||||
return '.';
|
||||
}
|
||||
|
||||
class position *
|
||||
position::next_in(int dir_x, int dir_y)
|
||||
{
|
||||
int x2 = (map->w + x + dir_x) % map->w;
|
||||
int y2 = (map->h + y + dir_y) % map->h;
|
||||
return new position(x2, y2, map);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
map::print_map(void)
|
||||
{
|
||||
for (int y = 0; y < h; y++) {
|
||||
for (int x = 0; x < w; x++) {
|
||||
class position p = position(x, y, this);
|
||||
std::cout << tile_at(p).symbol();
|
||||
}
|
||||
std::cout << '\n';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue