My code so far (BullCowCartridge.cpp):
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordLists/HiddenWordList.txt");
FFileHelper::LoadFileToStringArray(Words, *WordListPath);
//...
SetupGame(); //Initializing the game
PrintLine(TEXT("The number of possible words is %i"), Words.Num());
PrintLine(TEXT("HiddenWord is %s."), *HiddenWord, HiddenWord.Len()); //Debug Line
TArray<FString> ValidWords;
for (int32 Counter = 0; Counter < 10; Counter++)
{
if (Words[Counter].Len() >= 4 && Words[Counter].Len() <= 8)
{
ValidWords.Emplace(Words[Counter]);
//PrintLine(TEXT("%s"), *Words[Counter]);
}
}
for (int32 Counter = 0; Counter < ValidWords.Num(); Counter++)
{
PrintLine(TEXT("%s."), ValidWords[Counter]);
}
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if (bGameOver)
{
ClearScreen();
SetupGame();
}
else //Checking PlayerGuess
{
ProcessGuess(Input);
}
//Press enter to Play Again
//Check PlayerInput
}
//What does SetupGame() do?
void UBullCowCartridge::SetupGame()
{
//Welcome the player
PrintLine(TEXT("Welcome to Bull Cow world, where cows come in many sizes!"));
// HiddenWord = Words;
HiddenWord = TEXT("blower"); //hardcoded for now
Lives = HiddenWord.Len();
bGameOver = false;
// PrintLine(TEXT("HiddenWord is %s.\nIt is %i characters long "), *HiddenWord, HiddenWord.Len());
PrintLine(TEXT("Guess the %i letter world"), HiddenWord.Len());
PrintLine(TEXT("You have %i lives"), Lives);
PrintLine(TEXT("Type in your guess and press enter")); //prompt player for guess
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("\nPress enter to start again."));
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
if (Guess == HiddenWord)
{
PrintLine (TEXT("You win!"));
//+ difficulty
//On max difficulty: PlayAgain or Quit
EndGame();
return;
}
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("It's %i letters long, dummy... \nTry again!"), HiddenWord.Len());
PrintLine(TEXT("You still have %i lives left."), Lives);
return;
}
if(!IsIsogram(Guess))
{
PrintLine(TEXT("Can't have repeating letters, guess again"));
}
// If it doesn't meet requirement, GuessAgain
//Remove a life
PrintLine(TEXT("WROOOOOOONG!"));
--Lives;
if (Lives <= 0)
{
ClearScreen();
PrintLine(TEXT("You have lost!"));
PrintLine(TEXT("The hidden word was: %s"), *HiddenWord);
EndGame();
return;
}
//Show player bulls and cows
PrintLine(TEXT("Try again. You have %i lives left."), Lives);
// Which letters are in the right place?
}
bool UBullCowCartridge::IsIsogram(FString Word) const
{
for (int32 Index = 0; Index < Word.Len(); Index++)
{
for (int32 Comparison = Index + 1; Comparison < Word.Len(); Comparison++)
{
if (Word[Index] == Word[Comparison])
{
return false;
}
}
}
return true;
BullCowCartridge.h:
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Console/Cartridge.h"
#include "BullCowCartridge.generated.h"
UCLASS(ClassGroup=(Custom), meta=(BlueprintSpawnableComponent))
class BULLCOWGAME_API UBullCowCartridge : public UCartridge
{
GENERATED_BODY()
public:
virtual void BeginPlay() override;
virtual void OnInput(const FString& Input) override;
void SetupGame();
void EndGame();
void ProcessGuess(FString Guess);
bool IsIsogram(FString Word) const;
// Your declarations go below!
private:
FString HiddenWord;
int32 Lives;
bool bGameOver;
TArray<FString> Words;
};
Error I’m getting:
Not sure what’s going on here, as everything was working fine up until now. I recently created a GitHub repository to keep track of the changes I make and how I make them in my own way, but it was compiling fine until just now.