Setting the bGameIsWon to false, section02_lecture43

So I’m just wondering something…

In int main we do the loop to get PlayGame() going.

int main(){
    PrintIntro();
    do {
        PlayGame();
    }while (AskToPlayAgain() == true);
}

Inside of PlayGame we call BCGame.Reset()

void PlayGame() {

BCGame.Reset();

inside of BCGame.Reset() we set bIsGameWon to false;

void FBullCowGame::Reset()
{

	constexpr int32 MAX_TRIES = 8;
	const FString HIDDEN_WORD = "antlers";
	bIsGameWon = false;

Because we set bIsGameWon to false in Reset() that gets called everytime we want to play the game again; We dont have to set in anywhere else.
Why set the bIsGameWon to false every time we make a guess that is of the correct length and as long the counter is not the same as WordLength?

if (BullCowCount.Bulls == MyHiddenWord.length()) {
		bIsGameWon= true;
	}
else{
    BIsGameWon = false;
}

Makes no sense at this point of the game astleast.

Cheers!

1 Like

You’re right, no need to set bIsGameWon to false on every guess attempt

I agree. The initial state is well defined, so you probably wouldn’t touch the variable if you don’t have to, and it looks cleaner. Also, the statement may be confusing to other programmers because they could assume it was not initialized properly.

Privacy & Terms