Hello,
I’ve just finished the lecture on switch statements. I"m having trouble with the Try # incrementing when I type in a valid guess.
Also, when I type in a valid guess, the number of Bulls and Cows is not displayed. So, the BCGame.SubmitValidGuess() function within PlayGame is not being executed.
I added a watch to my while loop and I see that it is always showing up as “true” but I don’t know what is wrong with my CheckGuessValidity() function. I’ve pasted the code here and included a screenshot of what I’m seeing when I run the program without debugging.
Any help would be much appreicated!
Thanks,
-Ryan
EGuessStatus FBullCowGame::CheckGuessValidity(FString Guess)
{
if (Guess.length() != GetHiddenWordLength())
{
return EGuessStatus::Wrong_Wordlength;
}
else
{
return EGuessStatus::OK;
}
}
FText GetValidGuess()
{
//Asking the user to input a guess.
EGuessStatus Status = EGuessStatus::Invalid_Status;
FText Guess = “”;
do {
int32 CurrentTry = BCGame.GetCurrentTry();
std::cout << "Try:" << CurrentTry;
std::cout << ". Enter your guess:";
getline(std::cin, Guess);
EGuessStatus Status = BCGame.CheckGuessValidity(Guess);
switch (Status)
{
case EGuessStatus::Wrong_Wordlength:
std::cout << "Please enter a " << BCGame.GetHiddenWordLength() << " letter word.\n";
break;
case EGuessStatus::OK:
std::cout << "OK";
break;
case EGuessStatus::Not_Lowercase:
std::cout << "Please enter your word with lower case letters.\n";
break;
default:
break;
}
std::cout << std::endl;
} while (Status != EGuessStatus::OK);
return Guess;
}
void PlayGame()
{
BCGame.Reset();
int32 MaxTries = BCGame.GetMaxTries();
//Asking the user to input a guess and repeat back.
//TODO change for loop to a while loop.
for (int32 i = 1; i <= MaxTries; i++) {
FText Guess = GetValidGuess(); //TODO check for valid guess as well.
FBullCowCount BullCowCount = BCGame.SubmitValidGuess(Guess);
std::cout << "Bulls:" << BullCowCount.Bulls << ". Cows:" << BullCowCount.Cows << std::endl;
std::cout << "Your guess was: " << Guess << std::endl;
std::cout << std::endl;
}
//TODO summarize the game.
//state number of bulls and cows
//state win or loss
}