Beispiel #1
0
        public void MakeBeverage(IBeverage selectedBeverage, bool sugarAdded = false, bool milkAdded = false)
        {
            IBeverage beverage = (IBeverage)Activator.CreateInstance(selectedBeverage.GetType());

            if (sugarAdded)
            {
                beverage.AddIngredient(IngredientType.Sugar);
            }

            if (milkAdded)
            {
                beverage.AddIngredient(IngredientType.Milk);
            }

            int status = -1;

            foreach (var item in beverage.Ingredients)
            {
                switch (item)
                {
                case IngredientType.CoffeePowder:
                    status = CoffeePowderContainer.GetDose();
                    break;

                case IngredientType.ChocolatePowder:
                    status = ChocolatePowderContainer.GetDose();
                    break;

                case IngredientType.Milk:
                    status = MilkContainer.GetDose();
                    break;

                case IngredientType.HotMilk:
                    status = MilkContainer.GetDose();
                    break;

                case IngredientType.Sugar:
                    status = SugarContainer.GetDose();
                    break;

                default:
                    status = 1;
                    break;
                }

                if (status == -1)
                {
                    break;
                }
            }

            if (status != -1)
            {
                dispensedBeverages.Add(beverage);
                OnDispensed($"Drink: {beverage.ToString()}");
            }
        }