#include "backend/Enemy.h" #include "backend/Location.h" #include "backend/RNG.h" #include "backend/print.h" #include "backend/Dungeon.h" #include "backend/Exception.h" #include "../GameController.h" #include "../strings.h" using namespace std; void GameController::cmd_hit(string & target_name) { RNG & rng = RNG::get(); 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() > player.get_attack()) { lprtf("Je hebt gemist!\n"); } else { 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); } this->dungeon->update(); return; } throw Exception("vijand \"%s\" niet gevonden", target_name.c_str()); }