A weird game.
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.
turings-tarpit/game_engine.cpp

62 lines
1.1 KiB

#include <map>
#include <string>
#include <iostream>
#include <fmt/core.h>
#include <fmt/color.h>
#include "game_engine.hpp"
const auto ERROR = fmt::emphasis::bold | fg(fmt::color::red);
using namespace fmt;
using namespace std;
GameEngine::GameEngine(int hp) : starting_hp(hp) {
hit_points = starting_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;
}
}
void GameEngine::start_round() {
hits_taken = 0;
}
void GameEngine::end_round() {
++rounds;
if(hits_taken == 0) {
++streak;
heal();
}
}
void GameEngine::reset() {
rounds = 0;
streak = 0;
hit_points = starting_hp;
hits_taken = 0;
}
bool GameEngine::hit(string &type) {
int damage = determine_damage(type);
hit_points -= damage;
++hits_taken;
streak = 0;
return is_dead();
}
void GameEngine::heal() {
hit_points = hit_points * 1.10;
if(hit_points > 100) hit_points = 100;
}
bool GameEngine::is_dead() {
return hit_points <= 0;
}