コード例 #1
0
        static void deleteItem(BinaryTreeShop bt)
        {
            Console.Clear();
            string input = "";

            while (input != "end")
            {
                Console.Clear();
                Console.WriteLine("-----Delete Item from Shop-----");
                bt.printShop();
                Console.WriteLine("Please enter the name of a weapon to delete (enter 'end' to quit):");
                input = Console.ReadLine();
                //all items stored in lowercase so searches done in lowercase
                input = input.ToLower();
                if (input == "end")
                {
                    break;
                }
                if (bt.Search(input) == null)
                {
                    Console.WriteLine("This item is not in the shop. Press any key to continue...");
                    Console.ReadKey();
                }
                else
                {
                    bt.delete(input);
                    Console.WriteLine("Item deleted from shop! Press any key to continue...");
                    Console.ReadKey();
                }
            }
        }
コード例 #2
0
        static void buyItem(Player p, BinaryTreeShop bt)
        {
            Console.Clear();
            string input = "";

            while (input != "end")
            {
                Console.Clear();
                Console.WriteLine("-----Buy Item from Shop-----");
                bt.printShop();
                p.printBackpack();
                Console.WriteLine("Please enter the name of a weapon to buy (enter 'end' to quit):");
                input = Console.ReadLine();
                //all items stored in lowercase so searches done in lowercase
                input = input.ToLower();
                if (input == "end")
                {
                    break;
                }
                if (bt.Search(input) == null)
                {
                    Console.WriteLine("This item is not in the shop. Press any key to continue...");
                    Console.ReadKey();
                }
                else
                {
                    ShopNode purchasedItem = bt.Search(input);
                    int      numpurchased;
                    Console.WriteLine("Please enter the number of " + input + " you wish to purchase:");
                    input = Console.ReadLine();
                    //check for correct input
                    while (!int.TryParse(input, out numpurchased) || numpurchased < 1)
                    {
                        Console.WriteLine("Please enter a valid number for number of items:");
                        input = Console.ReadLine();
                    }
                    if (purchasedItem.getNumStock() < numpurchased)
                    {
                        Console.WriteLine("There isn't that many of this item in the shop...");
                    }
                    else
                    {
                        if (p.buy(purchasedItem.shopitem, numpurchased))
                        {
                            purchasedItem.setNumStock(purchasedItem.getNumStock() - numpurchased);
                            if (purchasedItem.getNumStock() == 0)
                            {
                                bt.delete(purchasedItem.shopitem.weaponName);
                            }
                        }
                    }
                    Console.WriteLine("Press any key to continue...");
                    Console.ReadKey();
                }
            }
        }