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); }
private void btnRemoveCar_Click(object sender, RoutedEventArgs e) { _cars.RemoveAt(0); }