Make the game engine use a start/end round and do healing if you don't make any mistakes.

master
Zed A. Shaw 3 months ago
parent e35536c7e3
commit c52bc8fafd
  1. 7
      builder.cpp
  2. 16
      game_engine.cpp
  3. 7
      game_engine.hpp
  4. 3
      gui.cpp

@ -40,7 +40,7 @@ void Builder::run_build(GameEngine &game, const char* command) {
FILE *build_out = popen(command, "r"); FILE *build_out = popen(command, "r");
dbc::check(build_out != nullptr, "Failed to run command."); dbc::check(build_out != nullptr, "Failed to run command.");
int hit_count = 0; game.start_round();
while(fgets(buffer, BUF_MAX, build_out) != nullptr) { while(fgets(buffer, BUF_MAX, build_out) != nullptr) {
string line(buffer); // yeah, that's probably a problem 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)); gui.output(format("\nHIT WITH {} @ {}:{}:{} {}", type, file_name, lnumber, col, message));
game.hit(type); game.hit(type);
++hit_count;
// refactor this // refactor this
if(game.is_dead()) { if(game.is_dead()) {
@ -72,9 +71,7 @@ void Builder::run_build(GameEngine &game, const char* command) {
} }
} }
if(hit_count == 0) { game.end_round();
game.heal(10);
}
int rc = pclose(build_out); int rc = pclose(build_out);
if(rc == 0) { if(rc == 0) {

@ -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) { bool GameEngine::hit(string &type) {
int damage = determine_damage(type); int damage = determine_damage(type);
hit_points -= damage; hit_points -= damage;
++hits_taken;
// super dumb but I'll clean it up later // super dumb but I'll clean it up later
return is_dead(); return is_dead();
} }
void GameEngine::heal(int amount) { void GameEngine::heal() {
hit_points += amount; hit_points = hit_points * 1.10;
if(hit_points > 100) hit_points = 100;
} }
bool GameEngine::is_dead() { bool GameEngine::is_dead() {

@ -36,14 +36,19 @@ class GameEngine {
public: public:
int hit_points = 0; int hit_points = 0;
int hits_taken = 0;
GameEngine(int hp); GameEngine(int hp);
int determine_damage(string &type); int determine_damage(string &type);
void start_round();
void end_round();
bool hit(string &type); bool hit(string &type);
bool is_dead(); bool is_dead();
void heal(int amount); void heal();
}; };

@ -76,6 +76,9 @@ int GUI::main_loop(GameEngine &game, std::function<bool()> runner) {
while (!loop.HasQuitted()) { while (!loop.HasQuitted()) {
int run_error = runner(); int run_error = runner();
if(run_error != 0) output("RUNNER ERROR!!!! CATASTROPHIC!!!");
loop.RunOnce(); loop.RunOnce();
screen.Post(Event::Custom); screen.Post(Event::Custom);
std::this_thread::sleep_for(std::chrono::milliseconds(10)); std::this_thread::sleep_for(std::chrono::milliseconds(10));

Loading…
Cancel
Save