The game engine now has two bonuses for long build streaks. +10% max hp or 1 free death. I'll be adding more but that's enough to work on the real UI.

This commit is contained in:
Zed A. Shaw 2024-09-15 04:19:52 -04:00
parent 07553400f5
commit 0a9fa59365
3 changed files with 81 additions and 9 deletions

View file

@ -12,7 +12,7 @@ using namespace fmt;
using namespace std;
GameEngine::GameEngine(int hp) : starting_hp(hp) {
hit_points = starting_hp;
hit_points = max_hp();
};
int GameEngine::determine_damage(string &type) {
@ -25,8 +25,17 @@ int GameEngine::determine_damage(string &type) {
}
void GameEngine::reset() {
streak = 0;
hit_points = starting_hp;
println("!!!!!!! RESET hit_points={}, max={}", hit_points, max_hp());
if(free_death) {
hit_points = max_hp() * 0.5f;
} else {
streak = 0;
hit_points = max_hp();
}
println("!!!!!!!! AFTER RESET hit_points={}, max={}", hit_points, max_hp());
free_death = false;
}
bool GameEngine::hit(string &type) {
@ -37,12 +46,12 @@ bool GameEngine::hit(string &type) {
}
void GameEngine::heal() {
hit_points = hit_points * 1.10;
if(hit_points > 100) hit_points = 100;
hit_points = hit_points * 1.10f;
if(hit_points > max_hp()) hit_points = max_hp();
}
bool GameEngine::is_dead() {
return hit_points <= 0;
return free_death ? false : hit_points <= 0;
}
void GameEngine::start(GameEvent ev) {
@ -63,7 +72,9 @@ void GameEngine::in_round(GameEvent ev, string &hit_type) {
switch(ev) {
case GameEvent::HIT:
hit(hit_type);
if(is_dead()) {
// NOTE: don't use is_dead to avoid free_death
if(hit_points <= 0) {
state(GameState::DEAD);
} else {
state(GameState::IN_ROUND);
@ -103,6 +114,22 @@ void GameEngine::success(GameEvent ev) {
void GameEngine::failure(GameEvent ev) {
assert(ev == GameEvent::BUILD_DONE && "failure state expected BUILD_DONE");
++rounds;
streak = 0;
// streak is handled by reset()
state(GameState::IDLE);
}
int GameEngine::max_hp() {
return starting_hp * hp_bonus;
}
void GameEngine::add_bonus(GameBonus bonus) {
switch(bonus) {
case GameBonus::MORE_HP:
hp_bonus += 0.10f;
hit_points = max_hp();
break;
case GameBonus::FREE_DEATH:
free_death = true;
break;
}
}