IsIsogram() for loop

Here’s my code so far. I printed both the HiddenWord and Word FStrings in one PrintLIne() statement.

2 Likes

How are you enjoying C++?

I’m having the time of my life. However, the compile times under Visual Community 2019 are brutal. Im getting an average between 2 to 3 and minutes. I purchased a new computer with way more processing power and will have it next week. Hope that helps solve the problem. Aside from that, it’s a great course I’m really learning a lot.

Here my código so far:

#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();

    SetupGame(); 

    PrintLine(TEXT("La palabra secreta es: %s."), *HiddenWord); // Debug Line
}

void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{



    if (bGameOver)
    {
        ClearScreen();
        SetupGame();
    }
    else // Checking PlayerGuess
    {
        ProcessGuess(Input);
    }
}

void UBullCowCartridge::SetupGame()
{  
    // Welcoming player
    PrintLine (TEXT("Muuuuuy bienvenida sea usted!"));
    
    HiddenWord = TEXT("cafe"); 
    Lives = HiddenWord.Len();
    bGameOver = false; 

    PrintLine (TEXT("Adivina la palabra de %i letras"), HiddenWord.Len());
    PrintLine(TEXT("\nTe queda %i vidas"), Lives);
    PrintLine (TEXT("Escribe una palabra y \npresiona ENTER para continuar")); // Prompt PlayerGuees

    // const TCHAR HW[] = TEXT("mota");
    // PrintLine(TEXT("Primera letra de la palabra secreta es: %c"), HiddenWord[0]); // Print "c"
    // PrintLine(TEXT("La cuarta letra de HW es: %c"), HW[3]); // Print letter "a"

    IsIsogram(HiddenWord);
}

void UBullCowCartridge::EndGame()
{
    bGameOver = true;
    ClearScreen();
    PrintLine(TEXT("\nPresiona Enter para jugar de nuevo"));
}

void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord) // Order doesn't matter
    {
        PrintLine (TEXT("Correcto"));
        EndGame();
        return;
    }

    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("La palabra tiene %i letra/s"), HiddenWord.Len());
        PrintLine(TEXT("Intenta de nuevo. \nTe quedan %i vida/s"), Lives);
        return;
    }

    // Check if Isogram
    if (!IsIsogram(Guess)) 
    {
        PrintLine(TEXT("No debe haber letras repetidas.\nIntenta de nuevo."));
        return;
    }

    //Remove Life
    PrintLine(TEXT("Perdiste una vida."));
    --Lives;
    
    if (Lives <= 0)
    {
        PrintLine(TEXT("Ya no te quedan vidas."));
        PrintLine(TEXT("La palabra secreta era: %s"), *HiddenWord);
        EndGame();
        return;
    }

    // Show the player Bulls and Cows
    PrintLine(TEXT("Intenta de nuevo.\nTe quedan %i vida/s"), Lives);

}

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    for (int32 Index = 0; Index < Word.Len(); Index++)
    {
        PrintLine(TEXT("%c"), Word[Index]);
    }

    // For each Level
    // Start at element [0]
    // Compare against the next letter.
    // Until we reach [Word.Len() -1].
    // if any are the same return false.

    return true;
}

Privacy & Terms