You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
39 lines
809 B
39 lines
809 B
#include <map>
|
|
#include <string>
|
|
#include <fmt/core.h>
|
|
#include <fmt/color.h>
|
|
#include "game_engine.hpp"
|
|
|
|
using namespace fmt;
|
|
using namespace std;
|
|
|
|
const auto ERROR = fmt::emphasis::bold | fg(fmt::color::red);
|
|
|
|
GameEngine::GameEngine(int hp) : hit_points(hp) {};
|
|
|
|
int GameEngine::determine_damage(string &type) {
|
|
try {
|
|
return damage_types.at(type);
|
|
} catch(std::out_of_range &err) {
|
|
print(ERROR, "BAD DAMAGE TYPE {}\n", type);
|
|
return 1000;
|
|
}
|
|
}
|
|
|
|
bool GameEngine::hit(string &type) {
|
|
int damage = determine_damage(type);
|
|
hit_points -= damage;
|
|
|
|
if(is_dead()) {
|
|
print(ERROR, "YOU DIED!\n");
|
|
} else {
|
|
println("DAMAGE {}, HP: {}", damage, hit_points);
|
|
}
|
|
|
|
// super dumb but I'll clean it up later
|
|
return is_dead();
|
|
}
|
|
|
|
bool GameEngine::is_dead() {
|
|
return hit_points <= 0;
|
|
}
|
|
|