Hi,
Here is my code at lecture 63. I have tested it out in Unreal Engine 4, and it works just like the instructor’s code. It is a bit different.
Note: The instructor’s code up till lecture 63: https://github.com/UnrealCourse2019/BullCowGame/commit/ae161bae9de70b88efe01caf182b308c43a0b012
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay()
{
Super::BeginPlay();
HiddenWord = TEXT("cow");
Lives = HiddenWord.Len();
SetupGame();
}
void UBullCowCartridge::OnInput(const FString& Input)
{
if(bGameOver) {
ClearScreen();
SetupGame();
return;
} else {
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame() {
bGameOver = false;
bWin = false;
PrintLine(TEXT("Welcome to Bull Cow"));
PrintLine(TEXT("You have %i lives"),Lives);
PrintLine(TEXT("Guess the %i letter word"),HiddenWord.Len());
PrintLine(TEXT("Type in your guess and press enter..."));
}
void UBullCowCartridge::EndGame() {
bGameOver = true;
if(!bWin) {
if(Lives>0) {
PrintLine(TEXT("You have lost a life"));
PrintLine(TEXT("You have %i lives remaining \n"),Lives);
} else {
Lives = HiddenWord.Len();
PrintLine(TEXT("You have lost!"));
PrintLine(TEXT("The hidden word was %s"),*HiddenWord);
}
}
PrintLine(TEXT("Press enter to play again..."));
}
void UBullCowCartridge::ProcessGuess(FString Guess) {
if(Guess==HiddenWord) {
PrintLine(TEXT("You have Won!"));
bWin = true;
EndGame();
} else {
if(Guess.Len()!=HiddenWord.Len()){
PrintLine(TEXT("The Hidden Word is %i characters long."),HiddenWord.Len());
}
--Lives;
EndGame();
}
}```