In for a Loop?

Here is my Code:

// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"

void UBullCowCartridge::BeginPlay() // When the game starts
{
    Super::BeginPlay();
    
    SetupGame();// makes sense to set up game first: Lives and Word ready to go
  
    PrintLine(TEXT("The Hidden word is: %s."), *HiddenWord);// debug line

}


void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{  
    if (bGameOver == true)
    {
        ClearScreen();
        SetupGame();
        return;   
    } 
    else // Check Player guess
    {
        ProcessGuess(Input);
        return;
    }
}  


void UBullCowCartridge::SetupGame()
{

    // Welcomeing The Player
    PrintLine(TEXT("Welcome to Bull Cow!"));

    HiddenWord = TEXT("words"); 
    Lives = HiddenWord.Len();
    bGameOver = false;
    
    PrintLine(TEXT("The Hidden word is: %s."), *HiddenWord);// debug line

    PrintLine(TEXT("Guess the %i letter word!"), HiddenWord.Len()); 
    PrintLine(TEXT("you have %i lives."), Lives);
    PrintLine(TEXT("Type in your guess and \npress enter to moove on..."));
    
    // const TCHAR HW[] = TEXT("words");
    // PrintLine(TEXT("Character 1 of the hidden word is: %c"), HW [0]);
    // PrintLine(TEXT("The 4th character of HW is: %c"), HW [3]);
    IsIsogram(HiddenWord);
}


void UBullCowCartridge::EndGame()
{
    bGameOver = true; 
        PrintLine(TEXT("\nPress Enter to play again..."));
}


void UBullCowCartridge::ProcessGuess(FString Guess)
{
    if (Guess == HiddenWord)
        {
            ClearScreen();
            PrintLine(TEXT("You Win!"));
            EndGame(); 
            return;
            // More Words to Complete?
            // If Yes, Print: You Completed this Word --> Ask if Want to continue playing?-- return
                             
            //if No,Print below--return
            
            //Prompt Play again?
            // If Yes SetUpGame--return
            // If No: EndGame--return
        }
   
 
    if (Guess.Len() != HiddenWord.Len())
    {
        PrintLine(TEXT("The hidden word is %i letters long"), HiddenWord.Len());
        PrintLine(TEXT("Sorry! Guess again, you have %i \nlives left"), Lives);
        
        return;
        
    }
     // Isogram?
    if (!IsIsogram(Guess))
    {
       PrintLine(TEXT("No repeatingletters, guess again"));
    }
    
    // Prompt to GuessAgain
    // Repeated Letters?
    // Prompt to GuessAgain 
    PrintLine(TEXT("Lost a Life!"));
    --Lives;

    if (Lives <= 0)
    {
        ClearScreen();
        PrintLine(TEXT("You have no lives left!"));
        PrintLine(TEXT("The hidden world was: %s"), *HiddenWord);
        EndGame();
        return;
    }
    // Show the player BUlls and Cows
    PrintLine(TEXT("Guess again, you have %i lives left"), Lives);
     
    // Check User Input
    // Play Again or Quit?  
   
        // Only one if right now, but if more than one check, then will place more if statements
    //if Character Guess and return
    //if isogram-- return           
}

bool UBullCowCartridge::IsIsogram(FString Word) const
{
    for (int32 Index = 0; Index < Word.Len(); Index++)
    {
        PrintLine(TEXT("%c"), Word[Index]);
    }
    
    {
        /* code */
    }
    
    
    
    // for each letter
    // start at element [0]
    // Compare against the next letter
    // Until we reach [Word.Len() -1]
    // if the any letters are the same return false.
    
    return true;
}

I was not able to anticipate the code he typed in. Part of my issue was my unclear understanding of passing off variables between function: Input --> Guess --> Word–>for statement.

But having now gone through the video it made more sense and my understanding of the matter a little more clear. As I build up my c++ “vocabulary” it should be easier to figure out. If you do not know what “1”, “2”,"+", and “=” means, it will be very difficult to anticipate “3”.

That being said, I am glad to have a course teaching me the c++ “ABC’s and 123’s”, otherwise I would have cowed under the weight of the code until it bull me over.

I can’t with your jokes :rofl:

Privacy & Terms