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();
}
}
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();
}
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:
Made a mistake somewhere or is
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.