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