Beispiel #1
0
        public void AddGoldItem(GoldItem item)
        {
            if (capacity >= current + item.Value)
            {
                var goldItems = GetGoldItems();
                if (goldItems.Any(gi => gi.Key == item.Key))
                {
                    goldItems.Single(gi => gi.Key == item.Key).IncreaseValue(item.Value);
                }
                else
                {
                    bag.Add(item);
                }

                current += item.Value;
            }
        }
Beispiel #2
0
 private static void InsertItem(string key, long value, Bag bag)
 {
     if (key.Length == 3)
     {
         CashItem cash = new CashItem(key, value);
         bag.AddCashItem(cash);
     }
     else if (key.Length >= 4 && key.ToLower().EndsWith("gem"))
     {
         GemItem gem = new GemItem(key, value);
         bag.AddGemItem(gem);
     }
     else if (key.ToLower().Equals("gold"))
     {
         GoldItem gold = new GoldItem(key, value);
         bag.AddGoldItem(gold);
     }
 }