OnInput() function implementation

This is my implementation of the OnInput() function:

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
    if (!bGameOver)
    {
        if (Input == HiddenWord)
        {
            PrintLine(TEXT("Correct Guess"));
            PrintLine(TEXT("The hidden word is %s"), *HiddenWord);

            EndGame();
        }
        else
        {
            --Lives;

            PrintLine(TEXT("Wrong Guess. You have lost a life"));
            PrintLine(TEXT("Lives left %i"), Lives);

            if (Length != Input.Len())
            {
                PrintLine(FString::Printf(TEXT("Hidden word is %i chars long."), Length));
            }

            if (Lives == 0)
            {
                EndGame();
            }
        }
    }
    else
    {
        ClearScreen();
        SetupGame();
    }
}

I think it does the same functionality but structured slightly differently.

I have also used another member variable Length to store the HiddenWord length. This is setup in SetupGame() with the rest of the game state initialisation.

2 Likes

Awesome!! How are you liking the course?

It’s a good beginner’s course, Can’t wait to get into Unreal itself but I appreciate you need to get the basic C++ learning out of the way first.

Privacy & Terms