IsGameWon() without using a bool

My solution to the IsGameWon() function didn’t involve making a Boolean or checking for the number of bulls. I added a guess parameter to the function and simply did:

// Check to see if the game has been won
bool FBullCowGame::IsGameWon(FString Guess) const
{
if (Guess == MyIsogram)
{
return true;
}
else
{
return false;
}
}

Can somebody tell me whether this is worse than the method implemented by Ben? I thought that adding a new variable and changing both the SubmitValidGuess() and Reset() functions would have been much more work whereas my method was self-contained and could be made much simpler by just using

// Check to see if the game has been won
bool FBullCowGame::IsGameWon(FString Guess) const
{
return (Guess == MyIsogram)
}

By the way MyIsogram is what I called the MyHiddenWord variable

If your game works then it should be ok. I actually did a similar method comparing the guess word to my hidden word and it works the first play through but when I play again it says:
Try 1 what is your guess: Please enter a 5 letter word

Try 1 what is your guess:

So my game if you hit play again is accidentally checking the response to play again and acting like it’s a guess word. So time to fix that.

I actually came here to see if anyone else used the same method of using the IsGameWon() for the if statement. I wasn’t really paying a lot of attention but I think I saved 3 or 4 lines of code instead of using a variable. Only thing I can think of for using the variable is if there was more than one way of winning. Like in a game of Civilization.

@surge914 I would check when you’re asking if the game is won. If it is before getting the first guess from the player, my gut says it could be checking against a blank Guess from the reset.

1 Like

Hi @EpicSauce8 yea it seems to be that the game is checking a blank guess after saying yes to play again which is weird because it should be asking the user to input the guess before it does the check. As far as game won is concerned it doesn’t seem to be inflicting with anything. Thanks for your input and have a great day.

Thanks for the comments. My game works fine at the moment so I’ve left it as it is (but I haven’t yet gone on to the later lectures so it may all change again).

Privacy & Terms