Here is the My cpp file.
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
#include "HiddenWordList.txt"
#include "Misc/FileHelper.h"
#include "Misc/Paths.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
const FString WordListPath = FPaths::ProjectContentDir() / TEXT("WordList/HiddenWordList.txt");
//FFileHelper::LoadFileToStringArrayWithPredicate(UList, *WordListPath, [this](const auto& word) {return Isogram.Num() && word.Len() <= 8 && word.Len() >= 4; });
Isogram = Justifiable(UList);
Justifiable(UList);
DefineOrgenization();//declard first function
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if (ClearGamble) //declard the function under to the if statement
{
ClearScreen();//for clearscreen
DefineOrgenization();//for further approch
}
else//declard function under to the else statement
{
DefineApproach(Input);//declard approch Function
}
}
void UBullCowCartridge::DefineOrgenization()
{
PrintLine(TEXT("Appreciate To Appear as an Player"));
Unseen = Isogram[FMath::RandRange(0, Isogram.Num() - 1)];
Lives = Unseen.Len();//Set the Lives = Unseen
ClearGamble = false;//set bool as an false value
PrintLine(TEXT("It's your Lives :%i "), Lives);
PrintLine(TEXT("The Unseen Word Is :%s"), *Unseen);//Debug Line
PrintLine(TEXT("Press The Enter for Resume"));
}
void UBullCowCartridge::DefineConclusion()
{
ClearGamble = true; //declard true bool value
PrintLine(TEXT("Press Enter To Play Again "));//to print in the end
}
void UBullCowCartridge::DefineApproach(const FString& Imagine)
{
if (Imagine == Unseen) //check the correct word if it s tue than go further if it's not than play agian or exit
{
ClearScreen();//for clarscreen if one can won
PrintLine(TEXT("You are Secure"));
DefineConclusion();//to the play again
DefineOrgenization();//to the welocme player
return;
}
else
{
if (Imagine.Len() != Unseen.Len()) //check the lives and hiddenword
{
PrintLine(TEXT("Your Current Lives Is : %i"), Lives);
PrintLine(TEXT("The Unseen Word Is : %s"), *Unseen);
DefineConclusion();
return;
}
if (!ISarithm(Imagine)) //check the repiting words
{
PrintLine(TEXT("No Repeting Words"));
PrintLine(TEXT("Your Remaning Lives Is : %i"), Lives);
return;
}
PrintLine(TEXT("Don't Loose Hope"));
--Lives;
if (Lives <= 0) //if Lives is zero
{
ClearScreen();
PrintLine(TEXT("You Don't Have Any Lives"));
PrintLine(TEXT("You Loose"));
DefineConclusion();
DefineOrgenization();
return;
}
PrintLine(TEXT("Game Over"));
}
}
bool UBullCowCartridge::ISarithm(const FString& word)
{
for (int32 Clue = 0; Clue < word.Len();Clue++)//comparision the words
{
for (int32 Comparision = Clue + 1 ; Comparision < word.Len(); Clue++)
{
if (word[Clue] == word[Comparision])
{
return false;
}
}
}
return true;
}
TArray<FString> UBullCowCartridge::Justifiable(const TArray<FString>& UUList)
{
TArray<FString> VaildWords;
for (FString Tword : UUList) //comparision of another unseen words
{
if (UUList.Num() <= 8 && UUList.Num() >=4 && ISarithm(Tword))
{
VaildWords.Emplace(Tword);
}
}
return VaildWords;
}