public static bool BuyItem(int itemID, Hero hero) { var itemIndex = itemID - 1; var getItem = (from item in ShopItems where itemIndex == ShopItems.IndexOf(item) select item).FirstOrDefault(); // Check if the hero has enough money if (hero.Gold >= getItem.Value) { // Add to Hero's inventory, remove from stores inventory. hero.Bag.Add(getItem); hero.RemoveGold(getItem.Value); // If item is not a potion, remove from store. if (!IsPotion(getItem.GetType())) { ShopItems.RemoveAt(itemIndex); } return(true); } else { // Didn't have enough gold, return(false); } }