Exemplo n.º 1
0
        public ChaosUnitController(EnemyController unit,
                                   UnitsCountNotifier unitsCountNotifier,
                                   IOccupatedPossitionsMap occupatedPossitionsMap,
                                   UnitNameResolver unitNameResolver,
                                   ChaosBattlefield.SquareArea area)
        {
            _unit = unit;
            _occupatedPossitionsMap = occupatedPossitionsMap;
            _unitsCountNotifier     = unitsCountNotifier;
            _unitNameResolver       = unitNameResolver;
            _unitName = _unitNameResolver.ResolveNextName();
            _area     = area;

            Initialize();
        }
Exemplo n.º 2
0
        private IOneUnitController GetNearestUnitInArea(ChaosBattlefield.SquareArea area, IntVector2 unitPosition)
        {
            var unitsWithDistances = new Dictionary <IOneUnitController, int>();

            var unitsInRegion = _occupatedPossitionsMap.GetUnitsInRegion(area.TopLeft, area.BottomRight);

            unitsInRegion.ForEach(u =>
            {
                if (!u.Position.Equals(unitPosition) && !(u is PlayerController))
                {
                    unitsWithDistances.Add(u, u.Position.GetEmpiricalValueForPoint(unitPosition));
                }
            });

            if (unitsWithDistances.Count == 0)
            {
                return(null);
            }

            var ordered = unitsWithDistances.OrderBy(u => u.Value);

            return(ordered.First().Key);
        }