Exemplo n.º 1
0
        public IAnimal FindTargetForLion(IAnimal lion)
        {
            Debug.Assert(lion is Lion);

            var targets = new List <IAnimal>();

            foreach (var animal in Database.Animals)
            {
                // can lion eat this animal?
                if (lion.CanEat(animal))
                {
                    targets.Add(animal);
                }
            }

            if (targets.Count == 0)
            {
                return(null);
            }

            return(targets[Randomizer.Next(targets.Count)]);
        }