aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 22:47:42 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-11-01 22:47:42 +0100
commit07796bea15a2d5f43766f062379b63fc9e9e1b5d (patch)
tree2d398f161a9a933176f50779ff164e76c3871f43 /frontend/cmd
parentaf76b9a0ae58dc8c87548053a5bc310ad6be25ce (diff)
WIP consumables
Diffstat (limited to 'frontend/cmd')
-rw-r--r--frontend/cmd/go.cpp5
-rw-r--r--frontend/cmd/use.cpp24
2 files changed, 23 insertions, 6 deletions
diff --git a/frontend/cmd/go.cpp b/frontend/cmd/go.cpp
index 75f6345..b8bb7e2 100644
--- a/frontend/cmd/go.cpp
+++ b/frontend/cmd/go.cpp
@@ -1,7 +1,6 @@
#include "backend/Location.h"
#include "backend/Dungeon.h"
#include "backend/Exception.h"
-#include "backend/print.h"
#include "../GameController.h"
#include "../strings.h"
@@ -30,9 +29,7 @@ void GameController::cmd_go(string & argv) {
this->dungeon->update();
- if (!player.is_dead()) {
+ if (!player.is_dead())
player.set_location(*next_location);
- lprtf("Je staat nu bij de locatie %s\n", player.get_location().get_name().c_str());
- }
}
diff --git a/frontend/cmd/use.cpp b/frontend/cmd/use.cpp
index badab10..36824b5 100644
--- a/frontend/cmd/use.cpp
+++ b/frontend/cmd/use.cpp
@@ -1,8 +1,28 @@
+#include "backend/ConsumableObject.h"
+#include "backend/Exception.h"
+#include "backend/print.h"
+
#include "../GameController.h"
+#include "../strings.h"
using namespace std;
-void GameController::cmd_use(string & argv) {
- // TODO
+void GameController::cmd_use(string & target_name) {
+ Player & player = this->dungeon->get_player();
+ Location & location = player.get_location();
+ for (Object * object : player.inventory) {
+ if (str_lower(object->get_name().c_str()) != str_lower(target_name)) continue;
+
+ auto consumable = unique_ptr<ConsumableObject>(dynamic_cast<ConsumableObject *>(object));
+ if (consumable == nullptr)
+ throw Exception("%s is niet consumeerbaar", object->get_name().c_str());
+
+ lprtf("Je drinkt %s.\n", object->get_displayname().c_str());
+ player.inventory.remove(object);
+ consumable->consume(player);
+ return;
+ }
+
+ throw Exception("object \"%s\" niet gevonden", target_name.c_str());
}