Exemple #1
0
        public void UseInventory(Ingredient ingredient)
        {
            var totalIndex = TotalInv.IndexOf(TotalInv.Where(i => i.Name == ingredient.Name).FirstOrDefault());

            if (totalIndex == -1 || TotalInv[totalIndex].Weight < ingredient.Weight)
            {
                Console.WriteLine($"There is not enough {ingredient.Name} in your inventory");
                return;
            }
            var usedWeight = ingredient.Weight;

            while (usedWeight > 0)
            {
                var listIndex = InventoryList.IndexOf(InventoryList.Where(i => i.Name == ingredient.Name).FirstOrDefault());
                if (InventoryList[listIndex].Weight < usedWeight)
                {
                    usedWeight -= InventoryList[listIndex].Weight;
                    InventoryList.RemoveAt(listIndex);
                }
                else
                {
                    InventoryList[listIndex].Weight -= usedWeight;
                    usedWeight = 0;
                }
            }
            AdjustTotalInventory(ingredient);
        }
Exemple #2
0
 private void btnRemoveCar_Click(object sender, RoutedEventArgs e)
 {
     _cars.RemoveAt(0);
 }