예제 #1
0
        /*
         * ========================================================================================
         * BuyShopItem ---> Allows hero to buy the shops items
         * ========================================================================================
         */
        private void SellShopItem()
        {
            Console.Clear();

            List <IBuyableItem> buyableItems = AllBuyableItems.Where(item => (!item.Sold || item.CanBeSoldMultipleTimes)).ToList();

            if (buyableItems.Any())
            {
                Console.WriteLine("================[All Items]================");
                DisplayAllItems();

                Console.WriteLine("Tip: input item number to buy it");
                bool isNumber = int.TryParse(Console.ReadLine().Trim(), out int inputtedIndex);


                IBuyableItem selectedItem = isNumber && inputtedIndex > 0 && inputtedIndex <= buyableItems.Count ? buyableItems[inputtedIndex - 1] : null;


                if (isNumber && selectedItem != null && selectedItem.Price <= Hero.GoldCoins)
                {
                    SellItem(selectedItem);

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"You just bought a new {selectedItem.Name}\n\n");
                    Console.ResetColor();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Nothing Was Bought . . .");
                    Console.WriteLine("Because one of the following reasons:");
                    Console.WriteLine("- item's price was greater than your current Gold Coins");
                    Console.WriteLine("- input wasn't an item number\n");
                    Console.ResetColor();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Sorry The Shop Is Out Of Stock . . .");
                Console.ResetColor();
            }
        }
예제 #2
0
        /*
         * ========================================================================================
         * DisplayAllItems ---> Prints all shop items and color codes items by their category
         * ========================================================================================
         */
        private void DisplayAllItems()
        {
            List <IBuyableItem> allItems = AllBuyableItems.Where(item => (!item.Sold || item.CanBeSoldMultipleTimes)).ToList();

            for (int i = 1; i < allItems.Count + 1; i++)
            {
                if (allItems[i - 1].ItemCategory == ItemCategoryEnum.Strength)
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(allItems[i - 1].ShowItemStats(i));
                }
                else if (allItems[i - 1].ItemCategory == ItemCategoryEnum.Defence)
                {
                    Console.ForegroundColor = allItems[i - 1] is Armor ? ConsoleColor.DarkBlue : ConsoleColor.Blue;
                    Console.WriteLine(allItems[i - 1].ShowItemStats(i));
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.DarkGreen;
                    Console.WriteLine(allItems[i - 1].ShowItemStats(i));
                }
                Console.ResetColor();
            }
        }
예제 #3
0
 public List <Shield> GetCurrentShields() => AllBuyableItems
 .Where(item => (item.ItemCategory == ItemCategoryEnum.Defence && item is Shield) && (!item.Sold || item.CanBeSoldMultipleTimes))
 .Cast <Shield>()
 .ToList();
예제 #4
0
 public List <Armor> GetCurrentArmor() => AllBuyableItems
 .Where(item => (item.ItemCategory == ItemCategoryEnum.Defence && item is Armor) && (!item.Sold || item.CanBeSoldMultipleTimes))
 .Cast <Armor>()
 .ToList();
예제 #5
0
 public List <Weapon> GetCurrentWeapons() => AllBuyableItems
 .Where(item => (item.ItemCategory == ItemCategoryEnum.Strength && item is Weapon) && (!item.Sold || item.CanBeSoldMultipleTimes))
 .Cast <Weapon>()
 .ToList();
예제 #6
0
        /*
         * ========================================================================================
         * BuyHeroItem ---> Allows hero to sell his/her items to the shop
         * ========================================================================================
         */
        private void BuyHeroItem()
        {
            Console.Clear();

            List <IBuyableItem> heroItems = Hero.GetMasterInventoryList().ToList();

            if (heroItems.Any())
            {
                for (int i = 0; i < heroItems.Count; i++)
                {
                    if (heroItems[i].ItemCategory == ItemCategoryEnum.Strength)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        if (heroItems[i] is Weapon weapon)
                        {
                            if (weapon.IsEquipped)
                            {
                                Console.WriteLine($"{i + 1}. Sell your {weapon.Name} for {weapon.SellingPrice} Gold Coins (Currently Equipped)");
                            }
                            else
                            {
                                Console.WriteLine($"{i + 1}. Sell your {weapon.Name} for {weapon.SellingPrice} Gold Coins");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"{i + 1}. Sell your {heroItems[i].Name} for {heroItems[i].SellingPrice} Gold Coins");
                        }
                    }
                    else if (heroItems[i].ItemCategory == ItemCategoryEnum.Defence)
                    {
                        Console.ForegroundColor = heroItems[i] is Armor ? ConsoleColor.DarkBlue : ConsoleColor.Blue;
                        if (heroItems[i] is Armor armor)
                        {
                            if (armor.IsEquipped)
                            {
                                Console.WriteLine($"{i + 1}. Sell your {armor.Name} for {armor.SellingPrice} Gold Coins (Currently Equipped)");
                            }
                            else
                            {
                                Console.WriteLine($"{i + 1}. Sell your {armor.Name} for {armor.SellingPrice} Gold Coins");
                            }
                        }
                        else if (heroItems[i] is Shield shield)
                        {
                            if (shield.IsEquipped)
                            {
                                Console.WriteLine($"{i + 1}. Sell your {shield.Name} for {shield.SellingPrice} Gold Coins (Currently Equipped)");
                            }
                            else
                            {
                                Console.WriteLine($"{i + 1}. Sell your {shield.Name} for {shield.SellingPrice} Gold Coins");
                            }
                        }
                        else
                        {
                            Console.WriteLine($"{i + 1}. Sell your {heroItems[i].Name} for {heroItems[i].SellingPrice} Gold Coins");
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine($"{i + 1}. Sell your {heroItems[i].Name} for {heroItems[i].SellingPrice} Gold Coins");
                    }
                    Console.ResetColor();
                }

                Console.WriteLine("\nPlease input a item number to sell it\n");

                bool isNumber = int.TryParse(Console.ReadLine().Trim(), out int userIndex);

                userIndex--;

                bool invalidIndex = userIndex > heroItems.Count || userIndex < 0 ? true : false;

                if (isNumber && !invalidIndex)
                {
                    Guid         foundId        = heroItems[userIndex].ItemId;
                    IBuyableItem deleteThisItem = Hero.ArmorBag.Where(item => item.ItemId == foundId).FirstOrDefault();

                    if (deleteThisItem == null)
                    {
                        deleteThisItem = Hero.ShieldBag.Where(item => item.ItemId == foundId).FirstOrDefault();
                    }
                    if (deleteThisItem == null)
                    {
                        deleteThisItem = Hero.WeaponsBag.Where(item => item.ItemId == foundId).FirstOrDefault();
                    }
                    if (deleteThisItem == null)
                    {
                        deleteThisItem = Hero.HealthPotionBag.Where(item => item.ItemId == foundId).FirstOrDefault();
                    }
                    if (deleteThisItem == null)
                    {
                        throw new Exception("No Item was found to sell");
                    }

                    Hero.UnEquipItem(deleteThisItem);
                    Hero.AddGoldCoins(deleteThisItem.SellingPrice);
                    if (deleteThisItem.ItemCategory == ItemCategoryEnum.Strength)
                    {
                        Hero.WeaponsBag.Remove((Weapon)deleteThisItem);
                    }
                    else if (deleteThisItem.ItemCategory == ItemCategoryEnum.Defence)
                    {
                        if (deleteThisItem is Armor)
                        {
                            Hero.ArmorBag.Remove((Armor)deleteThisItem);
                        }
                        else if (deleteThisItem is Shield)
                        {
                            Hero.ShieldBag.Remove((Shield)deleteThisItem);
                        }
                    }
                    else
                    {
                        Hero.HealthPotionBag.Remove((HealthPotion)deleteThisItem);
                    }

                    // Make sold item available in the shop again
                    IBuyableItem shopItem = AllBuyableItems.Where(item => item.ItemId == foundId).FirstOrDefault();
                    shopItem.Sold = false;

                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine($"You just sold your {deleteThisItem.Name} for {deleteThisItem.SellingPrice} Gold Coins");
                    Console.ResetColor();
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Did not sell an item because of one of the following statements:");
                    Console.WriteLine(" - didn't input a number");
                    Console.WriteLine(" - inputted number wasn't within a valid range");
                    Console.ResetColor();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("You Have No Items To Sell");
                Console.ResetColor();
            }
        }