Hey, I just completed and uploaded my version of Number Wizard UI to itch.io. Any feedback or critique or comments are appreciated! I put in some simple cheat detection, but it’s pretty limited and doesn’t cover all the cases. If anyone has ideas or fixed this themselves, I’d love to hear how you did it as I was banging my head against that brick wall for a while.
Play the game here: https://benschiffler.itch.io/number-wizard
My NumberWizard code:
/*
* Copyright (c) Ben Schiffler
* www.benschiffler.com
*/
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class NumberWizard : MonoBehaviour {
#region Variables
public int max;
public int min;
private int guess;
public Text text;
public Text rangeText;
public int maxGuessesAllowed = 12;
#endregion
#region Unity Methods
void Start () {
StartGame();
}
void StartGame()
{
min = 1;
max = Random.Range(1, 11) * 1000;
//initialize first guess
guess = Random.Range(min, max+1);
text.text = guess.ToString() + "?";
rangeText.text = "Choose a number between " + min + " and " + max + ".";
}
public void GuessHigher()
{
print("GuessHigher:: max = " + max + ", min = " + min + ", guess = " + guess);
min = guess;
NextGuess();
}
public void GuessLower()
{
print("GuessLower:: max = " + max + ", min = " + min + ", guess = " + guess);
max = guess;
NextGuess();
}
void NextGuess()
{
int prevGuess = guess;
guess = Random.Range(min, max + 1);
int tryNewOptions = 0;
while (guess == prevGuess && tryNewOptions < 10)
{
guess = Random.Range(min, max + 1);
tryNewOptions++;
}
if (min == max || min > max)
{
SceneManager.LoadScene("Cheat");
}
text.text = guess.ToString() + "?";
print("NextGuess:: max = " + max + ", min = " + min + ", guess = " + guess);
maxGuessesAllowed = maxGuessesAllowed - 1;
if(maxGuessesAllowed <= 0)
{
SceneManager.LoadScene("Win");
}
}
#endregion
}
And my LevelManager code:
using UnityEngine;
using UnityEngine.SceneManagement;
public class LevelManager : MonoBehaviour {
#region Variables
#endregion
#region Unity Methods
public void LoadLevel(string name)
{
Debug.Log("Level load requested for: " + name);
SceneManager.LoadScene(name);
}
public void QuitRequest()
{
Debug.Log("Quit requested! Good bye :)");
Application.Quit();
}
#endregion
}
Thanks, and good luck yourselves! 