aboutsummaryrefslogtreecommitdiff
path: root/Tile.cpp
blob: a891f155ba7a8ade4830685f5c9b2857a3a503ac (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#include <cstdio>

#include "Tile.h"
#include "TileAppearance.h"
#include "TileBehavior.h"
#include "Museum.h"

using namespace std;

Tile::Tile(Museum & museum, TileData & data) : museum(museum) {
	this->set_data(data);
}

void Tile::set_type(const string & type) {
	this->data.type = type;
	this->set_data(this->data);
}

void Tile::set_data(TileData & data) {
	this->data = data;
	this->color = TileAppearance::get_color(this->data.type);
	this->behavior = TileBehavior::get_strategy(this->data.type).clone(this->museum);
}

void Tile::update() {
	this->behavior->update(*this);
}

void Tile::step(Artist * artist) {
	this->behavior->step(artist);
}

Tile * Tile::get_neighbor(int dx, int dy) {
	Canvas & canvas = this->museum.canvas;
	int x = this->data.x + dx;
	int y = this->data.y + dy;
	if (x < 0) return nullptr;
	if (x >= canvas.data.columns) return nullptr;
	if (y < 0) return nullptr;
	if (y >= canvas.data.columns) return nullptr;
	return &canvas.get_tile(x, y);
}