Number Wizard Greeting

Hello! I’m trying the Unity 2D course again after falling off a couple of years ago (and falling off again in December, though I didn’t get very far that time). Here’s my Number Wizard work, which also reflects the rest of the Number Wizard Console lectures. I’ve gone for a more grandiose and wordy Wizard than in Rick’s project:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour
{
    int max;
    int min;
    int guess;

    // Start is called before the first frame update
    void Start()
    {
        StartGame();
    }

    void StartGame()
    {
        max = 1000;
        min = 1;
        guess = 500;

        Debug.Log("I am the Number Wizard! I have total mastery of all numbers between " + min + " and " + max + "!");
        Debug.Log("I challenge you to think of a number that I cannot guess!");
        Debug.Log("Please do not think of a number higher than " + max + ".");
        Debug.Log("Similarly, please do not pick a number lower than " + min + ".");
        Debug.Log("For each guess I make, push the up arrow if your number is higher, or the down arrow if it's lower.");
        Debug.Log("Else, press Enter to tell me that I'm right.");
        Debug.Log("I declare that your number is " + guess + "!");
        max = max + 1;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("Your number is higher?");
            min = guess;
            NextGuess();
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Your number is lower?");
            max = guess;
            NextGuess();
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("The Number Wizard always wins!!! (given enough guesses)");
            StartGame();
        }
    }

    void NextGuess()
    {
        guess = (max + min) / 2;
        Debug.Log("Then I declare that your number is " + guess + "!");
    }
}

Privacy & Terms