Number Wizard V1.5

This is my take on the number wizards game, i added a system which allows you to choose the maximum range the computer will search for your number in.

public class NumberWizard : MonoBehaviour {
        int max;
        int min;
        int guess;
        int maxoption;
    // Use this for initialization
    void Start () {
        print ("**************************************************");
        print ("Welcome to Number Wizard");
        print ("Select the maximum number the computer should guess to");
        print ("Press NumPad 1 to add 1000, press 2 to add 100 or press 3 to add 10");
        print ("Press Numpad ENTER to begin the game");
       
        maxoption = 0;
       
    }
   
    void StartGame (){
        print ("==================================================");
        print ("Think of a number in your head, but don't tell me!");
       
        max = maxoption;
        min = 1;
        guess = 20;
 
        print ("The highest number you can pick is " + max );
        print ("The lowest number you can pick is " + min );
       
        print ("Is your number higher, lower or equal to" + guess + "?");
        print ("Press UP arrow for higher, DOWN arrow for lower and RETURN for equal");
       
        max = max + 1;
    }
   
    // Update is called once per frame
    void Update () {
        if (Input.GetKeyDown(KeyCode.Keypad1)){
            maxoption = maxoption + 1000;
            print (maxoption);         
        }else if (Input.GetKeyDown(KeyCode.Keypad2)){
            maxoption = maxoption + 100;
            print (maxoption);
        }else if (Input.GetKeyDown(KeyCode.Keypad3)){
            maxoption = maxoption + 10;
            print (maxoption);
        }else if (Input.GetKeyDown(KeyCode.KeypadEnter)){
            StartGame();
        }
       
       
        if (Input.GetKeyDown(KeyCode.UpArrow)){
            //print("UP arrow key was pressed");
            min = guess;
            NextGuess ();
        }else if (Input.GetKeyDown(KeyCode.DownArrow)){
            //print("DOWN arrow key was pressed");
            max = guess;
            NextGuess ();
        }else if (Input.GetKeyDown(KeyCode.Return)){
            print("I Won!!!");
            Start ();
        }
    }
   
    void NextGuess (){
        guess = (max + min) / 2;
        print ("Is your number higher, lower or equal to " + guess + "?");
        print ("Press UP arrow for higher, DOWN arrow for lower and RETURN for equal");
    }
}
2 Likes