Esempio n. 1
0
        public IDrink CreateDrink(string drinkName, IDictionary <string, Amount> options, Strength strength = 0)
        {
            // Create the Drink
            IDrink drink = null;

            switch (drinkName)
            {
            case "Coffee":
                drink = new Coffee()
                {
                    DrinkStrength = strength
                };
                break;

            case "Espresso":
                drink = new Espresso();
                break;

            case "Capuccino":
                drink = new Capuccino();
                break;

            case "Wiener Melange":
                drink = new WienerMelange();
                break;

            case "Café au Lait":
                drink = new CafeAuLait();
                break;

            case "Chocolate":
                drink = new Chocolate();
                break;

            case "Chocolate Deluxe":
                drink = new ChocolateDeluxe();
                break;

            case "Irish Coffee":
                drink = new IrishCoffee(_configurables[drinkName]);
                break;

            case "Italian Coffee":
                drink = new ItalianCoffee(_configurables[drinkName]);
                break;

            case "Spanish Coffee":
                drink = new SpanishCoffee(_configurables[drinkName]);
                break;
            }

            if (drink != null)
            {
                // Set price using decorators
                foreach (var option in options)
                {
                    switch (option.Key)
                    {
                    case "Sugar":
                        if (drink.CompatibleToppings.Contains("Sugar"))
                        {
                            drink = new SugarDecorator(drink, option.Value);
                        }
                        break;

                    case "Milk":
                        if (drink.CompatibleToppings.Contains("Milk"))
                        {
                            drink = new MilkDecorator(drink, option.Value);
                        }
                        break;
                    }
                }
            }

            return(drink);
        }
        private void BrewDrink()
        {
            IDrink drink;

            switch (_drinkName)
            {
            case "Coffee":
                drink = new Coffee()
                {
                    Strength = CoffeeStrength
                };
                break;

            case "Espresso":
                drink = new Espresso();
                break;

            case "Capuccino":
                drink = new Capuccino();
                break;

            case "Wiener Melange":
                drink = new WienerMelange();
                break;

            case "Café au Lait":
                drink = new CafeAuLait();
                break;

            case "Chocolate":
                drink = new Chocolate();
                break;

            case "Chocolate Deluxe":
                drink = new Chocolate(makeDeluxe: true);
                break;

            case "Tea":
                TeaBlend teaBlend = _teaBlendRepository.GetTeaBlend(SelectedTeaBlendOption);
                if (_hasSugar)
                {
                    drink = new TeaDrink(teaBlend, sugeramount: (int)SugarAmount);
                }
                else
                {
                    drink = new TeaDrink(teaBlend);
                }
                break;

            default:
                drink = _fh.GetBaseDrink(_drinkName);
                break;;
            }

            if (_hasSugar)
            {
                drink = new SugarDecorator(drink, _sugarAmount);
            }

            if (_hasMilk)
            {
                drink = new MilkDecorator(drink, _milkAmount);
            }

            SelectedDrink = drink;
        }