A bit of restructuring and some color output for fun.

master
Zed A. Shaw 4 months ago
parent 5c1b6d9243
commit 00597c0aaa
  1. 32
      watchgit.cpp

@ -1,38 +1,49 @@
#include <iostream> #include <iostream>
#include <iomanip>
#include <fstream> #include <fstream>
#include <fmt/core.h> #include <fmt/core.h>
#include <fmt/color.h>
#include <fmt/chrono.h> #include <fmt/chrono.h>
#include <regex>
#include <string> #include <string>
#include <iterator>
#include <ctime>
#include "dbc.h" #include "dbc.h"
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <git2.h> #include <git2.h>
#include <efsw/efsw.hpp> #include <efsw/efsw.hpp>
#include <regex> #include <regex>
#include <set>
#include <filesystem> #include <filesystem>
#include <map>
using namespace std; using namespace std;
using namespace fmt; using namespace fmt;
namespace fs = std::filesystem; namespace fs = std::filesystem;
const auto ERROR = fmt::emphasis::bold | fg(fmt::color::red);
#define BUF_MAX 1024 #define BUF_MAX 1024
class GameEngine { class GameEngine {
int hit_points = 0; int hit_points = 0;
map<string, int> damage_types{
{"error", 4}, {"warning", 1}};
public: public:
GameEngine(int hp) : hit_points(hp) {}; GameEngine(int hp) : hit_points(hp) {};
bool hit(unsigned int damage) { 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; hit_points -= damage;
if(is_dead()) { if(is_dead()) {
println("YOU DIED!"); print(ERROR, "YOU DIED!\n");
} else { } else {
println("DAMAGE {}, HP: {}", damage, hit_points); println("DAMAGE {}, HP: {}", damage, hit_points);
} }
@ -121,12 +132,7 @@ void run_build(GameEngine &game, const char* command) {
stats_out << result; stats_out << result;
println("{} @ {}:{}:{} {}", type, file_name, lnumber, col, message); println("{} @ {}:{}:{} {}", type, file_name, lnumber, col, message);
game.hit(type);
if(type == "error") {
game.hit(4);
} else {
game.hit(1);
}
} }
} }

Loading…
Cancel
Save