Exemple #1
0
 public static List <CashItem> ChangeCashItems(List <CashItem> cash, string item, long quantity)
 {
     if (cash.Any(x => x.Name == item))
     {
         int index = cash.FindIndex(x => x.Name == item);
         cash[index].Quantity += quantity;
     }
     else
     {
         CashItem currentCash = new CashItem(item);
         currentCash.Quantity = quantity;
         cash.Add(currentCash);
     }
     return(cash);
 }
Exemple #2
0
 public void AddCashItem(CashItem item)
 {
     if (capacity >= current + item.Value && GemItemsValue >= CashItemsValue + item.Value)
     {
         List <Item> cashItems = GetCashItems();
         if (cashItems.Any(gi => gi.Key == item.Key))
         {
             cashItems.Single(gi => gi.Key == item.Key).IncreaseValue(item.Value);
         }
         else
         {
             bag.Add(item);
         }
         current += item.Value;
     }
 }
Exemple #3
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);
     }
 }
Exemple #4
0
        public void FillBag(Bag bag, string type, string nameOfItem, long quantity)
        {
            switch (type)
            {
            case "Gem":
                GemItem.ChangeGemItems(Gems, nameOfItem, quantity);
                break;

            case "Cash":
                CashItem.ChangeCashItems(Cash, nameOfItem, quantity);
                break;

            case "Gold":
                GoldItem.ChangeGoldItems(Gold, nameOfItem, quantity);
                break;

            default:
                break;
            }
        }