Ejemplo n.º 1
0
        private static Jewel CheckContainsJewel(string type, string typeOfItem, long quantityItem)
        {
            Jewel currentJewel = bag.FirstOrDefault(x => x.Name == type);

            Item currentItem = currentJewel.Jewels.FirstOrDefault(x => x.ItemName == typeOfItem);

            if (currentItem == null)
            {
                AddJewels(currentJewel, quantityItem);
            }
            else
            {
                IncreaceJewels(currentItem, quantityItem, currentJewel);
            }

            return(currentJewel);
        }
Ejemplo n.º 2
0
 private static void IncreaceJewels(Item currentItem, long quantityItem, Jewel currentJewel)
 {
     if (currentJewel.Name == "Gold" &&
         bag[0].Sum() + quantityItem >= bag[1].Sum())
     {
         currentItem.Amount += quantityItem;
     }
     else if (currentJewel.Name == "Gem" &&
              bag[1].Sum() + quantityItem >= bag[2].Sum() &&
              bag[1].Sum() + quantityItem < bag[0].Sum())
     {
         currentItem.Amount += quantityItem;
     }
     else if (currentJewel.Name == "Cash" &&
              bag[2].Sum() + quantityItem < bag[1].Sum())
     {
         currentItem.Amount += quantityItem;
     }
 }
Ejemplo n.º 3
0
 private static void AddJewels(Jewel currentJewel, long quantityItem)
 {
     if (currentJewel.Name == "Gold" &&
         bag[0].Sum() + quantityItem >= bag[1].Sum())
     {
         currentJewel.Jewels.Add(item);
     }
     else if (currentJewel.Name == "Gem" &&
              bag[1].Sum() + quantityItem >= bag[2].Sum() &&
              bag[2].Sum() + quantityItem < bag[0].Sum())
     {
         currentJewel.Jewels.Add(item);
     }
     else if (currentJewel.Name == "Cash" &&
              bag[2].Sum() + quantityItem <= bag[1].Sum())
     {
         currentJewel.Jewels.Add(item);
     }
 }