I need to press enter when i have 0 lives left, but I can’t find out a way after going from 1 to 0 lives to go to my else statement:
// 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();
PrintLine(TEXT("The HiddenWord is: %s. \nIt is %i Characters long"), *HiddenWord, HiddenWord.Len()); //debug Line
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
/*
if game is over ClearScreen() and SetupGame()
else check PlayerGuess
*/
if(bGameOver)
{
ClearScreen();
SetupGame();
}
else
{
ProcessGuess(Input);
}
}
void UBullCowCartridge::SetupGame()
{
HiddenWord = TEXT("bertja");
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine(TEXT("This is the BullCow Game!"));
PrintLine(TEXT("You have %i lives"), Lives);
PrintLine(TEXT("Guess the %i letter isogram"), HiddenWord.Len());
PrintLine(TEXT("Your input here, then press enter"));
// const TCHAR HW[] = TEXT("plums");
//PrintLine(TEXT("Character 1 of the hidden word is: %c"), HiddenWord[0]); // print "b"
//PrintLine(TEXT("Character 4 of the HW is: %c"), HW[3]); // print "m"
IsIsogram(HiddenWord);
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("Press enter to restart"));
}
void UBullCowCartridge::ProcessGuess(FString Guess)
{
if (Lives > 0)
{
if(Guess == HiddenWord)
{
PrintLine(TEXT("You are correct and the winner!"));
EndGame();
return;
}
if(Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("Please input a %i letter word"), HiddenWord.Len());
PrintLine(TEXT("You have %i lives left"), Lives);
return;
}
if(!IsIsogram(Guess))
{
PrintLine(TEXT("The word can't have duplicate letters\nGuess again"));
return;
}
--Lives;
PrintLine(TEXT("You Lost a life\nYou have %i Lives left"), Lives);
return;
}
else
{
ClearScreen();
PrintLine(TEXT("You lose, the hiddenword was %s"), *HiddenWord);
EndGame();
return;
}
// PrintLine(TEXT("Wrong answer\nthe hiddenword is %i letters long"), HiddenWord.Len());
// PrintLine(TEXT("You got x Bulls and x Cows"));
// PrintLine(TEXT("You have %i lives left"), Lives);
}
bool UBullCowCartridge::IsIsogram(FString Word)
{
// if Guess[all] != Guess[Word.Len() -1]
// compare the letters
// if any letter is the same return false
for (int32 Index = 0; Index < Word.Len(); Index++)
{
PrintLine(TEXT("%c"), Word[Index]);
}
return true;
}