aboutsummaryrefslogtreecommitdiff
path: root/frontend/GameData.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 14:07:01 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-10-30 14:07:01 +0100
commit862186ae7cbbd922057fa5f6b49509c36f9ade36 (patch)
tree10193494e1c4bdff793a2daafc2b3359e8794303 /frontend/GameData.cpp
parentb1d5d7936bed17a684daff15b0294ef70754e8b9 (diff)
generate dungeon kinda works
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r--frontend/GameData.cpp41
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;
+}
+