After a break from programming, number Wizard is the first project I work on with a smile on my face. I am excited about all the challenges; I decided not to deviate too much from it, but feel free to comment, suggest changes, or ask questions about it.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class NumberWizard : MonoBehaviour {
[SerializeField] int defaultMin = 1;
[SerializeField] int defaultMax = 1000;
int minNumber;
int maxNumber;
int numberGuess { get { return (minNumber + maxNumber) / 2; } }
// Use this for initialization
void Start () {
SetupGame();
PromptIntro();
GuessUserNumber();
}
void SetupGame() {
minNumber = defaultMin;
maxNumber = defaultMax + 1;
}
void PromptIntro() {
Debug.Log("Bienvenido to the number Wizzard");
Debug.Log("Pick a number and don't tell me what it is...");
Debug.Log("The number must be between: " + minNumber + " and " + maxNumber);
}
void GuessUserNumber() {
Debug.Log("is your number: " + numberGuess + "?");
Debug.Log("Press \"Enter\" for if the answer is correct; \"Up Arrow for\" Higher than "
+ numberGuess + ", \"Down Arrow\" for Lower than " + numberGuess);
}
// Update is called once per frame
void Update () {
if (Input.GetKeyDown(KeyCode.UpArrow)) {
ProcessHigherThan();
GuessUserNumber();
} else if (Input.GetKeyDown(KeyCode.DownArrow)) {
ProcessLowerThan();
GuessUserNumber();
} else if (Input.GetKeyDown(KeyCode.Return)) {
Debug.Log("YOUR NUMBER IS " + numberGuess);
PromptRestart();
SetupGame();
PromptIntro();
GuessUserNumber();
}
}
void ProcessHigherThan() {
minNumber = numberGuess;
}
void ProcessLowerThan() {
maxNumber = numberGuess;
}
void PromptRestart() {
Debug.Log("<color=#0000ff>LETS PLAY AGAIN!</color>");
}
}