aboutsummaryrefslogtreecommitdiff
path: root/BlueTileBehavior.cpp
blob: 487398af4b9bb115a81ffd72c5ac8756d04f6173 (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
#include <memory>

#include "BlueTileBehavior.h"
#include "YellowTileBehavior.h"
#include "Artist.h"
#include "Tile.h"

using namespace std;

BlueTileBehavior BlueTileBehavior::instance { BlueTileBehavior::type };

void BlueTileBehavior::step(Artist & artist) {
	this->interactions++;
	if (this->interactions > 1) return;

	if (artist.data.vx == 0) dx = 1;
	if (artist.data.vy == 0) dy = 1;
}

void BlueTileBehavior::update_neighbor(Tile * tile) {
	if (tile == nullptr) return;

	tile->set_type(BlueTileBehavior::type);
}

void BlueTileBehavior::update(Tile & tile) {
	if (this->interactions < 1) return;

	this->update_neighbor(tile.get_neighbor(this->dx, this->dy));
	this->update_neighbor(tile.get_neighbor(-this->dx, -this->dy));

	tile.set_type(YellowTileBehavior::type);
}

unique_ptr<TileBehaviorStrategy> BlueTileBehavior::clone(Museum & museum) {
	auto instance = new BlueTileBehavior();
	instance->museum = &museum;
	return unique_ptr<TileBehaviorStrategy>(instance);
}