aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/view.cpp
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 17:32:53 +0100
commitb20f46c15dce8b196dbb8890890978947745e094 (patch)
treed9defa84717ffa843fd11b05d0e856473d6d8d59 /frontend/cmd/view.cpp
parenta7e84b60366c78b131d43157980fbe4c2df655e6 (diff)
change flow architecture
Diffstat (limited to 'frontend/cmd/view.cpp')
-rw-r--r--frontend/cmd/view.cpp45
1 files changed, 24 insertions, 21 deletions
diff --git a/frontend/cmd/view.cpp b/frontend/cmd/view.cpp
index 04ad6aa..0f4f3d1 100644
--- a/frontend/cmd/view.cpp
+++ b/frontend/cmd/view.cpp
@@ -1,44 +1,46 @@
#include "../GameController.h"
#include "../strings.h"
+#include "../Exception.h"
#include "backend/print.h"
#include "backend/Location.h"
+#include "backend/Dungeon.h"
using namespace std;
-FollowupAction GameController::cmd_view(string & target) {
+void GameController::cmd_view(string & target) {
if (target.size() == 0) {
- lprtf("Fout, gebruik: Bekijk <Zelf|VIJHAND|OBJECT>\n");
- return FollowupAction::NONE;
+ throw Exception("gebruik: Bekijk <Zelf|VIJHAND|OBJECT>");
}
- Location & location = this->player.get_location();
+ Player & player = this->dungeon->get_player();
+ Location & location = player.get_location();
// view self
if (str_lower(target) == "zelf") {
- lprtf("Je hebt %d levenspunten.\n", this->player.get_health());
+ lprtf("Je hebt %d levenspunten.\n", player.get_health());
- lprtf("Je hebt een aanvalskans van %.0f%%.\n", this->player.get_attack() * 100);
+ lprtf("Je hebt een aanvalskans van %.0f%%.\n", player.get_attack() * 100);
- if (this->player.weapon == nullptr)
+ if (player.weapon == nullptr)
lprtf("Je hebt geen wapen vast.\n");
else
- lprtf("Je hebt het volgende wapen vast: %s.\n", this->player.weapon->get_displayname().c_str());
+ lprtf("Je hebt het volgende wapen vast: %s.\n", player.weapon->get_displayname().c_str());
- if (this->player.armor == nullptr)
+ if (player.armor == nullptr)
lprtf("Je draagt geen wapenrusting.\n");
else
- lprtf("Je draagt de volgende wapenrusting: %s.\n", this->player.armor->get_displayname().c_str());
+ lprtf("Je draagt de volgende wapenrusting: %s.\n", player.armor->get_displayname().c_str());
- lprtf("Je hebt %u goundstuk%s.\n", this->player.gold, this->player.gold == 1 ? "" : "ken");
+ lprtf("Je hebt %u goundstuk%s.\n", player.gold, player.gold == 1 ? "" : "ken");
- size_t items = this->player.inventory.size();
+ size_t items = player.inventory.size();
lprtf("Je hebt %d %s%s\n", items, items == 1 ? "overig object" : "overige objecten", items > 0 ? ":" : ".");
- for (auto & object : this->player.inventory) {
+ for (auto & object : player.inventory) {
lprtf("- %s\n", object->get_displayname().c_str());
}
- return FollowupAction::NONE;
+ return;
}
// try to find visible object in location
@@ -46,15 +48,15 @@ FollowupAction GameController::cmd_view(string & target) {
if (str_lower(object->get_name().c_str()) != str_lower(target)) continue;
lprtf("%s\n", object->get_description().c_str());
- return FollowupAction::NONE;
+ return;
}
// try to find object in inventory
- for (auto & object : this->player.inventory) {
+ for (auto & object : player.inventory) {
if (str_lower(object->get_name().c_str()) != str_lower(target)) continue;
lprtf("%s\n", object->get_description().c_str());
- return FollowupAction::NONE;
+ return;
}
// try to find enemy by name
@@ -65,7 +67,9 @@ FollowupAction GameController::cmd_view(string & target) {
unsigned enemy_health = enemy->get_health();
lprtf("%s heeft %s levenspunten.\n", enemy->get_name().c_str(), enemy_health);
- if (!enemy->is_dead()) return FollowupAction::NONE;
+ if (!enemy->is_dead())
+ return;
+
bool snatched = false;
for (Object * object : enemy->get_hidden_objects()) {
if (!snatched) lprtf("%s had de volgende voorwerpen:\n", enemy->get_displayname().c_str());
@@ -74,10 +78,9 @@ FollowupAction GameController::cmd_view(string & target) {
location.add_visible_object(object);
snatched = true;
}
- return FollowupAction::NONE;
+ return;
}
- lprtf("Fout, geen entiteit met naam \"%s\" gevonden.\n", target.c_str());
- return FollowupAction::NONE;
+ throw Exception("geen entiteit met naam \"%s\" gevonden.", target.c_str());
}