Created
December 13, 2015 13:23
-
-
Save tinyhappysteps/497af1832681af67b232 to your computer and use it in GitHub Desktop.
Improved number wizard -- unity
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class NumberWizards : MonoBehaviour { | |
int max = 1000; | |
int min = 1; | |
int guess = 500; | |
// Use this for initialization | |
void Start () { | |
StartGame(); | |
} | |
// Update is called once per frame | |
void Update () { | |
if (Input.GetKeyDown(KeyCode.UpArrow)) { | |
min = guess; | |
NextGuess(); | |
} else if (Input.GetKeyDown(KeyCode.DownArrow)) { | |
max = guess; | |
NextGuess(); | |
} else if (Input.GetKeyDown(KeyCode.Return)) { | |
print("I won!"); | |
StartGame(); | |
} | |
} | |
void NextGuess () { | |
guess = (min + max) / 2; | |
print ("Is the number higher or lower than " + guess); | |
} | |
void StartGame () { | |
max = 1000; | |
min = 1; | |
guess = 500; | |
print ("========="); | |
print ("Welcome to Number Wizard"); | |
print ("Pick a number in your head and don't tell me!"); | |
print ("The highest number you can pick is " + max); | |
print ("The lowest number you can pick is " + min); | |
print ("Is the number higher or lower than " + guess); | |
print ("Up = higher, down = lower, return = equals"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment