Ejemplo n.º 1
0
        public void SellLemonade(Day day)
        {
            int buyerCounter = 0;

            for (int i = 0; i < day.customers.Count; i++)
            {
                if (pitcher.cupsOfLemonade > 0 && inventory.cups.Count > 0)
                {
                    try
                    {
                        if (day.customers[i].payPreference >= recipe.pricePerCup && day.customers[i].tastePreference == recipe.sweetness)
                        {
                            Console.ForegroundColor = ConsoleColor.Yellow;
                            Console.Write($"{day.customers[i].fullName} bought a cup");
                            Console.WriteLine($" ({day.customers[i].tastePreference}!)");
                            pitcher.cupsOfLemonade--;
                            inventory.cups.Remove(inventory.cups[0]);
                            buyerCounter++;
                            wallet.GetMoneyForLemonade(recipe.pricePerCup);
                            Console.ResetColor();
                        }
                        else if (day.customers[i].payPreference >= recipe.pricePerCup && day.customers[i].tastePreference != recipe.sweetness)
                        {
                            Console.Write($"{day.customers[i].fullName} did not buy a cup");
                            Console.WriteLine($" (Not {day.customers[i].tastePreference}, too {recipe.sweetness})");
                        }
                        else
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Write($"{day.customers[i].fullName} did not buy a cup");
                            Console.WriteLine(" (Price too high)");
                            Console.ResetColor();
                        }
                    }
                    catch (ArgumentOutOfRangeException)
                    {
                        Console.WriteLine("No more customers!");
                        return;
                    }
                }
                else
                {
                    Console.WriteLine("No lemonade left to sell!");
                    UserInterface.DesplayCustomerCount(buyerCounter, day);
                    return;
                }
            }

            UserInterface.DesplayCustomerCount(buyerCounter, day);
            return;
        }