aboutsummaryrefslogtreecommitdiff
path: root/frontend
diff options
context:
space:
mode:
Diffstat (limited to 'frontend')
-rw-r--r--frontend/GameData.cpp30
-rw-r--r--frontend/cmd/query.cpp14
-rw-r--r--frontend/cmd/search.cpp16
3 files changed, 53 insertions, 7 deletions
diff --git a/frontend/GameData.cpp b/frontend/GameData.cpp
index edcd854..739ad1e 100644
--- a/frontend/GameData.cpp
+++ b/frontend/GameData.cpp
@@ -21,9 +21,31 @@ GameData::GameData() {
}
Enemy * GameData::create_enemy(const string & name) {
- Enemy * enemy = EnemyFactory::create_enemy();
- // TODO: fill fields
- return enemy;
+ static DBStatement query = this->db->prepare(R"(
+ select
+ naam,
+ omschrijving,
+ minimumobjecten,
+ maximumobjecten,
+ levenspunten,
+ aanvalskans,
+ minimumschade,
+ maximumschade
+ from Vijanden
+ where lower(naam) = lower(?)
+ limit 1
+ )");
+ query.reset()
+ .bind(name)
+ ;
+
+ try {
+ auto row = query.row();
+ return EnemyFactory::create_enemy(row.col<const char *>(0), row.col<const char *>(1));
+ // TODO: set all other properties
+ } catch (...) {
+ return EnemyFactory::create_enemy(name.c_str());
+ }
}
static const unordered_map<string, ObjectType> type_map = {
@@ -85,7 +107,7 @@ Location * GameData::create_location(const string & name) {
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(), "");
+ return LocationFactory::create_location(name.c_str());
}
}
diff --git a/frontend/cmd/query.cpp b/frontend/cmd/query.cpp
index e1e45a1..23d2a42 100644
--- a/frontend/cmd/query.cpp
+++ b/frontend/cmd/query.cpp
@@ -1,5 +1,6 @@
#include "backend/Location.h"
#include "backend/Object.h"
+#include "backend/Enemy.h"
#include "../Player.h"
#include "../print.h"
@@ -43,7 +44,18 @@ FollowupAction Player::cmd_query(string &) {
lprtf("\n");
}
- // TODO: enemies
+ {
+ lprtf("Vijanden: ");
+ size_t enemies = 0;
+ for (Enemy * enemy : this->location.get_enemies()) {
+ if (enemies > 0) lprtf(", ");
+ lprtf("%s", enemy->get_name());
+ enemies++;
+ }
+ if (enemies == 0)
+ lprtf("(geen)");
+ lprtf("\n");
+ }
return FollowupAction::NONE;
}
diff --git a/frontend/cmd/search.cpp b/frontend/cmd/search.cpp
index 4646ddc..67b0bf1 100644
--- a/frontend/cmd/search.cpp
+++ b/frontend/cmd/search.cpp
@@ -1,9 +1,21 @@
#include "../Player.h"
+#include "../print.h"
+
+#include "backend/Location.h"
using namespace std;
-FollowupAction Player::cmd_search(string & argv) {
- // TODO
+FollowupAction Player::cmd_search(string &) {
+ bool found = false;
+ for (Object * object : this->location.get_objects()) {
+ if (object->get_hidden() == false) continue;
+ if (!found) lprtf("Je vindt:\n");
+ lprtf("- %s\n", object->get_displayname());
+ object->set_hidden(false);
+ found = true;
+ }
+ if (!found)
+ lprtf("Je hebt niks gevonden.\n");
return FollowupAction::UPDATE;
}