Number Wizard - wanted to share this code

Just watched the tutorial today and just gave a try…
Just started my Game Dev Journey…

public class NumberWizard : MonoBehaviour
{
    int flag = 0;
    int maxNum;
    int minNum;
    int guess;

    // Start is called before the first frame update
    void Start()
    {
        RunGame();
    }

    void ResetValues()
    {
        maxNum = 1000;
        minNum = 1;
        guess = 500;
    }

    void RunGame()
    {
        if (flag == 0)
        {
            ResetValues();
            Debug.Log("\t!!!Namaste!!!\nWelcome to Akinator's Cheap Version!....");
            Debug.Log("I am 'Wizard'.....my only power is to guess numbers...pretty lame :c");
            Debug.Log("Don't give me that look..." + 
                "\nThink of a number between 1 to 1000 cause my Maths is weak ....and don't tell me about it");
            Debug.Log($"By the way I am pro at this but lets start with {guess}");
            Debug.Log($"If {guess} is your number -----> Hit Enter\nIf number is lower -----> Hit Up Arrow Key");
            Debug.Log("Or Number is higher -----> Hit Down Arrow Key");
            maxNum += 1;
            flag++;
        }
        else if (flag >=1 && flag <= 5)
        {
            ResetValues();
            Debug.Log("You are enjoying this don't you, but I am not.. let's guess another number\n Rules are same");
            maxNum += 1;
            flag++;
        }
        else if (flag > 5)
        {
            ResetValues();
            Debug.Log("That's enough ....are you not bored with it ?? .....Go home have a life....\n Watch next Unity Tutorial of GameDev.Tv ");
            maxNum += 1;
        }
    }
    
    void NextGuess()
    {
        guess = (maxNum + minNum) / 2;
        Debug.Log($"I know I am right... This is your number {guess}.....isn't it ohh mannn ????........");
    }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.Return))
        {
            if (flag == 0)
            {
                Debug.Log($"Really you choose {guess} Give me a challenge :)");
                RunGame();
            }
            else
            {
                Debug.Log("hhhhhh Got Em ");
                RunGame();
            }
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            maxNum = guess;
            NextGuess();
        }
        else if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            minNum = guess;
            NextGuess();
        }


    }
}

1 Like

Congratulations on starting your journey! I can’t wait to see what else you share on your journey.

1 Like

Thank you Kevin for your reply!..it means a lot to me…

Privacy & Terms