From 329cf37cc267631729e5748b23ca6247dae8e757 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Sat, 18 Nov 2023 17:58:43 +0800 Subject: [PATCH] fix modify hp calc --- .gitignore | 1 + main.cpp | 14 ++++++++++---- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 59b0c4b..af00e84 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ cmake-* .idea/ +build/ diff --git a/main.cpp b/main.cpp index 3c985a2..2fb2632 100644 --- a/main.cpp +++ b/main.cpp @@ -13,6 +13,7 @@ #include "FoodObject.h" #include #include +#include using std::string; using std::unique_ptr; @@ -212,6 +213,7 @@ std::vector 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); } } @@ -395,4 +401,4 @@ int main() { currentState->announceLoc(); gameLoop(); return 0; -} \ No newline at end of file +}