private void SortAnimals() { var sortedAnimals = animals.OrderByDescending(x => x.size); foreach (var animal in sortedAnimals) { bool AnimalSorted = false; foreach (var wagon in wagons) { if (wagon.CanFitAnimal(animal)) { wagon.AddAnimal(animal); animals.Remove(animal); AnimalSorted = true; } } if (!AnimalSorted) { var wagon = new Wagon(); wagon.AddAnimal(animal); wagons.Add(wagon); animals.Remove(animal); } } }
private void CreateWagon(Animal animal) { var wagon = new Wagon(); wagon.AddAnimal(animal); _train.AddWagon(wagon); listBox2.Items.Add(wagon.ToString()); }