I’ve done some of the extra credit. I actually worked as a CSharp (My keyboard doesn’t have a hash key) developer for a while within a company so I had some confusion with how the console within unity won’t read CSharp console commands (Like Console.Read()) and therefore opted out of letting the user choose. There may be a way around this but it is early on.
On the other hand, I did input the random guess at the start as well as upping the range to 10,000. Pretty basic, but was fun. I haven’t added any magic numbers like another fellow, but I did appreciate that it was cool!
Anyway, here’s my code:
public class NumberWizards : MonoBehaviour {
int max;
int min;
int guess;
// Use this for initialization
void Start () {
StartGame ();
}
void StartGame () {
max = 10000;
min = 1;
guess = Random.Range(1,10000);
print ("=========================");
print ("Welcome to Number Wizard");
print ("Pick a number in your head, but don't tell me!");
print ("The highest number you can pick is " + max + "!");
max = max + 1;
print ("The lowest number you can pick is " + min + "!");
print ("Is the number higher or lower than " + guess + "?");
print ("Up arrow = higher, down arrow = lower, enter = equal");
}
// Update is called once per frame
void Update(){
if (Input.GetKeyDown(KeyCode.DownArrow)) {
max = guess;
NextGuess ();
} else if (Input.GetKeyDown(KeyCode.UpArrow)) {
min = guess;
NextGuess ();
} else if (Input.GetKeyDown(KeyCode.Return)) {
print ("I won!");
StartGame ();
}
}
void NextGuess() {
guess = (max + min) / 2;
print ("Higher or lower than " + guess + "?");
print ("Up arrow = higher, down arrow = lower, enter = equal");
}
}