protected void AnimalTick(IEntity animal, HashSet <Type> canEat)
        {
            // Move
            ISet <Point> free      = pasture.GetFreeNeighbors(animal);
            Point        movePoint = Move(free);

            if (movePoint != null)
            {
                pasture.MoveEntity(animal, movePoint);
            }
            // Eat
            Point   currentPoint = pasture.GetPosition(animal);
            IEntity food         = Eat(currentPoint, canEat);

            if (food != null)
            {
                pasture.RemoveEntity(food);
                timeSinceEaten = 0;
            }
            else
            {
                timeSinceEaten++;
                if (timeSinceEaten >= timeUntilStarves)
                {
                    pasture.RemoveEntity(animal);
                }
            }
        }
Example #2
0
    /*
     * Performs the relevant actions of this entity, depending on what
     * kind of entity it is.
     */
    public void Tick()
    {
        if (alive)
        {
            moveDelay--;
        }

        if (moveDelay == 0)
        {
            Point neighbor = GetRandomMember(pasture.GetFreeNeighbors(this));

            if (neighbor != null)
            {
                pasture.MoveEntity(this, neighbor);
            }

            moveDelay = 10;
        }
    }
Example #3
0
        void move()
        {
            Random random = new Random();

            ISet <Point> neighbors = pasture.GetFreeNeighbors(this);
            int          num       = random.Next(0, neighbors.Count);
            int          count     = 0;

            foreach (Point p in neighbors)
            {
                count++;
                if (count == num)
                {
                    pasture.MoveEntity(this, p);
                    eat(p);
                }
            }
            curr_ttm = ttm;
        }