Exemple #1
0
    /// <summary>
    /// Function that runs while the game is active, and creates batteries in random locations
    /// </summary>
    private IEnumerator SpawnBatteries()
    {
        // only do it while the game is active
        while (_active)
        {
            // get the position at which to spawn a battery (random)
            var positionX = UnityEngine.Random.Range(TopLeft.x, BottomRight.x);
            var positionY = UnityEngine.Random.Range(TopLeft.y, BottomRight.y);

            // get a random value of the battery - how much charge is left
            var value = SpawnItemDistributionFetcher <int> .GetRandomEnumValue(GetDistribution());

            // spawn a battery, and assign its value
            var spawned = Instantiate(BatteryPrefab, new Vector3(positionX, positionY, -3), Quaternion.identity);
            spawned.GetComponent <BatteryScript>().Initialise(value);

            // wait a random amount of time before spawning another
            yield return(new WaitForSeconds(UnityEngine.Random.Range(_minBatteryWait, _maxBatteryWait)));
        }
    }
Exemple #2
0
    /// <summary>
    /// Generates a burger with random components
    /// </summary>
    /// <returns>The constructed burger</returns>
    public static BurgerConstruction GetOrder()
    {
        BurgerConstruction burger = new BurgerConstruction();

        // bun
        var bun = GetValue_ <BunType>();

        burger.AddItem(new BurgerBun(bun));    // top of bun

        // veg - can be 0, 1, or 2 items
        var numVeg = SpawnItemDistributionFetcher <int> .GetRandomEnumValue(GetDistributionVeg_());

        for (int i = 0; i < numVeg; i++)
        {
            burger.AddItem(new BurgerVeg(GetValue_ <BurgerVegType>()));
        }

        // burger - can be 1 or 2 pattys
        var numPattys = SpawnItemDistributionFetcher <int> .GetRandomEnumValue(GetDistributionBurgers_());

        var burgerType = GetValue_ <BurgerType>();

        for (int i = 0; i < numPattys; i++)
        {
            burger.AddItem(new BurgerPatty(burgerType));
        }

        // sauce - can be 0 or 1 sauces
        var numSauce = SpawnItemDistributionFetcher <int> .GetRandomEnumValue(GetDistributionSauce_());

        for (int i = 0; i < numSauce; i++)
        {
            burger.AddItem(new BurgerSauce(GetValue_ <SauceType>(), 0));
        }

        burger.AddItem(new BurgerBun(bun));    // bottom of bun

        return(burger);
    }
Exemple #3
0
    /// <summary>
    /// Populates the ball with the attributes of a randomised shopping item
    /// </summary>
    /// <param name="ball">The script to update</param>
    public void GetFood(ShopDropBallScript ball)
    {
        // get a (semi) random shopping element
        var numValues = Enum.GetValues(typeof(FoodType)).Length;
        var value     = SpawnItemDistributionFetcher <FoodType> .GetRandomEnumValue(GetDistribution());

        var points   = 0;
        var foodName = "";
        var offset   = new Vector3(0, 0);

        // set values for points, size, and name based on the item type
        switch (value)
        {
        case FoodType.BirthdayCake:
            foodName = "Birthday Cake";
            offset   = new Vector2(0.11f, 0.11f);
            points   = 40;
            break;

        case FoodType.Gammon:
            foodName = "Gammon";
            offset   = new Vector2(0.025f, 0.025f);
            points   = 33;
            break;

        case FoodType.ChristmasPudding:
            foodName = "Christmas Pudding";
            offset   = new Vector2(-0.1f, -0.1f);
            points   = 29;
            break;

        case FoodType.Cheese:
            foodName = "Cheese";
            offset   = new Vector2(0.04f, 0.04f);
            points   = 25;
            break;

        case FoodType.Sweets:
            foodName = "Sweets";
            offset   = new Vector2(-0.09f, -0.09f);
            points   = 24;
            break;

        case FoodType.Watermelon:
            foodName = "Watermelon";
            offset   = new Vector2(.09f, .02f);
            points   = 20;
            break;

        case FoodType.WashingUpLiquid:
            foodName = "Washing-up Liquid";
            offset   = new Vector2(-0.08f, 0.06f);
            points   = 15;
            break;

        case FoodType.BreadRoll:
            foodName = "Bread Roll";
            offset   = new Vector2(-0.08f, -0.08f);
            points   = 14;
            break;

        case FoodType.Lettuce:
            foodName = "Lettuce";
            offset   = new Vector2(0f, 0f);
            points   = 12;
            break;

        case FoodType.Pineapple:
            foodName = "Pineapple";
            offset   = new Vector2(-0.05f, 0.08f);
            points   = 11;
            break;

        case FoodType.Orange:
            foodName = "Orange";
            offset   = new Vector2(-.18f, -.18f);
            points   = 10;
            break;

        case FoodType.Potato:
            foodName = "Potato";
            offset   = new Vector2(-.1f, -.1f);
            points   = 8;
            break;

        case FoodType.Sponge:
            foodName = "Sponge";
            offset   = new Vector2(-.05f, -.05f);
            points   = 5;
            break;

        case FoodType.ToiletRoll:
            foodName = "Toilet Roll";
            offset   = new Vector2(-.07f, -.07f);
            points   = 1;
            break;
        }

        // update item properties and appearance
        ball.transform.localScale += offset;
        ball.GetComponent <SpriteRenderer>().sprite = Sprites[(int)value];
        ball.Points = points;
        ball.Food   = foodName;
    }