Suggestion for preventing player to break the Guess

If the player plays the game with truly sticking to the original number in his / her mind, everything works fine. However, if the player pushes the guess to the limit and keep pressing higher and lower buttons, the guess result will become strange.
To avoid this situation, I set a simple condition to check the limit.

public void onPressHigher()
    {
        if (max != guess)
        {
            min = guess + 1;
            NextGuess();
        }
    }

    public void onPressLower()
    {
        if (min != guess)
        {
            max = guess - 1;
            NextGuess();
        }
    }
6 Likes

Looking good man! Nice job thinking about that scenario. I never knew about that bug.

1 Like

Thanks!
I always like to try breaking a game by messing around, LOL.

1 Like

Haha smart! helps you polish your game :stuck_out_tongue_winking_eye:

That is absolute genius! Thank you so much. It fixed my code wonderfully!

I didn’t know about the != operator yet, I just searched and learned that it means not equal, thank you so much! Funny enough I entered the class discussion because of the same bug I solved it differently than you but in a very similar way. Here is how I did before knowing about the != operator:

public void OnPressHigher()
{
if (max > min)
{
min = guess + 1;
}
NextGuess();
}

public void OnPressLower()
{
    if (min < max)
    {
        max = guess - 1;
    }
    NextGuess();
}
1 Like

If the random guess is at the minimum limit and the user hits lower, or if the random guess is at the maximum limit and the user hits higher, it would make a lot more sense to realize the player has either:

  1. Made a mistake somewhere or is
  2. Trolling the wizard.

Either scenario could be dealt with using another scene (possibly humorous) to ask the user if they’ve forgotten their number or w/e.

1 Like

yea i found this problem too i just did not know how to solve it…
thanks

Thanks! This helped me too. Had no idea how to tackle the bug. Great work.

Privacy & Terms