At 13:46 I understand what the IsIsogram() function does for the most part but what I don’t understand is how the variable Word is getting the player input or the Guess because it is only used within IsIsogram. Can someone explain this to me?
// 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();
//Debug line
PrintLine(TEXT("The HiddenWord is: %s.\nIt is %i characters long"), *HiddenWord, HiddenWord.Len());
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
// if game is over then clearscreen and setupgame
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else
{ //else Check player guess
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame()
{
//Welcome player
HiddenWord = (TEXT("Cakes"));
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine(TEXT("Welcom to bull cow gam:)"));
PrintLine(TEXT("Guess the %i Letter word"),HiddenWord.Len());
PrintLine(TEXT("You have %i Lives"),Lives);
PrintLine(TEXT("Press Enter to continue"));
/* const TCHAR HW[] = TEXT("cakes");
PrintLine(TEXT("Character 1 of the hidden word is: %c"), HiddenWord[0]); */
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press Enter to play again."));
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
if (Guess == HiddenWord)
{
PrintLine(TEXT("You win"));
EndGame();
return;
}
// Check if rightnumber of characters
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("Sorry, try guessing again! \nYou have %i Lives remaining"), Lives);
PrintLine(TEXT("The hidden word is %i letters long."), HiddenWord.Len());
return;
}
// Check if isogram
if (!IsIsogram(Guess))
{
PrintLine(TEXT("No repeting letters, guess again"));
return;
}
//Remove Life
--Lives;
PrintLine(TEXT("Lost a life!"));
//Check if Lives = 0
if (Lives <= 0)
{
ClearScreen();
PrintLine(TEXT("You have no lives left!"));
PrintLine(TEXT("The word was %s"),*HiddenWord);
EndGame();
return;
}
// Show Player Bulls and Cows
}
bool UBullCowCartridge::IsIsogram(FString Word) const
{
for (int32 Index = 0; Index < Word.Len(); Index++)
{
PrintLine(TEXT("%c"), Word[Index]);
}
/* For each letter.
start at element [0].
Compare against the next letter.
Until we reach [Word.Len() -1].
if any letters are the same return false */
return true;
}