更新 main.cpp

fix update hp before show command
This commit is contained in:
tqcq 2023-12-05 12:38:33 +00:00
parent 329cf37cc2
commit b21175ac14

View File

@ -219,6 +219,22 @@ void gameLoop() {
bool commandOk = false; bool commandOk = false;
inputCommand(&commandBuffer); inputCommand(&commandBuffer);
auto now = time(nullptr);
if (now - prev_time > 60) {
int hp_offset = (now - prev_time) / 60;
prev_time += hp_offset * 60;
currentState->setHP(currentState->getHP() - hp_offset);
}
gameOver = gameOver || (currentState->getHP() <= 0);
if (gameOver) {
wrapOut("HP is 0 GameOver!!!");
wrapEndPara();
break;
}
wrapOut("Current HP: " + std::to_string(currentState->getHP()));
wrapEndPara();
/* The first word of a command would normally be the verb. The first word is the text before the first /* The first word of a command would normally be the verb. The first word is the text before the first
* space, or if there is no space, the whole string. */ * space, or if there is no space, the whole string. */
auto endOfVerb = static_cast<uint8_t>(commandBuffer.find(' ')); auto endOfVerb = static_cast<uint8_t>(commandBuffer.find(' '));
@ -383,13 +399,6 @@ void gameLoop() {
wrapEndPara(); wrapEndPara();
} }
auto now = time(nullptr);
if (now - prev_time > 60) {
int hp_offset = (now - prev_time) / 60;
prev_time += hp_offset * 60;
currentState->setHP(currentState->getHP() - hp_offset);
}
gameOver = gameOver || (currentState->getHP() <= 0);
} }
} }