Пример #1
0
        /*
         * ========================================================================================
         * SellItem ---> Allows transfers the sold item to the hero
         * ========================================================================================
         */
        private void SellItem(IBuyableItem item)
        {
            Hero.RemoveGoldCoins(item.Price);
            ToggleSoldProperty(item);

            if (item.ItemCategory == ItemCategoryEnum.Strength)
            {
                Hero.WeaponsBag.Add((Weapon)item);
            }
            else if (item.ItemCategory == ItemCategoryEnum.Defence)
            {
                if (item is Armor)
                {
                    Hero.ArmorBag.Add((Armor)item);
                }
                else if (item is Shield)
                {
                    Hero.ShieldBag.Add((Shield)item);
                }
            }
            else
            {
                Hero.HealthPotionBag.Add((HealthPotion)item);
            }
        }
Пример #2
0
 private static void CreateAndAddCheatItem(Hero hero, Shop shop, IBuyableItem cheatItem)
 {
     if (cheatItem is Weapon)
     {
         hero.WeaponsBag.Add((Weapon)cheatItem);
         shop.AllBuyableItems.Add(cheatItem);
         hero.EquipWeapon(hero.WeaponsBag.IndexOf((Weapon)cheatItem));
     }
     else if (cheatItem is Armor)
     {
         hero.ArmorBag.Add((Armor)cheatItem);
         shop.AllBuyableItems.Add(cheatItem);
         hero.EquipArmor(hero.ArmorBag.IndexOf((Armor)cheatItem));
     }
     else if (cheatItem is Shield)
     {
         hero.ShieldBag.Add((Shield)cheatItem);
         shop.AllBuyableItems.Add(cheatItem);
         hero.EquipShield(hero.ShieldBag.IndexOf((Shield)cheatItem));
     }
     else
     {
         throw new System.NotImplementedException("item type N/A");
     }
 }
Пример #3
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();
            }
        }
Пример #4
0
 private void ToggleSoldProperty(IBuyableItem item) => item.Sold = item.Sold ? false : true;
Пример #5
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();
            }
        }