top of page

Number Wizard
This time I made Number Wizard. Number Wizard is computer will guess the number that player thinking.
I did in UNITY. This is the code of Number Wizard.
using UnityEngine;
using System.Collections;
public class NumberWizard : MonoBehaviour {
int max = 1000;
int min = 1;
int guess;
// Use this for initialization
void Start () {
guess = (max + min)/2;
print ("welcome to NumberWizard");
print ("pick number is your head, but don't tell me");
print ("The highest number that you can pick is "+ max);
print ("The lowest number that you can pick is "+ min);
print ("Up= higher, down= lower, enter= correct");
print ("My guess is:"+guess);
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown (KeyCode.UpArrow)) {
//print ("You pressed up the arrow, good job");
max = guess;
guess = (max + min) / 2;
print ("Is your number is" + guess);
}
if (Input.GetKeyDown(KeyCode.DownArrow)) {
//print ("You pressed up the arrow, good job");
min= guess;
guess = (max + min)/2;
print ("Is your number is"+guess);
}
if (Input.GetKeyDown(KeyCode.Return)) {
//print ("You pressed up the arrow, good job");
min= guess;
guess = (max + min) / 2;
print ("I guess your number is:+guess");
}
}
}
bottom of page