Hi!
I faced two errors and it seems I did something wrong or maybe accidentally broke the code.
Could anybody help to identify where is the mistake here?
Please see below the screenshot of where the errors are and the code I have so far. Thank you!
// 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();
PrintLine(TEXT("The HiddenWord is: %s."), *HiddenWord); // Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
// int32 a = 1;
// int32 b = ++a;
// int32 c = ++ ++a;
// int32 d = a += 2;
// int32 e = a++;
// PrintLine(TEXT("%i, %i, %i, %i, %i"), a, b, c, d, e);
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else // Checking PlayerGuess
{
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame()
{
// Welcoming the player
PrintLine(TEXT("Hi! Welcome to the Bull Cows Game!"));
HiddenWord = TEXT("cakes");
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine(TEXT("Guess the %i letter word"), HiddenWord.Len());
PrintLine(TEXT("Your have %i lives."), Lives);
PrintLine(TEXT("Type in your guess \nand press Enter to Continue...")); // Prompt player for guess
// const TCHAR HW[] = TEXT("plums");
// PrintLine(TEXT("Character 1 of the hidden word is: %c"), HiddenWord[0]); // print "c"
// PrintLine(TEXT("The 4th character of HW is: %c"), HW[3]); // prints "m"
int32 i = 0;
while (i < 10)
{
PrintLine(TEXT("%i"), i);
i++;
}
for (int32 Index = 0; Index < 2; Index++)
{
PrintLine(TEXT("%i"), Index);
}
int32 j = 0;
do
{
PrintLine(TEXT("%i"), j);
j++;
} while (j < 2);
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("\nPress enter to play again."));
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
if (Guess == HiddenWord)
{
PrintLine(TEXT("You have won!"));
EndGame();
return;
}
// Check If Isogram
if (!IsIsogram(Guess))
{
PrintLine(TEXT("No repeating letters, guess again"));
return;
}
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("The hidden word is %i letters long"), HiddenWord.Len());
PrintLine(TEXT("Sorry, try guessing again! \nYou have %i lives remaining"), Lives);
return;
}
// Remove Life
PrintLine(TEXT("Lost a life!"));
--Lives;
if (Lives <= 0)
{
ClearScreen();
PrintLine(TEXT("You have no lives left!"));
PrintLine(TEXT("The hidden word was: %s"), *HiddenWord);
EndGame();
return;
}
// show the player the buuls and cows
PrintLine(TEXT("Guess again, you have %i lives left"), Lives);
}
bool UBullCowCartridge::IsIsogram(FString Word) const
{
// For each letter
// Start at element [0].
// Compare against the next letter.
// Until we reach [Word.Len() -1].
// if any are the same return false
return true;
}