// 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("Text File/HiddenWordList.txt");
FFileHelper::LoadFileToStringArray(Words, *WordListPath);
UBullCowCartridge::InitGame();
/*for (int32 i = 0; i < 5; ++i)
{
PrintLine(TEXT("%s"), *Words[i]);
}*/
//PrintLine(TEXT("The hidden word is %s"), *HiddenWord);
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
ClearScreen();
CheckGuess(Input);
}
void UBullCowCartridge::InitGame()
{
ValidWords = GetValidWords(Words);
HiddenWord = TEXT("machines");
HWLength = HiddenWord.Len();
Lives = HWLength;
bGameOver = false;
PrintLine(TEXT("The number of possible words is %i"), ValidWords.Num());
PrintLine(TEXT("Moo!"));
PrintLine(TEXT("Guess the %i letter word"), HWLength); //Remove hard coded number
PrintLine(TEXT("Type in your guess and press enter\nLives: %i"), Lives);
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("\nPress Enter to continue"));
}
bool UBullCowCartridge::IsIsogram(const FString& Check) const
{
for (int32 i = 0; i < InpLength; ++i)
{
for (int32 j = i + 1; j < InpLength; ++j)
{
if (Check[i] == Check[j])
{
return false;
}
}
}
return true;
}
void UBullCowCartridge::CheckGuess(const FString& Check)
{
InpLength = Check.Len();
if (bGameOver)
{
ClearScreen();
InitGame();
return;
}
if (Check == HiddenWord)
{
PrintLine(TEXT("You win!"));
EndGame();
return;
}
if (InpLength != HWLength)
{
PrintLine(TEXT("Incorrect guess, try again.\nLives: %i"), Lives);
PrintLine(TEXT("The hidden word is %i characters long"), HWLength);
return;
}
if (!IsIsogram(Check))
{
PrintLine(TEXT("No repeating letters! Try again!"));
return;
}
--Lives;
PrintLine(TEXT("You've lost a life!\nLives: %i"), Lives);
if (Lives <= 0)
{
ClearScreen();
PrintLine(TEXT("You have no lives left"));
PrintLine(TEXT("The hidden word was: %s"), *HiddenWord);
EndGame();
return;
}
}
TArray<FString> UBullCowCartridge::GetValidWords(TArray<FString> Starter) const
{
for (int i = 0; i < Starter.Num(); ++i)
{
if (Starter[i].Len() >= 4 && Starter[i].Len() <= 8)
{
ValidWords.Emplace(Starter[i]);
}
}
return ValidWords;
}
The error: ‘int TArray<FString,FDefaultAllocator>::Emplace<FString&>(FString &)’: cannot convert ‘this’ pointer from ‘const TArray<FString,FDefaultAllocator>’ to ‘TArray<FString,FDefaultAllocator> &’
I’m not see where I’m allegedly using a pointer.