예제 #1
0
        private IFlower GetTargetFlowerCloserToBee(IBee bee, List <IFlower> blossomingFlowers)
        {
            int minimumDistance = -1;
            int flowerIndex     = -1;

            for (var i = 0; i < blossomingFlowers.Count; i++)
            {
                if (blossomingFlowers[i].FlowerPollenArea.Width != 0 && blossomingFlowers[i].FlowerPollenArea.Height != 0)
                {
                    var distance = _interactionManager.GetDistanceBetweenObjectAandObjectB(bee.BeeInOuterWorldSize, blossomingFlowers[i].FlowerPollenArea);
                    if (i == 0)
                    {
                        minimumDistance = distance;
                        flowerIndex     = i;
                    }
                    else if (distance < minimumDistance)
                    {
                        minimumDistance = distance;
                        flowerIndex     = i;
                    }
                }
            }
            var selectedFlower = (flowerIndex != -1) ? blossomingFlowers[flowerIndex] : null;

            return(selectedFlower);
        }