Canadian Number Wizard

Here’s my code for the Number Wizard. I tried to give him some Canadian flare. One thing I don’t know how to do is have 1,000 display as 1 000 which is a small detail but one I think would add to the Number Wizard’s character.

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

public class NumberWizard : MonoBehaviour
{
    int max = 1000;
    int min = 1;
    int guess = 500;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Welcome to Number Wizard bud. You come up with a number and I'll try to guess it.");
        Debug.Log("As long as your number is between " + min + " and " + max + ", we shouldn't have any issues.");
        Debug.Log("Ok bud! If you're ready, is your number " + guess + "?");
        Debug.Log("Press up if you're number is higher, down if it's lower, or enter if it's correct.");
        max = max + 1;
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            min = guess;
            guess = (max + min) / 2;
            Debug.Log("So it's higher eh? Well how about " + guess + "?");
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            max = guess;
            guess = (max + min) / 2;
            Debug.Log("So it's lower eh? Well how about" + guess + "?");
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("Good game there bud.");
        }
    }
}

2 Likes

I love the Canadian flare! :grin::clap:

1 Like

Privacy & Terms