here is my code
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include "HiddenWordList.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetUpGame();
}
void UBullCowCartridge::OnInput(const FString& PlayersInput) // When the player hits enter
{
if (bGameOver)
{
ClearScreen();
SetUpGame();
}
else //checking PLayer Guess
{
ProcessGuess(PlayersInput);
}
}
void UBullCowCartridge::SetUpGame()
{
//welcome the player
PrintLine (TEXT("Welcome to Bulls and Cows!!"));
HiddenWord = GetValidWords(WordList)[FMath::RandRange(0, GetValidWords(WordList).Num() - 1)];
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine (TEXT("Guess the %i letter word"), HiddenWord.Len());
PrintLine (TEXT("You have %i lives. Type in your guess"), Lives);
PrintLine (TEXT("Press enter to continue..."));//prompt player for guess
PrintLine (TEXT("The Hidden word is: %s."), *HiddenWord);//debug line
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine (TEXT("\nPress enter to play again"));
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
if (Guess == HiddenWord)
{
PrintLine (TEXT("You win!!!"));
EndGame();
return;
}
//Remove life
PrintLine(TEXT("You have lost a life."));
--Lives;
//check if its the right number of letters
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("The hidden word is %i letters long."), HiddenWord.Len());
PrintLine(TEXT("Sorry, try again. \nYou have %i lives remaining."), Lives);
}
if (Lives <= 0)
{
ClearScreen();
PrintLine(TEXT("You have no lives left."));
PrintLine(TEXT("The hidden word was %s."), *HiddenWord);
EndGame();
return;
}
//check if its an isogram
if (! IsIsogram(Guess))
{
PrintLine(TEXT("No repeating letters."));
return;
}
//show the players the bulls and cows
int32 Bulls, Cows;
GetBullCows(Guess, Bulls, Cows);
PrintLine(TEXT("You have %i bulls and %i cows"), Bulls, Cows);
}
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;
}
TArray<FString> UBullCowCartridge::GetValidWords(const TArray<FString>& Word) const
{
TArray<FString> ValidWords;
for (FString Words : Word)
{
if (Words.Len() >= 4 && Words.Len() <= 10)
{
if (IsIsogram(Words))
{
ValidWords.Emplace(Words);
}
}
}
return ValidWords;
}
void UBullCowCartridge::GetBullCows(const FString& Guess, int32& BullCount, int32&CowCount) const
{
BullCount = 0;
CowCount = 0;
// for every index of the guess is same as the index of the hidden word, bull count ++
// if not a bull was it a cow. If yes cow count ++
for (int32 GuessIndex[] = 0; int32 GuessIndex[] < Guess.Len(); GuessIndex++)
{
if (Guess[GuessIndex] == HiddenWord[GuessIndex])
{
BullCount ++;
continue
}
for (int32 HiddenIndex = 0; HiddenIndex < HiddenWord.Len(); HiddenIndex++)
{
if (Guess[GuessIndex] == HiddenWord[HiddenIndex])
{
CowCount ++;
}
}
}
}
Here is the error statement from unreal.