#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame();
PrintLine(FString::Printf(TEXT("The hidden word is %s"), *Hiddenword));//Debug line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if(bGameOver)
{
ClearScreen();
SetupGame();
}
else//checking player guess
{
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame()
{
Hiddenword= TEXT("cabinet") ;
lives=Hiddenword.Len();
bGameOver= false;
PrintLine(TEXT("Hi There! Welcome to the game"));
PrintLine(TEXT("Guess the %i lettered word"),Hiddenword.Len());
PrintLine(TEXT("Type in your guess. \nPress enter to continue"));
PrintLine(TEXT("Number of lives left is %i"),lives);
Hiddenword= TEXT("cabinet") ;
}
void UBullCowCartridge::EndGame()
{
bGameOver=true;
ClearScreen();
}
void UBullCowCartridge::ProcessGuess(FString Input)
{
if(Input== Hiddenword)
{
PrintLine(TEXT("You Have Won !!"));
EndGame();
return;
}
/*if(!Isogram())
{
PrintLine(TEXT("There are no repeating letters"));
}*/
lives--;
PrintLine(TEXT("Lost a life"));
PrintLine(TEXT("Guess again. You have %i lives remaining"),lives);
if(Hiddenword.Len()!=Input.Len())
{
PrintLine(TEXT("Hiddenword has %i letters"),Hiddenword.Len());
return;
}
if(lives<=0)
{
PrintLine(TEXT("GAME OVER!!!"));
PrintLine(TEXT("The hidden word was %s"),*Hiddenword);
PrintLine(TEXT("\nPress Enter to continue playing"));
EndGame();
return;
}
}
This is my code.
The output is attached