Esempio n. 1
0
 public Ingredient(int id, string name, int type, int price)
 {
     ID    = id;
     Name  = name;
     Price = price;
     Type  = (Ingredient_Type)type;
 }
Esempio n. 2
0
        /// <summary>
        /// Updates information required for Cart
        /// </summary>
        private void CheckCart()
        {
            Cart.Discounts = new List <Discount_Set>();
            int PizzaAmount = Cart.Cart_Items.Where(x => x.Menu_Item.Type == Menu_Item_Type.Pizza).Sum(x => x.Amount);
            int DrinkAmount = Cart.Cart_Items.Where(x => x.Menu_Item.Type == Menu_Item_Type.Drink).Sum(x => x.Amount);
            List <Discount_Set> Discount = Discounts.OrderByDescending(x => x.Items_Needed.Count).ToList();

            while (Discount.Any(x => (x.Items_Needed.Count(y => y == Menu_Item_Type.Pizza) <= PizzaAmount) && (x.Items_Needed.Count(y => y == Menu_Item_Type.Drink) <= DrinkAmount)))
            {
                var d = Discount.OrderByDescending(x => x.Type).FirstOrDefault(x => (x.Items_Needed.Count(y => y == Menu_Item_Type.Pizza) <= PizzaAmount) && (x.Items_Needed.Count(y => y == Menu_Item_Type.Drink) <= DrinkAmount));
                PizzaAmount = PizzaAmount - d.Items_Needed.Where(x => x == Menu_Item_Type.Pizza).Count();
                DrinkAmount = DrinkAmount - d.Items_Needed.Where(x => x == Menu_Item_Type.Drink).Count();
                d._Price    = 0;
                Cart.Discounts.Add(d);
            }
            foreach (Discount_Set item in Cart.Discounts.OrderByDescending(x => x.Type).ThenByDescending(x => x.Percentage))
            {
                if (item.Type == Discount_Type.Item)
                {
                    Ingredient_Type   t           = (Ingredient_Type)item.Item_Type;
                    List <Ingredient> Ingredients = Cart._Ingredients.Where(x => x.Type == t).ToList();
                    int da = Cart.Discounts.Where(x => x.Item_Type == t && x._Price != 0 && x.Top == item.Top).ToList().Count();
                    if (item.Top)
                    {
                        Ingredients = Ingredients.OrderByDescending(x => x.Price).Skip(da).ToList();
                    }
                    else
                    {
                        Ingredients = Ingredients.OrderBy(x => x.Price).Skip(da).ToList();
                    }
                    item._Price = -Ingredients.FirstOrDefault(x => x.Type == t).Price;
                }
                else
                {
                    float p = Cart.Price * ((float)item.Percentage / 100);
                    item._Price = -p;
                    Cart.Price  = Cart.Price - p;
                }
            }

            List <object> OrderItems = Cart.Cart_Items.ToList <object>();

            foreach (object item in Cart.Discounts)
            {
                OrderItems.Add(item);
            }
            Cart_listbox.ItemsSource = OrderItems;
            Cart_listbox.Items.Refresh();
            Order_Price_lbl.Content = Cart.Price + " USD";
        }
Esempio n. 3
0
    //For each thing in the current ingredients, check if it matches in the
    //correct ingredients. Once you get n matches, where n is the length of the
    //correct ingredients list, you have a correct recipe, as long as you
    //have no more ingredients left (i.e. extra ingredients are bad)

    public bool CheckRecipe()
    {
        /*
         * This function, when called, returns one of the following:
         *  true  <- if they have matched the ingredients.
         *  false <- if they have not yet matched the correct ingredients.
         */
        int        matches = 0;
        List <int> alreadyMatchedPlaces = new List <int>();

        for (int place = 0; place < currentIngredients.Count; place++)
        {
            Ingredient_Type iplace = currentIngredients[place];
            if (orderMatters)
            {
                if (correctIngredients.Length > place && correctIngredients[place] == iplace)
                {
                    matches += 1;
                }
            }
            else
            {
                for (int correctPlace = 0; correctPlace < correctIngredients.Length; correctPlace++)
                {
                    if (iplace == correctIngredients[correctPlace] &&
                        !alreadyMatchedPlaces.Contains(correctPlace))
                    {
                        //Add this slot to the already matched slots
                        alreadyMatchedPlaces.Add(correctPlace);
                        matches += 1;
                    }
                }
            }
        }

        /* This performs the final comparison between the
         * number of correct matches and the total number of
         * ingredients they must match and returns true or false. */
        return(matches == correctIngredients.Length);
    }
Esempio n. 4
0
 public void AddIngredient(Ingredient_Type ingredienttype)
 {
     currentIngredients.Add(ingredienttype);
     txtCurrentIngredients.text = IngredientsToString(currentIngredients.ToArray());
 }