Okay so… first I added some more Error status to handle different scenarios.
// Errors handling
enum class EGuessStatus
{
Invalid_Status,
OK,
Is_Empty,
Invalid_Character,
Has_Space_Character,
Not_Isogram,
Wrong_Lenght,
Not_Lowercase
};
Then added them to CheckGuessValidity()…
// Check if the GuessWord is valid and returns various error states
EGuessStatus FBullCowGame::CheckGuessValidity(FString GuessWord) const
{
if (GuessWord.empty())
{
return EGuessStatus::Is_Empty;
}
else if (HasSpace(GuessWord))
{
return EGuessStatus::Has_Space_Character;
}
else if (HasInvalidChar(GuessWord))
{
return EGuessStatus::Invalid_Character;
}
else if (GetHiddenWordLenght() != GuessWord.length())
{
return EGuessStatus::Wrong_Lenght;
}
else if (!IsIsogram(GuessWord))
{
return EGuessStatus::Not_Isogram;
}
else if (!IsLowercase(GuessWord))
{
return EGuessStatus::Not_Lowercase;
}
else
{
return EGuessStatus::OK;
}
}
and added the needed functions…
private:
bool IsLowercase(FString) const;
bool HasSpace(FString) const;
bool HasInvalidChar(FString) const;
defined and made the logic…
// I found usefull stuff for the string methods here http://en.cppreference.com/w/c/string/byte/isblank
bool FBullCowGame::HasSpace(FString GuessWord) const
{
for (auto Letter : GuessWord)
{
if (isspace(Letter))
{
return true;
}
}
return false;
}
bool FBullCowGame::HasInvalidChar(FString GuessWord) const
{
for (auto Letter : GuessWord)
{
if (iscntrl(Letter) || ispunct(Letter) || isdigit(Letter))
{
return true;
}
}
return false;
}
bool FBullCowGame::IsLowercase(FString GuessWord) const
{
for (auto Letter : GuessWord)
{
if (!islower(Letter))
{
return false;
}
else
{
return true;
}
}
return true;
}
and finally made the output!
case EGuessStatus::Not_Lowercase:
std::cout << "Oops! Your word contains some uppercase letters. Please enter all lowercase letters.\n\n";
break;
case EGuessStatus::Is_Empty:
std::cout << "Oops! You didn't enter a word. Please type some letters.\n\n";
break;
case EGuessStatus::Has_Space_Character:
std::cout << "Oops! You word contains a space. Please type the word again.\n\n";
break;
case EGuessStatus::Invalid_Character:
std::cout << "Oops! You word contains an invalid character. Please type the word again.\n\n";
break;
…and incredibly everything works!
wow! much code!
Just sharing my happiness 