diff --git a/builder.cpp b/builder.cpp index d039360..5905cbd 100644 --- a/builder.cpp +++ b/builder.cpp @@ -40,7 +40,7 @@ void Builder::run_build(GameEngine &game, const char* command) { FILE *build_out = popen(command, "r"); dbc::check(build_out != nullptr, "Failed to run command."); - int hit_count = 0; + game.start_round(); while(fgets(buffer, BUF_MAX, build_out) != nullptr) { string line(buffer); // yeah, that's probably a problem @@ -63,7 +63,6 @@ void Builder::run_build(GameEngine &game, const char* command) { gui.output(format("\nHIT WITH {} @ {}:{}:{} {}", type, file_name, lnumber, col, message)); game.hit(type); - ++hit_count; // refactor this if(game.is_dead()) { @@ -72,9 +71,7 @@ void Builder::run_build(GameEngine &game, const char* command) { } } - if(hit_count == 0) { - game.heal(10); - } + game.end_round(); int rc = pclose(build_out); if(rc == 0) { diff --git a/game_engine.cpp b/game_engine.cpp index 6e2fe5a..892a80a 100644 --- a/game_engine.cpp +++ b/game_engine.cpp @@ -136,16 +136,28 @@ int GameEngine::determine_damage(string &type) { } } +void GameEngine::start_round() { + hits_taken = 0; +} + +void GameEngine::end_round() { + if(hits_taken == 0) { + heal(); + } +} + bool GameEngine::hit(string &type) { int damage = determine_damage(type); hit_points -= damage; + ++hits_taken; // super dumb but I'll clean it up later return is_dead(); } -void GameEngine::heal(int amount) { - hit_points += amount; +void GameEngine::heal() { + hit_points = hit_points * 1.10; + if(hit_points > 100) hit_points = 100; } bool GameEngine::is_dead() { diff --git a/game_engine.hpp b/game_engine.hpp index a8d5dd2..604e3c6 100644 --- a/game_engine.hpp +++ b/game_engine.hpp @@ -36,14 +36,19 @@ class GameEngine { public: int hit_points = 0; + int hits_taken = 0; GameEngine(int hp); int determine_damage(string &type); + void start_round(); + + void end_round(); + bool hit(string &type); bool is_dead(); - void heal(int amount); + void heal(); }; diff --git a/gui.cpp b/gui.cpp index 8f0aa2f..bb29ac1 100644 --- a/gui.cpp +++ b/gui.cpp @@ -76,6 +76,9 @@ int GUI::main_loop(GameEngine &game, std::function runner) { while (!loop.HasQuitted()) { int run_error = runner(); + + if(run_error != 0) output("RUNNER ERROR!!!! CATASTROPHIC!!!"); + loop.RunOnce(); screen.Post(Event::Custom); std::this_thread::sleep_for(std::chrono::milliseconds(10));