#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame();
PrintLine(TEXT("The hidden word is: %s."), *HiddenWord);
}
void UBullCowCartridge::OnInput(const FString &Input) // When the player hits enter
{
if (bGameOver)
{
if (Input == "y" || "Y")
{
bPlayAgain = true;
EndGame();
}
return;
}
ClearScreen();
if (Input == HiddenWord)
{
PrintLine(TEXT("You suck! I mean.. you won.. but you still suck!"));
EndGame();
}
else
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("censored that's not even the correct amount of letters."));
PrintLine(TEXT("The hidden word is %i characters long."), HiddenWord.Len());
PrintLine(TEXT("Your guess was %i characters long."), Input.Len());
PrintLine(TEXT("Figger it out!"));
}
if (Lives > 0)
{
--Lives;
PrintLine(TEXT("Incorrect! You have %i guesses remaining."), Lives);
}
else
{
PrintLine(TEXT("You lost. censored!"));
EndGame();
}
}
}
void UBullCowCartridge::SetupGame()
{
HiddenWord = TEXT("platform");
bGameOver = false;
Lives = HiddenWord.Len();
PrintLine(TEXT("Welcome to the Bull Cow Game!"));
PrintLine(TEXT("The word is %i letters long."), HiddenWord.Len());
PrintLine(TEXT("You have %i guesses. Good luck!"), Lives);
PrintLine(TEXT("Guess and press enter to start"));
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Would you like to play again? \nEnter 'Y' for yes or 'N' for no."));
if (bPlayAgain == true)
{
ClearScreen();
SetupGame();
}
}