Something I added that I thought was quite cool, let me know if it’s stupid or wrong!
So I wanted to let the user know how many tries it took them to win, so I added this code:
void PrintGameSummary()
{
if (BCGame.IsGameWon())
{
if (BCGame.GetCurrentTry() == 1)
{
std::cout << "Congratulations, you got it! It only took you " << BCGame.GetCurrentTry() << " try." << std::endl;
std::cout << std::endl;
}
else
{
std::cout << "Congratulations, you got it! It only took you " << BCGame.GetCurrentTry() << " tries." << std::endl;
std::cout << std::endl;
}
}
else
{
std::cout << "Bad luck, you've exceeded your tries. Maybe have another go!" << std::endl;
std::cout << std::endl;
}
return;
}
Is it better to do that compare in a switch statement maybe?
As a result of this I noticed an issue in that MyCurrentTry was incrementing at the very start of the SubmitValidGuess method, which meant that the game thought you were on turn 2 even if you won on the first go. To resolve this I move the MyCurrentTry++ down to the if statement at the end:
if (BullCowCount.Bulls == WordLength)
{
bGameIsWon = true;
}
else
{
bGameIsWon = false;
// increment the try number
MyCurrentTry++;
}