Early Returns

I tried to use few return statements since i see no point in using it for each if statement.
I think it is better just using them with the win/lose conditions, since the “not-an-isogram” and “not-correct-length” messages can be stacked in the terminal and also give the player more information if they use a word that is not an isogram but also with the incorrect length.

Aside from that, i implemented a forced conversion to lowercase to prevent errors with caps. Maybe it also needs validation to prevent alphanumerical strings later.

What do you think about this check order?

void UBullCowCartridge::CompareGuess(FString Guess)
{
    PrintLine(Guess); 

    //Convert Input to lowercase
    Guess = Guess.ToLower();

    if(Guess == HiddenWord)
    {
        PrintLine(TEXT("Congrats! That is the Hidden Word."));
        EndGame();
        return;
    }

    --Lives;
    if(Lives <= 0)
    {
        PrintLine(TEXT("GAME OVER\n The Hidden Word was %s"), *HiddenWord);
        EndGame();
        return;
    }

    if(Guess.Len() != HiddenWord.Len())
        PrintLine(TEXT("Remember, the Hidden Word is %i characters long!"), HiddenWord.Len());

    //If it is not isogram 
        //Ask the player to type a valid isogram
        
    //Print log of lives remaining
    PrintLine(TEXT("Lives remaining: %i"), Lives);
    PrintLine(TEXT("Try again..."));

}

The game so far…

1 Like

So far it looks good. Does it run well?

Privacy & Terms