aboutsummaryrefslogtreecommitdiff
path: root/frontend/cmd/hit.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/hit.cpp
parenta7e84b60366c78b131d43157980fbe4c2df655e6 (diff)
change flow architecture
Diffstat (limited to 'frontend/cmd/hit.cpp')
-rw-r--r--frontend/cmd/hit.cpp18
1 files changed, 11 insertions, 7 deletions
diff --git a/frontend/cmd/hit.cpp b/frontend/cmd/hit.cpp
index 2f39e8a..677bf4e 100644
--- a/frontend/cmd/hit.cpp
+++ b/frontend/cmd/hit.cpp
@@ -2,28 +2,32 @@
#include "backend/Location.h"
#include "backend/RNG.h"
#include "backend/print.h"
+#include "backend/Dungeon.h"
#include "../GameController.h"
#include "../strings.h"
+#include "../Exception.h"
using namespace std;
-FollowupAction GameController::cmd_hit(string & target_name) {
+void GameController::cmd_hit(string & target_name) {
RNG & rng = RNG::get();
- for (Enemy * enemy : this->player.get_location().get_enemies()) {
+ Player & player = this->dungeon->get_player();
+ for (Enemy * enemy : player.get_location().get_enemies()) {
if (str_lower(enemy->get_name().c_str()) != str_lower(target_name)) continue;
- if (rng.rand_double() > this->player.get_attack()) {
+ if (rng.rand_double() > player.get_attack()) {
lprtf("Je hebt gemist!\n");
} else {
- unsigned damage = rng.rand_int(this->player.weapon->get_damage_min(), this->player.weapon->get_damage_max() + 1);
+ unsigned damage = rng.rand_int(player.weapon->get_damage_min(), player.weapon->get_damage_max() + 1);
enemy->take_damage(damage);
lprtf("Je hebt %s geraakt en %d schade aangericht!\n", enemy->get_displayname().c_str(), damage);
}
- return FollowupAction::UPDATE;
+
+ this->dungeon->update();
+ return;
}
- lprtf("Vijand \"%s\" niet gevonden.\n", target_name.c_str());
- return FollowupAction::NONE;
+ throw Exception("Vijand \"%s\" niet gevonden.", target_name.c_str());
}