コード例 #1
0
ファイル: CmdProgram.cs プロジェクト: markdioszegi/SI4
 private void ListShops(Plaza plaza)
 {
     foreach (Shop shop in plaza.GetShops())
     {
         System.Console.WriteLine(shop.ToString());
     }
     Console.ReadKey();
 }
コード例 #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);
            }
        }