Question about code placement

I initially had put two “for” loops inside of the ProcessGuess function. Would it be completely wrong, or is this just a matter of better readability and for this game’s particular design?

**Note that it’s currently commented out.

void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord)
    {
        PrintLine (TEXT("You win!"));
        //+ difficulty
        //On max difficulty: PlayAgain or Quit
        EndGame();
        return;
    }

    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("It's %i letters long, dummy... \nTry again!"), HiddenWord.Len());
        PrintLine(TEXT("You still have %i lives left."), Lives);
        return;
    }

    if(!IsIsogram(Guess))
     {
        PrintLine(TEXT("Can't have repeating letters, guess again"));
     }
    // If it doesn't meet requirement, GuessAgain
    // else
    // {
        // for (int32 HW = 0; HW < HiddenWord.Len(); HW++)
        // {
        //     PrintLine(TEXT("%c"), HiddenWord[HW]);
        //     // PrintLine(TEXT("%c"), Guess[HW]);
        // }
        // for (int32 IP = 0; IP < Guess.Len(); IP++)
        // {
        //     PrintLine(TEXT("%c"), Guess[IP]);
        // }
        
    // }
1 Like

There’s nothing wrong with something that works (most of the time) as long as it’s simple and well documented. There’s always more than one way of doing things.
It’s why we have to refactor code as we find better ways of doing things.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms