Overall, really enjoy the way the information is being presented. I maybe should have skipped this unit overall for lack of Unity interaction. Great energy and humor. I got a little carried away and was done with all the coding coming out of the first keyboard command challenge. Keep it up!
Overall, just a couple minor differences in the finished product.
PS: to declare and initialize an integer “Score” (Quiz: question 2 I think it was), none of the options are technically correct given the case sensitivity of the language. Nothing too serious.
using UnityEngine;
public class NumberWizard : MonoBehaviour
{
private int _guess, _minimum, _maximum;
private System.Timers.Timer _keyTimer = new System.Timers.Timer(250);
// Use this for initialization
void Start()
{
_keyTimer.AutoReset = false;
StartGame();
}
void StartGame()
{
_minimum = 1;
_maximum = 1000;
Debug.Log("Welcome to Number Wizard! Ready for a game?");
Debug.Log("Please pick a number. Keep it secret!");
Debug.Log("The lowest available number is " + _minimum + ".");
Debug.Log("The highest available number is " + _maximum + ".");
NewGuess();
_maximum += 1;
}
// Update is called once per frame
void Update()
{
if (!_keyTimer.Enabled)
{
if (Input.GetKeyDown(KeyCode.UpArrow))
{
_minimum = _guess;
NewGuess();
}
else if (Input.GetKeyDown(KeyCode.DownArrow))
{
_maximum = _guess;
NewGuess();
}
else if (Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter))
{
Debug.Log("The Number Wizard wins again! Let's play another game!");
StartGame();
}
else if (Input.anyKeyDown)
{
Debug.Log("You've made an invalid selection. Please use (Up) (Down) or (Enter)!");
}
}
else Debug.Log("Don't be in such a hurry!");
}
void NewGuess()
{
_guess = (_minimum + _maximum) / 2;
Debug.Log("Is your number higher or lower than " + _guess + "?");
Debug.Log("Keyboard Controls: (Up) Higher, (Down) Lower, (Enter) Correct.");
}
}