Not depricating a chance for Isogram but am for length (they were told straight off). I think it makes more sense to do a positive Isogram check but we’ll see when we get there. Right now it doesn’t make sense how it is.
void UBullCowCartridge::BeginPlay()
{
Super::BeginPlay();
InitGame();
}
void UBullCowCartridge::OnInput(const FString& Input) // When the player hits enter
{
if (bGameOver)
{
ClearScreen();
InitGame();
}
else
{
GuessEval(Input);
}
}
void UBullCowCartridge::InitGame()
{
PrintLine(TEXT("This is a game called Bull/Cows.\nIt's about guessing a word."));
HiddenWord = TEXT("money");
Lives = HiddenWord.Len();
bGameOver = false;
PrintLine(TEXT("You have %i chances\nYour word has %i letters"),Lives ,HiddenWord.Len());
// Prompt for PLayerGuess
PrintLine(TEXT("Make your guess:"));
}
void UBullCowCartridge::EndGame()
{
bGameOver = true;
PrintLine(TEXT("\n\n Press Enter to play again."));
// ask for another go
}
void UBullCowCartridge::GuessEval(FString Guess)
{
if (Guess == HiddenWord)
{
ClearScreen();
PrintLine(TEXT("YEP! Thats right and with %i chances left!"), Lives);
EndGame();
return;
}
else
{
if (!IsIsogram(Guess))
{
PrintLine(TEXT("Your word does not have repeating letters.")); //replace with positive check
return;
}
--Lives;
if (Lives > 1)
{
PrintLine(TEXT("Nope, nice try though\nChance Lost\nRemaining chances: %i"), Lives);
}
if (Lives == 1)
{
PrintLine(TEXT("Ok, settle down\nThis is your LAST CHANCE"));
}
if (Lives == 0)
{
ClearScreen();
PrintLine(TEXT("I see you are all out of chances.\nGAME OVER!\nThe word you were looking for was: %s."), *HiddenWord);
EndGame();
return;
}
}
if (Guess.Len() != HiddenWord.Len())
{
PrintLine(TEXT("Related - didn't I say it is %i characters?"), HiddenWord.Len());
}
}
bool UBullCowCartridge::IsIsogram(FString Word)
{
/*For Each letter
Start at element[0]
Compare to next char
Until we reach [Word.Len() -1]
if repeating letters return false*/
return true;
}