So I just completed lecture 60 and I am facing a problem with my code
// Fill out your copyright notice in the Description page of Project Settings.
#include "BullCowCartridge.h"
void UBullCowCartridge::BeginPlay() // When the game starts
{
Super::BeginPlay();
SetupGame(); // Setting Up Game
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 // Checking Player Guess
{
if (Input == HiddenWord)
{
PrintLine (TEXT("You Win!")); // Winning Message
EndGame();
}
else
{
PrintLine(TEXT("Lost a life!"));
PrintLine(TEXT("%i"), --Lives);
if (Lives > 0)
{
if (Input.Len() != HiddenWord.Len())
{
PrintLine(TEXT("Sorry, try guessing again! \nYou have %i lives remaining"), Lives);
}
else
{
PrintLine(TEXT("You have no lives left!"));
EndGame();
}
}
}
}
}
// Need Not To Be Case Sensitive
// Check If Isogram
// Prompt To Guess Again
// Check Number Of Letters
// Prompt To Guess Again
// Remove Life
// Check If Lives > 0
// If Yes, GuessAgain
// Show Remaining Lives
// If No, Print Loosing Message and HiddenWord?
// Prompt To Restart, Press Enter To PlayAgain
// Check User Input
// PlayAgain Or Quit
void UBullCowCartridge::SetupGame()
{
// Welcome Message
PrintLine (TEXT("Howdy Farmer! Welcome to Bulls & Cows game"));
HiddenWord = TEXT("game");
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine (TEXT("Guess the %i letter word!"), HiddenWord.Len());
PrintLine (TEXT("You have %i lives"), Lives);
PrintLine (TEXT("Type in your guess and \npress ENTER to continue...")); // Prompt Player For Guess
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press enter to restart."));
}
When I run my code my lives just start depreciating below 0 whereas I have an else function which tells the game to stop if lives is less than 0. How to solve this?