A British style number wizard... so far

So, this is the code

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class NumberWizard : MonoBehaviour
{
    int max = 1000;
    int min = 1;
    int guess = 500;

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

        Debug.Log("Hello there.");
        Debug.Log("Have a cuppa tea and take a biscuit.");
        Debug.Log("I am going to ask you to play a game...");
        Debug.Log("Pick a number, any number:");
        Debug.Log("The highest number you can pick is: " + max);
        Debug.Log("The lowest number you can pick is:" + min);
    }

    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.DownArrow))
        {
            Debug.Log("Lower...!!");
            max = guess;
            guess = (max + min) / 2;
            Debug.Log(guess);
        }
        else if (Input.GetKeyDown(KeyCode.UpArrow))
        {
            Debug.Log("Higher...!!");
            min = guess;
            guess = (max + min) / 2;
            Debug.Log(guess);
        }
        else if (Input.GetKeyDown(KeyCode.LeftArrow))
        {
            Debug.Log("Left arrow was pressed.");

        }
        else if (Input.GetKeyDown(KeyCode.RightArrow))
        {
            Debug.Log("Right arrow was pressed.");
        }
        else if (Input.GetKeyDown(KeyCode.Return))
        {
            Debug.Log("...Just right.");
        }
        else if (Input.GetKeyDown(KeyCode.Space))
        {
            Debug.Log("Space key was pressed.");
        }
    }
}
3 Likes

Great job :+1:

1 Like

:+1: Great! I would add " + guess" for when player click enter, so player can see the number, but this is only suggestion! Keep going! :slight_smile:

Privacy & Terms