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-* cmake-*
.idea/ .idea/
build/

View File

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