fix modify hp calc
This commit is contained in:
parent
ee8cc69a8b
commit
329cf37cc2
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
||||
cmake-*
|
||||
.idea/
|
||||
build/
|
||||
|
14
main.cpp
14
main.cpp
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -395,4 +401,4 @@ int main() {
|
||||
currentState->announceLoc();
|
||||
gameLoop();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user