コード例 #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()
        {
            if (isAlive)
            {
                if (curr_ttm == 0)
                {
                    move();
                }
                else if (curr_ttr == 0)
                {
                    grow();
                }
                else
                {
                    eat(pasture.GetPosition(this));
                    curr_ttm--;
                    curr_ttr--;
                }

                if (curr_ttl == 0)
                {
                    pasture.RemoveEntity(this);
                }
            }
        }