My GameOver(param) method

Because i made my IsGameWon() take an enum type my code for this challenge is different

void GameOver(EGameWinStatus WinConditions)
{
    if (WinConditions == EGameWinStatus::Not_Enough_Bulls)
    {
	std::cout << "the hidden word was: " << BCGAME.GetHiddenWord() << std::endl;
	std::cout << "Game is over now\n";
	std::cout << "Thanks for playing!!\n" << std::endl;
    }
    else
    {
	std::cout << "Conglaturations YOUR WINNER!!\n";
    }
}

and heres my PlayGame() method

void PlayGame()
{
    int32 MAX_TURNS = BCGAME.GetMaxTries();
    EGameWinStatus WinLoseConditions = EGameWinStatus::DEFAULT;
    do
    {	
	    FText Guess = GetValidGuess();
	    FBullCowCount BULLS_COWS = BCGAME.SubmitValidGuess(Guess);
	    std::cout << "\nYou Got " << BULLS_COWS.Bulls << " Bulls and ";
	    std::cout << BULLS_COWS.Cows << " Cows\n\n";
	    WinLoseConditions = BCGAME.IsGameWon(BULLS_COWS);
	    switch (WinLoseConditions)
	    {
	    case EGameWinStatus::Not_Enough_Bulls:
		    std::cout << "Sorry, thats incorrect\n\n";
		    break;
	    case EGameWinStatus::DEFAULT:
		    std::cout << "Something went wrong updating bull count\n";
		    break;
	    default:
		    break;
	    }
    } while ((WinLoseConditions != EGameWinStatus::Enough_Bulls) && (BCGAME.GetCurrentTry() <= MAX_TURNS));
    GameOver(WinLoseConditions);
}

I also made a random number generator to select from a list of pre determined guess words. see here
My IsGameWon method using enum class and switch

Hi,

I guess if that works then its okay for now its just you can do the same thing with fewer and cleaner lines of code I think. For this kind of program that doesn’t consist of many lines or have performance constraints if it works I guess its fine. I am just following along with the class too and clearly not a professional. The way the class does it you can have 6 easy to read lines of code that do the same thing if you format it nice.
Then you have the declaration above the main function and the PrintGameSummary(); before the return in the PlayGame function which gives you the 6 total lines.

I was trying things out, having fun learning how to use different features of the language and challenging myself as i went through section 2. I believe this particular one i use enum type for checking the bull and cows instead of bool, i challenged myself to see if i could figure it out before watching the lecture and then just kept it in my program as i went through. Just going through the course and following along doesn’t teach me everything, so i found this to be a constructive way to learn as well.

So im fully aware my code is not perfect. Its neat that you can have a look at it and see how non practical it is. My only goal here is to learn.

1 Like

This is the post where i provide in detail what i did and why. again, i was just having fun figuring out my own way to do things

Yeah that’s great. It was a creative and different approach to the challenge, and I totally agree that it helps to learn the material by doing that. It’s also great that you got it up and running with the different approach too. I just thought id respond to say my two cents and to make me a little more engaged and consistent with the course :sunglasses:

LOLZ, no problem.

Great job on making your own version of the game summary. I was actually wondering if we were going to get to the point where we are writing a word generator to pick a random word at the start of the game as I’m interested to know how they do such stuff especially since i’m fairly new to coding. My only idea on how a word generator would work is by creating a dictionary of words which would look like an array filled with a bunch of words you like to use and then (and here is the gray area I don’t know about) there would be some way to call the array and randomly pick a word from it. Hope you guys have a great day.

Privacy & Terms