fix modify hp calc

This commit is contained in:
tqcq 2023-11-18 17:58:43 +08:00
parent ee8cc69a8b
commit 329cf37cc2
2 changed files with 11 additions and 4 deletions

1
.gitignore vendored
View File

@ -1,2 +1,3 @@
cmake-*
.idea/
build/

View File

@ -13,6 +13,7 @@
#include "FoodObject.h"
#include <fstream>
#include <sstream>
#include <time.h>
using std::string;
using std::unique_ptr;
@ -212,6 +213,7 @@ std::vector<std::string> split(const std::string &str) {
*/
void gameLoop() {
bool gameOver = false;
auto prev_time = time(nullptr);
while (!gameOver) {
/* Ask for a command. */
bool commandOk = false;
@ -379,11 +381,15 @@ void gameLoop() {
if (!commandOk) {
wrapOut(&badCommand);
wrapEndPara();
} else {
currentState->setHP(currentState->getHP() - 1);
gameOver = gameOver && (currentState->getHP() <= 0);
}
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);
}
}