コード例 #1
0
ファイル: CmdProgram.cs プロジェクト: markdioszegi/SI4
        void ShowPlazaMenu(Plaza plaza)
        {
            bool leavePlaza = false;

            while (!leavePlaza)
            {
                Console.Clear();
                System.Console.WriteLine($"Welcome to the {plaza.Name} plaza! Press");
                System.Console.WriteLine("1) to list all shops.");
                System.Console.WriteLine("2) to add a new shop.");
                System.Console.WriteLine("3) to remove an existing shop.");
                System.Console.WriteLine("4) to enter a shop by name.");
                System.Console.WriteLine("5) to open the plaza.");
                System.Console.WriteLine("6) to close the plaza.");
                System.Console.WriteLine("7) to check if the plaza is open or not.");
                System.Console.WriteLine("N) leave plaza.");
                switch (Console.ReadLine().ToLower())
                {
                case "1":
                    ListShops(plaza);
                    break;

                case "2":
                    AddShop(plaza);
                    break;

                case "3":
                    RemoveShop(plaza);
                    break;

                case "4":
                    EnterShop(plaza);
                    break;

                case "5":
                    plaza.Open();
                    System.Console.WriteLine("Plaza opened!");
                    Console.ReadKey();
                    break;

                case "6":
                    plaza.Close();
                    System.Console.WriteLine("Plaza closed!");
                    Console.ReadKey();
                    break;

                case "7":
                    if (plaza.IsOpen())
                    {
                        System.Console.WriteLine("The plaza is open.");
                    }
                    else
                    {
                        System.Console.WriteLine("The plaza is closed, get back tomorrow!");
                    }
                    Console.ReadKey();
                    break;

                case "n":
                    leavePlaza = true;
                    break;

                default:
                    throw new NotSupportedException("No such menu item!");
                }
            }
        }
コード例 #2
0
ファイル: CmdProgram.cs プロジェクト: Jazo74/Plaza-Project
        bool ChooseMainPlaza()
        {
            string choice = AnyInput("Please choose an option...");

            switch (choice)
            {
            case "1":     //is the plaza opened?
                Console.Clear();
                if (myPlaza.IsOpen())
                {
                    Console.WriteLine("The plaza is opened.");
                }
                else
                {
                    Console.WriteLine("The plaza is closed");
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "2":     // open the plaza
                Console.Clear();
                myPlaza.Open();
                Console.WriteLine("The plaza has just opened.");
                Thread.Sleep(1000);
                return(true);

            case "3":     // close plaza
                Console.Clear();
                myPlaza.Close();
                Console.WriteLine("The plaza has just closed.");
                Thread.Sleep(1000);
                return(true);

            case "4":     // list the shops
                Console.Clear();
                try
                {
                    if (myPlaza.GetShops().Count > 0)
                    {
                        foreach (Shop aShop in myPlaza.GetShops())
                        {
                            Console.WriteLine(aShop.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine("There are no shops in the Plaza.");
                    }
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("The Plaza is closed.");
                }
                AnyInput("Press any key to continue...");
                return(true);

            case "5":     // add new shop
                Console.Clear();
                string shopName = AnyInput("The name of the new shop?: ");
                string owner    = AnyInput("The owner of the new shop?: ");
                try
                {
                    Shop shop = new ShopImpl(shopName, owner);
                    myPlaza.AddShop(shop);
                    Console.WriteLine("A new shop has added the plaza.");
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("The Plaza is closed.");
                }
                catch (ShopAlreadyExistsException)
                {
                    Console.WriteLine("This shop is already exist.");
                }
                Thread.Sleep(1000);
                return(true);

            case "6":     // remove a shop
                Console.Clear();
                shopName = AnyInput("The shop name to remove?: ");
                try
                {
                    myPlaza.RemoveShop(myPlaza.FindShopByName(shopName));
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("The Plaza is closed.");
                }
                catch (NoSuchShopException)
                {
                    Console.WriteLine("No shop is exist with this name.");
                }
                Thread.Sleep(1000);
                return(true);

            case "7":     // entering a shop
                Console.Clear();
                shopName = AnyInput("Which shop you want to enter?: ");
                try
                {
                    bool shopbool = true;
                    while (shopbool)
                    {
                        Console.WriteLine("Entering the shop.");
                        Thread.Sleep(1000);
                        MenuShop(myPlaza.FindShopByName(shopName));
                        shopbool = ChooseShop(myPlaza.FindShopByName(shopName));
                    }
                }
                catch (PlazaIsClosedException)
                {
                    Console.WriteLine("The Plaza is closed.");
                }
                catch (NoSuchShopException)
                {
                    Console.WriteLine("No shop is exist with this name.");
                }
                Thread.Sleep(1000);
                return(true);

            case "8":     // listing the cart
                Console.Clear();
                if (myPlaza.IsOpen())
                {
                    if (cart.Count == 0)
                    {
                        Console.WriteLine("There is no product in the cart.");
                    }
                    else
                    {
                        for (int index = 0; index < cart.Count; index++)
                        {
                            Console.Write(cart[index].ToString());
                            Console.WriteLine(", Price: " + prices[index].ToString());
                        }
                    }
                }
                else
                {
                    Console.WriteLine("The plaza is closed.");
                }

                Console.WriteLine();
                AnyInput("Press any key to continue...");
                return(true);

            case "0":     // Exit program
                Console.Clear();
                return(false);

            default:
                return(true);
            }
        }