diff options
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index c8f47e3..edcd854 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -3,6 +3,7 @@ #include "backend/Enemy.h" #include "backend/EnemyFactory.h" +#include "backend/LocationFactory.h" #include "backend/Object.h" #include "backend/ObjectFactory.h" @@ -21,6 +22,7 @@ GameData::GameData() { Enemy * GameData::create_enemy(const string & name) { Enemy * enemy = EnemyFactory::create_enemy(); + // TODO: fill fields return enemy; } @@ -66,6 +68,27 @@ Object * GameData::create_object(const string & name) { } } +Location * GameData::create_location(const string & name) { + static DBStatement query = this->db->prepare(R"( + select + naam, + beschrijving + from Locaties + where lower(naam) = lower(?) + limit 1 + )"); + query.reset() + .bind(name) + ; + + try { + auto row = query.row(); + return LocationFactory::create_location(row.col<const char *>(0), row.col<const char *>(1)); + } catch (...) { + return LocationFactory::create_location(name.c_str(), ""); + } +} + void GameData::leaderbord_add(const string & name, unsigned int gold) { static DBStatement stmt = this->db->prepare(R"( insert into Leaderboard (naam, goudstukken) @@ -78,3 +101,21 @@ void GameData::leaderbord_add(const string & name, unsigned int gold) { stmt.execute(); } +vector<string> GameData::random_locations(unsigned count) { + static DBStatement query = this->db->prepare(R"( + select naam + from Locaties + order by random() + limit ? + )"); + query.reset() + .bind(count) + ; + + vector<string> names = {}; + for (DBQueryRow & row : query.rows()) { + names.push_back(row.col<const char *>(0)); + } + return names; +} + |