Exemple #1
0
        public void Buy(int itemNumber)
        {
            if (itemNumber >= Items.Count || itemNumber < 0)
            {
                Console.WriteLine($"Item number does not exist!");
                return;
            }
            IItem item = Items[itemNumber];

            if (Hero.Gold >= item.OriginalValue)
            {
                Hero.Gold -= item.OriginalValue;
                Hero.AddItem(item);
                Console.WriteLine($"You bought {item.Name} for {item.OriginalValue} gold.");
            }
            else
            {
                Console.WriteLine($"Insufficient gold!");
            }
        }