int max = 1000;
int min = 1;
int guess = 500;
// Start is called before the first frame update
void Start()
{
Debug.Log("Welcome to my humble lab I am the Number Wizard");
Debug.Log("Pick a number, don't tell me what it is... between" + max + "and" + min);
Debug.Log("Lets begin, is your number higher or lower than: " + guess);
Debug.Log("Arrow Up = Higher, Arrow Down = Lower, and 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("So your number is higher? How about: " + guess);
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
guess = (max + min) / 2;
Debug.Log("So your number is lower? How about: " + guess);
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log("Ahha I've guessed it correctly. I am the ALL KNOWING WIZARD!);
1 Like
Hello All,
Greating from india to all
Hi fellow coding students, here are my Number Wizard greetings:
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("Bonjour my friend, and welcome to Number Wizard!");
Debug.Log($"Pick a secret number between {min} and {max} and the wizard will use its wizardry skills to guess your number.");
Debug.Log($"Let's get started with a very important question:");
Debug.Log($"is your secret number higher or lower than {guess}?");
Debug.Log($"Up Arrow = higher, Down Arrow = lower, Enter = My number is {guess}!");
max = max + 1;
}
// Update is called once per frame
void Update()
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
min = guess;
guess = (max + min) / 2;
Debug.Log($"Is your number higher or lower than {guess}");
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
max = guess;
guess = (max + min) / 2;
Debug.Log($"Is your number higher or lower than {guess}");
}
else if (Input.GetKeyDown(KeyCode.Return))
{
Debug.Log($"The wizard has spoken: your secret number is {guess}!");
}
}
}