Bull & Cow Extracredit


So, Yeah This Is my Landscape, And Also I’m working on Level i’ll show you in further talk.

3 Likes

This Is my Code So far i don’t know it’s great progress or bad progress.

(<// 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(Isogram, *WordListPath, [this](const auto& word) {return ISarithm(word) && 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() * 5;//Set the Lives = Unseen
ClearGamble = false;//set bool as an false value

PrintLine(TEXT("It's :%i Letters Word"), Unseen.Len());
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”));
DefineFurtherLevel(Imagine);
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);
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;
}
}
FBullCowcount Score = GetBullAndcow(Imagine);
PrintLine(TEXT(“THE Bull is = %i And The cow is = %i”), Score.BullCount,Score.CowCount);
PrintLine(TEXT(“Game Over”));
}
void UBullCowCartridge::DefineFurtherLevel(const FString& Guess)//For next level
{

Unseen = Isogram[FMath::RandRange(0, Isogram.Num() - 1)];
PrintLine(TEXT(“The Unseen Word Is : %s”), *Unseen);
if(Guess == Unseen)
{
ClearScreen();
PrintLine(TEXT(“You Just Finish The First Level”));
PrintLine(TEXT(“Level = 1”));
DefineSecondLevel(Guess);
return;
}
}
void UBullCowCartridge::DefineSecondLevel(const FString& judge)
{
Unseen = Isogram[FMath::RandRange(0, Isogram.Num() - 1)];
PrintLine(TEXT(“The Unseen Word Is : %s”), *Unseen);
if(judge.Len() == Unseen.Len())
{
ClearScreen();
PrintLine(TEXT(“You Just Finish The Second Level”));
PrintLine(TEXT(“Level = 2”));
DefineThirdLevel(judge);
return;
}
}
void UBullCowCartridge::DefineThirdLevel(const FString& suppose)
{
Unseen = Isogram[FMath::RandRange(0, Isogram.Num() - 1)];
PrintLine(TEXT(“The Unseen Word Is : %s”), *Unseen);
for(int32 Hidden = 0 ; Hidden < Unseen.Len();Hidden)
{
if(suppose[Hidden] == Unseen[Hidden])
{
ClearScreen();
PrintLine(TEXT(“You Just Finish The Third Level”));
PrintLine(TEXT(“Level = 3”));
DefineFouthLevel(suppose);
return;
}
}
}
void UBullCowCartridge::DefineFouthLevel(const FString& assume)
{
Unseen = Isogram[FMath::RandRange(0, Isogram.Num() - 1)];
PrintLine(TEXT(“The Unseen Word Is : %s”), *Unseen);
if(assume == Unseen)
{
ClearScreen();
PrintLine(TEXT(“You Just Finish The Fourth Level”));
PrintLine(TEXT(“Level = 4”));
DefineFifthLevel(assume);
return;
}

}
void UBullCowCartridge::DefineFifthLevel(const FString& Imagine)
{
if(Imagine.Len() == Unseen.Len())
{
ClearScreen();
PrintLine(TEXT(“Congratulations You Just Finish The Game”));
PrintLine(TEXT(“Finish-Game”));
DefineConclusion();
DefineOrgenization();
return;
}

}
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(); Comparision++)
{
if (word[Clue] == word[Comparision])
{
return false;
}
}
}
return true;
}
TArray UBullCowCartridge::Justifiable(const TArray& UUList)
{
TArray VaildWords;
for (FString Tword : UUList) //comparision of another unseen words
{
if (Tword.Len() <= 8 && Tword.Len() >=4 && ISarithm(Tword))
{
VaildWords.Emplace(Tword);
}
}
return VaildWords;
}
FBullCowcount UBullCowCartridge::GetBullAndcow(const FString& Imagine) const
{
FBullCowcount Count ;
for(int32 ImagineIndex = 0; ImagineIndex < Imagine.Len() ; ImagineIndex++)
{
if (Imagine[ImagineIndex] == Unseen[ImagineIndex])
{
Count.BullCount++;
continue;
}
for(int32 UnseenIndex = 0 ; UnseenIndex < Unseen.Len() ; UnseenIndex++)
{
if(Imagine[ImagineIndex] == Unseen[UnseenIndex])
{
Count.CowCount++;
break;
}
}
}
return Count;

}>)

Privacy & Terms