#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay(); //Required for the game to start
SetupGame();
//PrintLine(TEXT("The hidden word is: %s"), *HiddenWord); //Debug line
IntroMessage();
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
//PrintLine(Input); //Debug Line
if(bGameOver == true)
{
ClearScreen();
SetupGame();
IntroMessage();
}
else
{
if(HiddenWord.Len() != Input.Len())
{
ClearScreen();
PrintLine(TEXT("Your word %s is the wrong length."), *Input);
PlayerGuess();
}
else
{
if(Input == HiddenWord)
{
ClearScreen();
PrintLine(TEXT("Great job you guessed %s which is right"), *Input);
bGameOver = true;
EndGame();
}
else
{
if(Lives>1)
{
ClearScreen();
--Lives;
PrintLine(TEXT("You guessed %s and that is wrong."), *Input);
PlayerGuess();
}
else
{
ClearScreen();
PrintLine(TEXT("You have guessed wrong to many times"));
bGameOver = true;
EndGame();
}
}
}
}
//check if its isogram if it is not route to guess again function with cause
}
void UBullCowCartridge::SetupGame()
{
HiddenWord = TEXT("House"); //need hidden word list
Lives = 4;
bGameOver = false;
}
void UBullCowCartridge::IntroMessage()
{
PrintLine(TEXT("Welcome friend I bet you have come to win \nthe pasture teasure. I will tell you after"));
PrintLine(TEXT("you win my challenage"));
PrintLine(TEXT("I am thinking of an Isogram you must \nguess it right in %i trys."), Lives);
PrintLine(TEXT("The word is %i characters long"), HiddenWord.Len());
PrintLine(TEXT("Good Luck what do you think the word is?"));
}
void UBullCowCartridge::PlayerGuess()
{
PrintLine(TEXT("You have %i tries left"), Lives);
PrintLine(TEXT("The word is %i charcaters long"), HiddenWord.Len());
PrintLine(TEXT("What do you think the word is"));
}
void UBullCowCartridge::EndGame()
{
PrintLine(TEXT("would you like to try and find the \ntreasure again?"));
PrintLine(TEXT("Press enter to continue"));
}
2 Likes
How are you enjoying C++?
I am having a lot of fun with C++. I have done work with blueprints a bit and C++ but feel i have better control and ability with C++ over blueprint.