A bit of restructuring and some color output for fun.
This commit is contained in:
parent
5c1b6d9243
commit
00597c0aaa
1 changed files with 19 additions and 13 deletions
32
watchgit.cpp
32
watchgit.cpp
|
@ -1,38 +1,49 @@
|
|||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/color.h>
|
||||
#include <fmt/chrono.h>
|
||||
#include <regex>
|
||||
#include <string>
|
||||
#include <iterator>
|
||||
#include <ctime>
|
||||
#include "dbc.h"
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <git2.h>
|
||||
#include <efsw/efsw.hpp>
|
||||
#include <regex>
|
||||
#include <set>
|
||||
#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}};
|
||||
|
||||
public:
|
||||
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;
|
||||
|
||||
if(is_dead()) {
|
||||
println("YOU DIED!");
|
||||
print(ERROR, "YOU DIED!\n");
|
||||
} else {
|
||||
println("DAMAGE {}, HP: {}", damage, hit_points);
|
||||
}
|
||||
|
@ -121,12 +132,7 @@ void run_build(GameEngine &game, const char* command) {
|
|||
stats_out << result;
|
||||
println("{} @ {}:{}:{} {}", type, file_name, lnumber, col, message);
|
||||
|
||||
|
||||
if(type == "error") {
|
||||
game.hit(4);
|
||||
} else {
|
||||
game.hit(1);
|
||||
}
|
||||
game.hit(type);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue