Number Wizard :

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("Howdy stranger, welcome to number wizard");
    Debug.Log("In this game, think of a number between 1 and 1000");
    Debug.Log("And I'll try to guess what it is");      
    Debug.Log("Then you tell me if the number you picked is higher or lower than my guess");
    Debug.Log("Push the up arrow key if your number is higher than my guess");
    Debug.Log("If my guess is lower, push the down arrow key");
    Debug.Log("If my guess is correct, push the enter key!");
    Debug.Log("Okay then, are you ready? Lets get started!");
    Debug.Log("Is it higher or lower than " + guess);
    max = max + 1;
}

// Update is called once per frame
void Update()
{
    if (Input.GetKeyDown(KeyCode.UpArrow))
    {
        Debug.Log("So it's higher than " + guess);
        min = guess;
        guess = (max + min) / 2;
        Debug.Log("is it " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.DownArrow))
    {
        Debug.Log("So it's lower than " + guess);
        max = guess;
        guess = (max + min) / 2;
        Debug.Log("Is it " + guess);
    }
    else if (Input.GetKeyDown(KeyCode.Return))
    {
        Debug.Log("Hah, I got it!");
        Debug.Log(":D");
        Debug.Log("I knew it was only a matter of time!");
    }
}

}

2 Likes

Awesome job!

Nice work especially with the story in the beginning of your project!
Only one thing to change if you want… In the end when player click Enter,
I think you should add " + guess" after “I got it” or something like Debug.Log("Hah, I got it! Your number is " + guess + “!”), so players actually see the number! Good job anyway! :slight_smile:

1 Like

Privacy & Terms