Example #1
0
    public static RandomRecipe GetInstance()
    {
        if (_instance == null)
        {
            _instance = new RandomRecipe();
        }

        return(_instance);
    }
Example #2
0
    public void NewRecipe()
    {
        var sb  = new StringBuilder();
        var rnd = RandomRecipe.GetInstance();

        rnd.GenerateRandomRecipe();
        recipeHeader.text = rnd.randomRecipe.Name;

        foreach (var ingredient in rnd.randomRecipe.Ingredients)
        {
            sb.Append(ingredient.Number + " x " + ingredient.Name + "\n");
        }

        recipeIngredients.text = sb.ToString();
    }
Example #3
0
    private bool IsInventoryCorrect(GameObject[] inventory)
    {
        if (!IsInventoryFull(inventory))
        {
            return(false);
        }

        var rnd = RandomRecipe.GetInstance();
        Dictionary <string, int> inventoryIngreds = new Dictionary <string, int>();

        foreach (var item in inventory)
        {
            if (!IsIngredientsContains(rnd.randomRecipe, item.GetComponent <SpriteRenderer>().sprite.name))
            {
                return(false);
            }

            if (inventoryIngreds.ContainsKey(item.GetComponent <SpriteRenderer>().sprite.name))
            {
                inventoryIngreds[item.GetComponent <SpriteRenderer>().sprite.name] += 1;
            }
            else
            {
                inventoryIngreds.Add(item.GetComponent <SpriteRenderer>().sprite.name, 1);
            }
        }

        foreach (var rndItem in rnd.randomRecipe.Ingredients)
        {
            if (inventoryIngreds[rndItem.Name] != rndItem.Number)
            {
                return(false);
            }
        }

        return(true);
    }
    //Handles random recipe
    private void GetRandomrecipe(int CatId)
    {
        //Instantiate random recipe database field
        RandomRecipe Recipe = new RandomRecipe();

        Recipe.CatID = CatId;
        Recipe.fillup();

        LinkRanName.NavigateUrl = "~/recipedetail.aspx?id=" + Recipe.ID;
        LinkRanName.Text        = Recipe.RecipeName;
        LinkRanName.ToolTip     = "View " + Recipe.RecipeName + " recipe";

        LinkRanCat.NavigateUrl = "~/category.aspx?catid=" + Recipe.CatID;
        LinkRanCat.Text        = Recipe.Category;
        LinkRanCat.ToolTip     = "Browse " + Recipe.Category + " category";

        lblranhits.Text = Recipe.Hits.ToString();

        ranrateimage.ImageUrl = Utility.GetStarImage(Recipe.Rating);
        lblvotes.Text         = Recipe.NoRates;

        //Release allocated memory
        Recipe = null;
    }
Example #5
0
    private void RemoveItemsFromInventory()
    {
        dumpAudio.Play();
        var rnd = RandomRecipe.GetInstance();

        foreach (var item in inventoryItems)
        {
            if (item.GetComponent <SpriteRenderer>().sprite != null)
            {
                var itemSpriteName = item.GetComponent <SpriteRenderer>().sprite.name;
                if (!IsIngredientsContains(rnd.randomRecipe, itemSpriteName))
                {
                    item.GetComponent <SpriteRenderer>().sprite = null;
                }
                else
                {
                    var number = NumberOfIngredient(rnd.randomRecipe, itemSpriteName);
                    var temp   = 0;
                    foreach (var item2 in inventoryItems)
                    {
                        if (item2.GetComponent <SpriteRenderer>().sprite != null)
                        {
                            if (item2.GetComponent <SpriteRenderer>().sprite.name == itemSpriteName)
                            {
                                temp++;
                                if (temp > number)
                                {
                                    item2.GetComponent <SpriteRenderer>().sprite = null;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
        public async Task <RandomRecipe> GenerateRandomRecipe()
        {
            RandomRecipe  deliciousRecipe = new RandomRecipe();
            List <string> dishes          = GetRecipeTypes();
            List <string> ingredients     = await ImportIngredientList();

            Random rand = new Random();

            int numberOfIngredients             = rand.Next(4, 7);
            List <Ingredient> chosenIngredients = new List <Ingredient>();

            for (int i = 0; i < numberOfIngredients; i++)
            {
                chosenIngredients.Add(new Ingredient {
                    Text   = ingredients[rand.Next(ingredients.Count())],
                    Weight = RoundUp(rand.Next(2000))
                });
            }
            deliciousRecipe.Ingredients = chosenIngredients;
            deliciousRecipe.Name        = deliciousRecipe.Ingredients[0].Text + " and " + deliciousRecipe.Ingredients[1].Text + " " + dishes[rand.Next(dishes.Count())];
            deliciousRecipe.Image       = await SearchGoogleForImage(deliciousRecipe.Name);

            return(deliciousRecipe);
        }
    //Handles random recipe
    private void GetRandomrecipe(int CatId)
    {
        //Instantiate random recipe database field
        RandomRecipe Recipe = new RandomRecipe();

        Recipe.CatID = CatId;
        Recipe.fillup();

        LinkRanName.NavigateUrl = "~/recipedetail.aspx?id=" + Recipe.ID;
        LinkRanName.Text = Recipe.RecipeName;
        LinkRanName.ToolTip = "View " + Recipe.RecipeName + " recipe";

        LinkRanCat.NavigateUrl = "~/category.aspx?catid=" + Recipe.CatID;
        LinkRanCat.Text = Recipe.Category;
        LinkRanCat.ToolTip = "Browse " + Recipe.Category + " category";

        lblranhits.Text = Recipe.Hits.ToString();

        ranrateimage.ImageUrl = Utility.GetStarImage(Recipe.Rating);
        lblvotes.Text = Recipe.NoRates;

        //Release allocated memory
        Recipe = null;
    }