My Number Wizard Code for Lesson/Video #13

Per the assignment… Thanks for taking a look!

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("Your computer is now trapping the soul of a Number Wizard. Please stand by...");
        Debug.Log("Number Wizard caught and consumed.");
        Debug.Log("Ready to play. Have fun!");
        Debug.Log("Pick a number between " + min + " and "+ max +".  But don't say it out loud.  The number wizard can hear you!");
        Debug.Log("Tell me if your number is higher or lower than " + guess);
        Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = 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("You picked higher.");
            Debug.Log("Is your number higher or lower than " + guess + "?");
            Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = Correct");

        } else if (Input.GetKeyDown(KeyCode.DownArrow)) {

            max = guess;
            guess = (max + min) / 2;
            Debug.Log("You picked higher.");
            Debug.Log("Is your number higher or lower than " + guess + "?");
            Debug.Log("Push Up = Higher, Push Down = Lower, Push Enter = Correct");

        } else if (Input.GetKeyDown(KeyCode.Return)) {

            Debug.Log("Enter key was pressed.");

        };
    }
}
1 Like

Awesome job! :100:

Privacy & Terms