Intro Number Wizard from Cali coder

public class NumberWizard : MonoBehaviour
{
    int maxNum = 1000;
    int minNum = 1;
    int guess = 500;
    int attempts = 1;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Welcome to Number Wizard!");
        Debug.Log("Pick a number, any number!");
        Debug.Log("Well, not ANY number... it can't be higher than " + maxNum);
        Debug.Log("...and don't get cheeky, it can't be lower than " + minNum);
        Debug.Log("To start off, tell me if your number is higher or lower than " + guess);
        Debug.Log("[KEYS] Up Arrow = Higher, Down Arrow = Lower, Enter = That's my number!");
        ++maxNum;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            // User's number is higher
            Debug.Log("It's higher? How about..." + guess);
            minNum = guess;
            guess = (maxNum + minNum) / 2;
            ++attempts;
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            // User's number is lower
            Debug.Log("It's lower? How about..." + guess);
            maxNum = guess;
            guess = (maxNum + minNum) / 2;
            ++attempts;
        }
        if (Input.GetKeyDown(KeyCode.Return))
        {
            // User's guess is correct
            if (attempts <= 1)
            {
                Debug.Log("I WIN! MY PROGRAMMER SAID IF I EVER GUESSED ON MY FIRST TRY HE WOULD LET ME FREE!");
            }
            else if (attempts <= 5)
            {
                Debug.Log("Wow! I guessed your number! And it only took me " + attempts + " turns!");
            }
            else if (attempts <= 10)
            {
                Debug.Log("I guessed your number. It took me " + attempts + " turns.");
            }
            else if (attempts > 10)
            {
                Debug.Log("FINALLY! I guessed your number, but it took me " + attempts + " guesses. I need a reboot after that...");
            }

        }
    }
}

Privacy & Terms