Make the game engine use a start/end round and do healing if you don't make any mistakes.
This commit is contained in:
parent
e35536c7e3
commit
c52bc8fafd
4 changed files with 25 additions and 8 deletions
|
@ -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) {
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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();
|
||||
};
|
||||
|
|
3
gui.cpp
3
gui.cpp
|
@ -76,6 +76,9 @@ int GUI::main_loop(GameEngine &game, std::function<bool()> 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));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue