Moved the game engine into its own unit and then made a failing test for it.

This commit is contained in:
Zed A. Shaw 2024-08-09 23:01:06 -04:00
parent fb5bf9d733
commit 440be444ea
7 changed files with 82 additions and 49 deletions

View file

@ -4,64 +4,21 @@
#include <fmt/color.h>
#include <fmt/chrono.h>
#include <string>
#include "dbc.h"
#include "dbc.hpp"
#include "game_engine.hpp"
#include <unistd.h>
#include <stdio.h>
#include <git2.h>
#include <efsw/efsw.hpp>
#include <regex>
#include <filesystem>
#include <map>
using namespace std;
using namespace fmt;
namespace fs = std::filesystem;
const auto ERROR = fmt::emphasis::bold | fg(fmt::color::red);
#define BUF_MAX 1024
class GameEngine {
int hit_points = 0;
map<string, int> damage_types{
{"error", 4},
{"warning", 1},
{"note", 1},
};
public:
GameEngine(int hp) : hit_points(hp) {};
int 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 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 is_dead() {
return hit_points <= 0;
}
};
class UpdateListener : public efsw::FileWatchListener {
public:
bool changes = false;