예제 #1
0
        // add a single pizza to an order
        private static void SelectPizza(Order cart, User user1, Store store)
        {
            store.ViewMenu();

            do
            {
                // select a base pizza from menu
                int selection;
                System.Console.Write("\nMake a selection: ");
                if
                (
                    !int.TryParse(Console.ReadLine(), out selection) ||
                    selection < 1 ||
                    selection > store.PizzaPresets.Count
                )
                {
                    System.Console.WriteLine("Whoops, that wasn't an option!\n");
                    continue;
                }

                // create base pizza from user selection
                var pizza = store.CreatePizza
                            (
                    store.PizzaPresets[selection - 1].Name,
                    store.PizzaPresets[selection - 1].Toppings,
                    cart
                            );
                System.Console.WriteLine($"{pizza.Name} Pizza selected!");
                store.AddSize(GetUserSize(store), pizza);   // get user size
                store.AddCrust(GetUserCrust(store), pizza); // get user crust
                // if pizza is custom, let user choose toppings
                if (pizza.Name == "Custom")
                {
                    store.AddToppings(GetUserToppings(store), pizza);
                }

                // if order exceeds the $250 limit, remove the last pizza
                if (cart.CalculatePrice() > 250)
                {
                    cart.Pizzas.Remove(pizza);
                    System.Console.WriteLine("Sorry, this pizza exceeds the $250 order limit.");
                }
                else
                {
                    System.Console.WriteLine($"{pizza.Name} Pizza added to your cart!");
                }
                return;
            } while (true);
        }