Here’s how my code is looking like so far in the course.
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay(){ // When the game starts
Super::BeginPlay();
SetUpGame();
PrintLine(TEXT("The HiddenWord is: %s"), *HiddenWord); //Debug Line
}
void UBullCowCartridge::OnInput(const FString& Input){ // When the player hits enter
if (bGameOver) {
ClearScreen();
SetUpGame();
}
else {
HiddenWord.Len();
//Checking the PlayerGuess
if (Input == HiddenWord) {
PrintLine(TEXT("Your guess was: ")+Input);
PrintLine(TEXT("Correct! You got the hidden word and won!"));
EndGame();
}
else {
PrintLine(TEXT("Your guess was: ")+Input);
if (Input.Len() != HiddenWord.Len()) {
PrintLine(TEXT("The Hidden Word is %i characters long - try again!"), HiddenWord.Len());
}
PrintLine(TEXT("Incorrect! Game Over!"));
EndGame();
}
}
//If the game is over, ClearScreen() and SetUpGame() - Resetting the game
//Else, keep checking the PlayerGuess
}
void UBullCowCartridge::SetUpGame() {
//Welcoming the Player
PrintLine(TEXT("Hi there! Welcome to Bulls and Cows!"));
HiddenWord = TEXT("cakes");
Lives = 5;
PrintLine(TEXT("Guess the %i letter word!"), HiddenWord.Len());
PrintLine(TEXT("To begin, please press Tab to start, \ntype in your guess and hit Enter!"));
bGameOver = false;
}
void UBullCowCartridge::EndGame() {
bGameOver = true;
PrintLine(TEXT("Press enter to play again."));
}