diff options
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index 0cf6a1d..b036695 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -1,4 +1,5 @@ #include <memory> +#include <unordered_map> #include "backend/Enemy.h" #include "backend/EnemyFactory.h" @@ -23,13 +24,28 @@ Enemy * GameData::create_enemy(const string & name) { return enemy; } +static const unordered_map<string, ObjectType> type_map = { + { "teleportatiedrank", ObjectType::CONSUMABLE }, + { "ervaringsdrank", ObjectType::CONSUMABLE }, + { "levenselixer", ObjectType::CONSUMABLE }, + { "wapenrusting", ObjectType::ARMOR }, + { "wapen", ObjectType::WEAPON }, + { "goudstukken", ObjectType::GOLD }, +}; + Object * GameData::create_object(const string & name) { - DBStatement query = this->db->prepare("select type from Objecten where naam = ?"); + DBStatement query = this->db->prepare("select type, omschrijving from Objecten where naam = ?"); query.bind(name); - // TODO: uhhhhhhhhh data ophalen - - Object * object = ObjectFactory::create_object(); - return object; + + try { + auto row = query.row(); + string type = row.col<const char *>(0); + const char * description = row.col<const char *>(1); + if (!type_map.contains(type)) throw std::exception(); + return ObjectFactory::create_object(type_map.at(type), name.c_str(), description); + } catch (...) { + return ObjectFactory::create_object(name.c_str()); + } } void GameData::leaderbord_add(const string & name, unsigned int gold) { |