private void Awake()
    {
        ICoffee coffe1 = new ChocolateDecorator(new Filtered());
        ICoffee coffe2 = new ChocolateDecorator(new MilkDecorator(new Espresso()));
        ICoffee coffe3 = new SpecialMessageOfDay(new ChocolateDecorator(new MilkDecorator(new Espresso())));

        Debug.Log(coffe1.GetDescription() + "\n" + coffe1.GetPrice());
        Debug.Log(coffe2.GetDescription() + "\n" + coffe2.GetPrice());
        Debug.Log(coffe3.GetDescription() + "\n" + coffe3.GetPrice());
    }
        /// <summary>
        /// Orders the drink.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="addOn">The add on.</param>
        /// <returns>IDrink implementation</returns>
        public static IDrink OrderDrink(DrinkType type, DrinkAddOn addOn)
        {
            IDrink drink = null;

            switch (type)
            {
            case DrinkType.Expresso:
                drink = new Expresso();
                break;

            case DrinkType.Tea:
                drink = new Tea();
                break;

            case DrinkType.IceTea:
                drink = new IceTea();
                break;

            default:
                break;
            }

            if (drink != null)
            {
                if (type != DrinkType.IceTea)
                {
                    if (addOn.HasMilk)
                    {
                        drink = new MilkDecorator(drink);
                    }
                    else
                    {
                        drink.Description += " without milk";
                    }
                }

                if (addOn.HasSugar)
                {
                    drink = new SugarDecorator(drink);
                }
                else
                {
                    drink.Description += " without sugar";
                }

                if (addOn.HasChocolate && type == DrinkType.Expresso)
                {
                    drink = new ChocolateDecorator(drink);
                }
            }

            drink.Description = $"We are preparing the following drink for you: {drink.Description}";
            return(drink);
        }
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyDown(KeyCode.A))
        {
            ICoffee coffee = new Espresso();
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.S))
        {
            ICoffee coffee = new Filtered();
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.D))
        {
            ICoffee coffee = new ChocolateDecorator(new Espresso());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.F))
        {
            ICoffee coffee = new ChocolateDecorator(new Filtered());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.Z))
        {
            ICoffee coffee = new MilkDecorator(new Espresso());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.X))
        {
            ICoffee coffee = new MilkDecorator(new Filtered());
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.C))
        {
            ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Filtered()));
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }

        if (Input.GetKeyDown(KeyCode.V))
        {
            ICoffee coffee = new ChocolateDecorator(new MilkDecorator(new Espresso()));
            Debug.Log("Coffee discription and cost: " + coffee.GetDescription() + " $" + coffee.GetCost());
        }
    }
Esempio n. 4
0
 /// <summary>
 /// Manages the coffee addIns
 /// </summary>
 /// <param name="drinkOrder"></param>
 /// <param name="hasMilk"></param>
 /// <param name="hasSugar"></param>
 /// <param name="hasChocolate"></param>
 /// <returns>IDrink</returns>
 public static IDrink ProcessCoofeeAddIns(IDrink drinkOrder, bool hasMilk, bool hasSugar, bool hasChocolate)
 {
     try
     {
         IDrink fullDrink;
         //in this case every coffee allow every addIns
         if (hasMilk && hasSugar && hasChocolate)
         {
             return(fullDrink = new MilkDecorator(new SugarDecorator(new ChocolateDecorator(drinkOrder))));
         }
         else if (!hasMilk && hasSugar && hasChocolate)
         {
             return(fullDrink = new SugarDecorator(new ChocolateDecorator(drinkOrder)));
         }
         else if (hasMilk && !hasSugar && hasChocolate)
         {
             return(fullDrink = new MilkDecorator(new ChocolateDecorator(drinkOrder)));
         }
         if (hasMilk && hasSugar && !hasChocolate)
         {
             return(fullDrink = new MilkDecorator(new SugarDecorator(drinkOrder)));
         }
         else if (!hasMilk && !hasSugar && hasChocolate)
         {
             return(fullDrink = new ChocolateDecorator(drinkOrder));
         }
         else if (hasMilk && !hasSugar && !hasChocolate)
         {
             return(fullDrink = new MilkDecorator(drinkOrder));
         }
         else if (!hasMilk && hasSugar && !hasChocolate)
         {
             return(fullDrink = new SugarDecorator(drinkOrder));
         }
         else
         {
             //drink without addIns
             return(drinkOrder);
         }
     }
     catch (Exception)
     {
         throw;
     }
 }
    private void Update()
    {
        /// <summary>
        /// Espresso
        /// </summary>
        /// <returns></returns>

        if (Input.GetKeyDown(KeyCode.E))
        {//Default Espress
            ICoffee coff = new CoffeeEspresso();
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.R))
        {//Espress w/milk
            ICoffee coff = new MilkDecorator(new CoffeeEspresso());
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.T))
        {//Espress w/choc
            ICoffee coff = new ChocolateDecorator(new CoffeeEspresso());
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.Y))
        {//Espress w/choc & Milk
            ICoffee coff = new ChocolateDecorator(new MilkDecorator(new CoffeeEspresso()));
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }



        /// <summary>
        /// Filtered
        /// </summary>
        /// <returns></returns>

        if (Input.GetKeyDown(KeyCode.F))
        {//Default Filtered
            ICoffee coff = new CoffeeFiltered();
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.G))
        {//Filtered w/milk
            ICoffee coff = new MilkDecorator(new CoffeeFiltered());
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.H))
        {//Filtered w/choc
            ICoffee coff = new ChocolateDecorator(new CoffeeFiltered());
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }

        if (Input.GetKeyDown(KeyCode.J))
        {//Filtered w/Milk & choc
            ICoffee coff = new MilkDecorator(new ChocolateDecorator(new CoffeeFiltered()));
            Debug.Log("New " + coff.GetDescription() + " Cost: " + coff.GetCost().ToString());
        }
    }