Messing around with Bulls Cows games - possible not to repeat instatiation?

Hi there!

Arriving at the penultimate lesson of the Bulls Cows games, I really wanted to share my work here.
I also have a doubt, which arose from trying to mess around with the code, changing some stuff that was previously implemented.
Basically, I want to decrement a life if the PlayerGuess isn’t an Isogram, but I also want to show the Bulls and Cows count to the player. In this way, he’ll be able to have an idea of what to write next. At the time, I’m just repeating the structure FBullCowCount up above within the if statement in order to asess the GetBullsCows(Score). Since I have to repeat those same lines of code later in the code, I was wondering if there’s a more practical way of doing this…

Thanks in advance!

Boeser

I’m not 100% sure what you’re asking, I looked at it twice now and thought two different things to focus on.

You can make quite a few changes that you can understand and you can make changes you don’t even know about yet.

For example, you have --lives twice. You’re doing it anyway when true or false so you should be able to just move that above the 1st if and have the same result using only one mention it.

eg current is same as:

if (false) lives–;
else lives–;

VS.

lives–;

if (false) {…}

To do the same with score as well, it will work without a bug as long as the score doesn’t change between the two uses otherwise it has to be called again.

eg still needs some additional changes but just an example:

if (false) {…}

FBullCowCount score = GetBullCows(Guess);

Score can then be re-used without duplicated code. But, it depends on where you want to check for isogram and where you want to play the game, etc.

So if you change the score or want to play again, you need to make more changes if you want to call it once.

You could just return and loop again and check lives and if there’s no more left then do that and return or whatever. There’s a lot of ways to do it and everyone will think of something a little different or a lot different.

Sticking to what you have I think this should help you to see different arrangements. You can break stuff out into more functions too and that would create other arrangements.

There’s a lot of possible ways.

Privacy & Terms