My take on number wizard (Black Ops "Save the World" style)

I decided make my own take on how to greet the player in number wizard and began to added a few more things into the code with the limited experience I have have with c#. Here it is!

EDITED

public class NumberWizard : MonoBehaviour
{
    private int minNumber = 1;
    private int maxNumber = 1000;
    private int guess = 500;
    private int guessCount = 10;

    private bool gameStarted = false;
    private bool roundEntered = false;

    // Start is called before the first frame update
    void Start()
    {
        Debug.Log("Agent, you have just been recruited to a secret black ops unit tasked with diffusing cutting edge weaponry.");
        Debug.Log("A terrorist cell know the 'Darkened Heritance' has developed a nuclear weapon that can only be diffused by successfully stalling the onboard computer system with guessing the number within 10 tries, but over 5 failed attempts");
        Debug.Log("You must find that number between " + minNumber + " and " + maxNumber + " in order to preserve the safety of the world!" );
        Debug.Log("Press S to begin the game");
        maxNumber = maxNumber + 1;
    }

    // Update is called once per frame
    void Update()
    {
        PlayerInput();

        if(guessCount == 0)
        {
            Debug.Log("The weapon exploded, game over!");
        }
    }

    private void PlayerInput()
    {
        if(gameStarted == false)
        {
            if (Input.GetKeyDown(KeyCode.S))
            {
                Debug.Log("As you enter the final room of the enemies secret facility, you spot your objective at the other end of the room. As you approach it, the bomb comes to life with a show of lights and begins to speak...");
                Debug.Log("Systems now active, deactivation protocols inaccessible without proper authorization. Make your guess, sir!");
                Debug.Log("Press E to enter the game and save the world!");
                gameStarted = true;
            }
        }
        if(roundEntered == false && gameStarted == true)
        {
            if (Input.GetKeyDown(KeyCode.E))
            {
                roundEntered = true;
                Debug.Log("Is your number higher or lower than " + guess + "?");
                Debug.Log("Push Up Arrow = Higher, Push Down Arrow = Lower, Push Enter = Correct");
            }
        }
        else if(roundEntered == true)
        {
            if (Input.GetKeyDown(KeyCode.UpArrow))
            {
                Debug.Log("You have said the number is higher");
                minNumber = guess;
                guess = (maxNumber + minNumber) / 2;
                guessCount--;
                Debug.Log("My new guess is: " + guess + "Current guesses remaining for deactivation = " + guessCount);
            }

            else if (Input.GetKeyDown(KeyCode.DownArrow))
            {
                Debug.Log("You have said the number is lower");
                maxNumber = guess;
                guess = (maxNumber + minNumber) / 2;
                guessCount--;

                Debug.Log("My new guess is: " + guess + "Current guesses remaining for deactivation = " + guessCount);
            }

            else if (Input.GetKeyDown(KeyCode.Return))
            {
                if (guessCount < 5)
                    Debug.Log("System deactivated! World destruction has been averted!");
                else if (guessCount >= 5)
                    Debug.Log("The weapons explodes. Game Over!");
            }
        }
    }
}
1 Like

Awesome looking code!!

Privacy & Terms