Exemplo n.º 1
0
        /**
         * Check whether or not this rabbit is to give birth at this step.
         * New births will be made into free adjacent locations.
         * New born rabbits are added to the Litter.
         */
        public void Breed()
        {
            // New rabbits are born into adjacent locations.
            // Get a list of adjacent free locations.
            List <Location> free = field.GetFreeAdjacentLocations(location);

            Litter.Clear();

            for (int b = 0; b < newBirths && free.Count > 0; b++)
            {
                Location loc = free[0];
                free.RemoveAt(0);

                Rabbit young = new Rabbit(false, field, loc);
                Litter.Add(young);
            }
        }
Exemplo n.º 2
0
        /**
         * Look for rabbits adjacent to the current location.
         * Only the first live rabbit is eaten.
         * @return Where food was found, or null if it wasn't.
         */
        protected override Location FindFood()
        {
            List <Location> adjacent = field.AdjacentLocations(location);

            foreach (Location where in adjacent)
            {
                Object animal = field.GetAnimalAt(where);

                if (animal is Rabbit)
                {
                    Rabbit rabbit = (Rabbit)animal;
                    if (rabbit.IsAlive())
                    {
                        rabbit.Die();
                        foodLevel = MainFoodValue;
                        return(where);
                    }
                }
            }
            return(null);
        }