My code so far with lives not lost when guess is wrong length

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking PlayerGuess
    {
        if (Input == HiddenWord)
        {
            PrintLine(TEXT("Congrats, you guessed the right word!"));
            EndGame();
        }
        else
        {
            if (Input.Len() != HiddenWord.Len())
                {
                PrintLine(TEXT("The word is %i letters long \nyou have %i lives left..."), HiddenWord.Len(), Lives);
                }
            else
            {
                --Lives;
                if (Lives > 0)
                {
                    PrintLine(TEXT("Wrong answer"));
                    PrintLine(TEXT("You have %i lives left"), Lives);
                }
                else
                {
                    ClearScreen();
                    PrintLine(TEXT("It seems you have run out of lives"));
                    PrintLine(TEXT("The Hidden word was %s."), *HiddenWord);
                    EndGame();
                }
            }
        }
    }
}
1 Like

Nice looking code!

1 Like

Privacy & Terms