aboutsummaryrefslogtreecommitdiff
path: root/TileBehaviorFactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'TileBehaviorFactory.cpp')
-rw-r--r--TileBehaviorFactory.cpp32
1 files changed, 21 insertions, 11 deletions
diff --git a/TileBehaviorFactory.cpp b/TileBehaviorFactory.cpp
index 99301ac..b795578 100644
--- a/TileBehaviorFactory.cpp
+++ b/TileBehaviorFactory.cpp
@@ -1,20 +1,30 @@
+#include <memory>
+
#include "TileBehaviorFactory.h"
-#include "Exception.h"
+#include "CreateArtistTileBehavior.h"
+#include "DeleteArtistTileBehavior.h"
+#include "NullTileBehavior.h"
+#include "SetNeighborTileBehavior.h"
+#include "StepTileBehavior.h"
using namespace std;
-TileBehavior & TileBehaviorFactory::get_strategy(string type) {
- auto & type_map = TileBehaviorFactory::get_collection();
+TileBehaviorFactory::TileBehaviorFactory(Museum & m) : museum(m) {};
- if (type_map.contains(type))
- return *type_map.at(type);
-
- throw Exception("unknown behavior for tile type \"%s\"", type.c_str());
-}
+unique_ptr<TileBehavior> TileBehaviorFactory::create(string type) {
+ TileBehavior * out = nullptr;
-void TileBehaviorFactory::register_strategy(string type, TileBehavior * strategy) {
- auto & type_map = TileBehaviorFactory::get_collection();
+ if (type == SetNeighborTileBehavior::type)
+ out = new SetNeighborTileBehavior(this->museum);
+ else if (type == CreateArtistTileBehavior::type)
+ out = new CreateArtistTileBehavior(this->museum);
+ else if (type == StepTileBehavior::type)
+ out = new StepTileBehavior(this->museum);
+ else if (type == DeleteArtistTileBehavior::type)
+ out = new DeleteArtistTileBehavior(this->museum);
- type_map[type] = strategy;
+ if (out == nullptr)
+ out = new NullTileBehavior(this->museum);
+ return unique_ptr<TileBehavior>(out);
}