From 30ff3004a5f41d5d4dac2a0bd5902454c46c8177 Mon Sep 17 00:00:00 2001 From: tqcq <99722391+tqcq@users.noreply.github.com> Date: Wed, 6 Dec 2023 10:11:10 +0800 Subject: [PATCH] optimize adjust wrapOut for hp --- main.cpp | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/main.cpp b/main.cpp index c503b3f..22d226e 100644 --- a/main.cpp +++ b/main.cpp @@ -232,13 +232,20 @@ void gameLoop() { 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(commandBuffer.find(' ')); + if (commandBuffer.compare(0, endOfVerb, "hp") == 0) { + wrapOut("Current HP: " + std::to_string(currentState->getHP())); + wrapEndPara(); + commandOk = true; + } else { + wrapOut("Current HP: " + std::to_string(currentState->getHP())); + wrapEndPara(); + } + + /* We could copy the verb to another string but there's no reason to, we'll just compare it in place. */ /* Command to go north. */ if ((commandBuffer.compare(0, endOfVerb, "north") == 0) || (commandBuffer.compare(0, endOfVerb, "n") == 0)) { @@ -297,12 +304,6 @@ void gameLoop() { } } - if (commandBuffer.compare(0, endOfVerb, "hp") == 0) { - wrapOut("Current HP: " + std::to_string(currentState->getHP())); - wrapEndPara(); - commandOk = true; - } - // check get , drop , eat if (!commandOk) { std::vector words = split(commandBuffer);