blob: f240542c3ce955f7423e2b6d26a47fb201db00d9 (
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
|
#include <cstdio>
#include "Tile.h"
#include "TileColorFactory.h"
#include "TileBehaviorFactory.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;
Canvas & canvas = this->museum.canvas;
this->color = canvas.tile_color.get_color(this->data.type);
this->behavior = canvas.tile_behavior.create(this->data.type);
}
void Tile::update() {
this->behavior->update(*this);
}
Tile * Tile::get_neighbor(const XY & offset) {
XY here {
.x = static_cast<int>(this->data.x),
.y = static_cast<int>(this->data.y),
};
try {
return &this->museum.canvas.get_tile(here + offset);
} catch (...) {
return nullptr;
}
}
|