Пример #1
0
        public List <Wagon> HandleHerbivore(Animal animal)
        {
            if (animal.animalType == Animal.AnimalType.Carnivore)
            {
                throw new ArgumentException("animal can't be a carnivore");
            }

            if (animal == null)
            {
                throw new ArgumentException("animal can't be null");
            }
            bool isAnimalPlaced = false;

            foreach (Wagon wagon in trainList)
            {
                if (!isAnimalPlaced)
                {
                    isAnimalPlaced = wagon.TryPlaceAnimal(animal);
                }
            }

            if (!isAnimalPlaced)
            {
                Wagon wagon = new Wagon(Wagon.WagonSize.Regular);
                wagon.PlaceAnimalInNewWagon(animal);
                trainList.Add(wagon);
            }
            return(trainList);
        }
Пример #2
0
        public List <Wagon> StartLoadingTrain(List <Animal> animalList)
        {
            animalList = SortAnimals(animalList);
            foreach (Animal animal in animalList)
            {
                if (animal == null)
                {
                    throw new ArgumentException("animal can't be null");
                }
                // check for animaltype and make new wagon if carnivore
                if (animal.animalType == Animal.AnimalType.Carnivore)
                {
                    Wagon wagon = new Wagon(Wagon.WagonSize.Regular);

                    wagon.PlaceAnimalInNewWagon(animal);
                    trainList.Add(wagon);
                }
                //check for animaltype and try to place in used wagon, else make new wagon
                else if (animal.animalType == Animal.AnimalType.Herbivore)
                {
                    HandleHerbivore(animal);
                }
            }
            return(trainList);
        }