diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 21:33:27 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-11-01 21:33:27 +0100 |
commit | af76b9a0ae58dc8c87548053a5bc310ad6be25ce (patch) | |
tree | b2aa5927ed19855c101120593b59a9c3224804ad /frontend/GameData.cpp | |
parent | bdf6ac149ec260dab767663419731b302679f458 (diff) |
more small tweaks
Diffstat (limited to 'frontend/GameData.cpp')
-rw-r--r-- | frontend/GameData.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp index ee05d4b..a716a57 100644 --- a/frontend/GameData.cpp +++ b/frontend/GameData.cpp @@ -17,12 +17,8 @@ GameData & GameData::get_instance() { return instance; } -GameData::GameData() { - this->db = make_unique<DB>("kerkersendraken.db"); -} - Enemy * GameData::create_enemy(const string & name) const { - static DBStatement query = this->db->prepare(R"( + static DBStatement query = this->db.prepare(R"( select naam, omschrijving, @@ -46,8 +42,7 @@ Enemy * GameData::create_enemy(const string & name) const { // TODO: min/max objects(?) enemy->set_health(row.col<int>(4)); enemy->set_attack(static_cast<float>(row.col<int>(5)) / 100); - enemy->set_damage_min(row.col<int>(6)); - enemy->set_damage_max(row.col<int>(7)); + enemy->set_damage({ row.col<int>(6), row.col<int>(7) }); return enemy.release(); } catch (...) { return EnemyFactory::create_enemy(name.c_str()); @@ -64,7 +59,7 @@ static const unordered_map<string, ObjectType> type_map = { }; Object * GameData::create_object(const string & name) const { - static DBStatement query = this->db->prepare(R"( + static DBStatement query = this->db.prepare(R"( select type, omschrijving, @@ -97,7 +92,7 @@ Object * GameData::create_object(const string & name) const { } Location * GameData::create_location(const string & name) const{ - static DBStatement query = this->db->prepare(R"( + static DBStatement query = this->db.prepare(R"( select naam, beschrijving @@ -117,8 +112,8 @@ Location * GameData::create_location(const string & name) const{ } } -void GameData::leaderbord_add(const string & name, unsigned int gold) const { - static DBStatement stmt = this->db->prepare(R"( +void GameData::leaderbord_add(const string & name, unsigned int gold) { + static DBStatement stmt = this->db.prepare(R"( insert into Leaderboard (naam, goudstukken) values (?, ?) )"); @@ -130,7 +125,7 @@ void GameData::leaderbord_add(const string & name, unsigned int gold) const { } void GameData::leaderbord_print() const { - static DBStatement query = this->db->prepare(R"( + static DBStatement query = this->db.prepare(R"( select naam, goudstukken from Leaderboard order by goudstukken desc @@ -147,14 +142,15 @@ void GameData::leaderbord_print() const { } } -vector<string> GameData::random_locations(unsigned count) { - static DBStatement query = this->db->prepare(R"( +vector<string> GameData::random_names(const string & table, unsigned count) const { + static DBStatement query = this->db.prepare(R"( select naam - from Locaties + from ? order by random() limit ? )"); query.reset() + .bind(table.c_str()) .bind(count) ; @@ -165,3 +161,15 @@ vector<string> GameData::random_locations(unsigned count) { return names; } +vector<string> GameData::random_locations(unsigned count) const { + return this->random_names("Locaties", count); +} + +vector<string> GameData::random_objects(unsigned count) const { + return this->random_names("Objecten", count); +} + +vector<string> GameData::random_enemies(unsigned count) const { + return this->random_names("Vijanden", count); +} + |