更新 main.cpp
fix update hp before show command
This commit is contained in:
parent
329cf37cc2
commit
b21175ac14
23
main.cpp
23
main.cpp
@ -219,6 +219,22 @@ void gameLoop() {
|
||||
bool commandOk = false;
|
||||
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
|
||||
* space, or if there is no space, the whole string. */
|
||||
auto endOfVerb = static_cast<uint8_t>(commandBuffer.find(' '));
|
||||
@ -383,13 +399,6 @@ void gameLoop() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user