コード例 #1
0
        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);
                }
            }
        }
コード例 #2
0
        void IEntity.Tick()
        {
            ISet <Point> free          = pasture.GetFreeNeighbors(this);
            Point        newgrasspoint = Reproduce(free);

            if (newgrasspoint != null)
            {
                pasture.AddEntity(new Grass(pasture, timeUntilReproduce), newgrasspoint);
            }
        }
コード例 #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;
        }
コード例 #4
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;
        }
    }
コード例 #5
0
        void grow()
        {
            Random random = new Random();

            if (this != null)
            {
                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.AddEntity(new Grass(pasture), p);
                    }
                }
                curr_ttg = ttg;
            }
        }