Beispiel #1
0
        public IntVector2 GetFreePoint(IntVector2 position)
        {
            var adjacentPoints = _adjacentPointsResolver.GetFreeAdjacentUnitPoints(position,
                                                                                   IsValidPosition);

            var occupiedPossitions = _occupatedPossitionsMap.GetOccupiedPositionsExcept(_baseActionController.Position);

            List <IntVector2Info> vectorInfos = new List <IntVector2Info>();

            adjacentPoints.ForEach(i => { vectorInfos.Add(new IntVector2Info(i, position, _baseActionController.Position, occupiedPossitions)); });

            var result = vectorInfos.OrderBy(i => i.AcceptableIndex).ToList();

            for (int i = 0; i < result.Count; i++)
            {
                if (IsAchivable(result[i].Vector))
                {
                    return(result[i].Vector);
                }
            }

            if (!result.Any())
            {
                ApplicationDebugger.ThrowException("FreePointToGoResolver: There is no available points");
            }

            return(IntVector2Constant.UNASSIGNET);
        }
Beispiel #2
0
        private IntVector2 GetAttackTargetPosition()
        {
            if (_unitInfo.AttackTarget == null || _unitInfo.AttackTarget.Position.Equals(IntVector2Constant.UNASSIGNET))
            {
                ApplicationDebugger.ThrowException(GetType().Name + ": " + "unitInfo.AttackTarget cannot be NULL");
            }

            return(_unitInfo.AttackTarget.Position);
        }
Beispiel #3
0
        public void SetOnPosition(IntVector2 position)
        {
            if (!_occupatedPossitionsMap.IsVacantPosition(position))
            {
                ApplicationDebugger.ThrowException(
                    String.Format("OneUnitController.SetOnPosition: position {0} {1} has already taken", position.x, position.y));
                return;
            }

            _stateController.CurrentState.SetOnPosition(position);
        }
Beispiel #4
0
        public void Attack(IntVector2 position)
        {
            var adjacentPoints = _motionController.Position.GetAdjacentPoints();

            if (!adjacentPoints.Contains(position))
            {
                ApplicationDebugger.ThrowException("Attacked possition isn't in unit range");
            }

            _rotationController.Rotate(_motionController.Position, position);
            _animationController.PlayAttackAnimation();
        }
Beispiel #5
0
        private IntVector2 GetFreePosition(SquareArea area)
        {
            var freePositions = _occupatedPossitionsMap.GetFreePositionsInRegion(area.TopLeft, area.BottomRight);

            if (freePositions.Count == 0)
            {
                ApplicationDebugger.ThrowException("ChaosBattlefield: no free positions");
            }
            var rand = _random.Next(freePositions.Count);

            return(freePositions[rand]);
        }
Beispiel #6
0
        public static int GetEmpiricalValueForPoint(this IntVector2 point, IntVector2 otherPoint)
        {
            if (otherPoint.Equals(IntVector2Constant.UNASSIGNET) || point.Equals(IntVector2Constant.UNASSIGNET))
            {
                ApplicationDebugger.ThrowException("IntVector2 EmpiricalValue for UNASSIGNET IntVector2");
            }

            var    t  = Math.Sqrt(Math.Pow(point.x - otherPoint.x, 2) + Math.Pow(point.y - otherPoint.y, 2));
            double r1 = t * 10.0;
            int    r  = (int)r1;

            return(r);
        }
Beispiel #7
0
        public List <IntVector2> GetFreeAdjacentUnitPoints(IntVector2 unitPosition, Predicate <IntVector2> isValid, int radiusValue = 1)
        {
            var adjacentPoints = new List <IntVector2>();

            while (radiusValue < 5)
            {
                adjacentPoints = unitPosition.GetAdjacentPoints(isValid, radiusValue);
                if (adjacentPoints.Any())
                {
                    return(adjacentPoints);
                }

                radiusValue++;
            }

            ApplicationDebugger.ThrowException("AdjacentPointsResolver: There are no adjacent points in unit range");
            throw new Exception();
        }
Beispiel #8
0
        public static List <IntVector2> GetAdjacentPoints(this IntVector2 point, Predicate <IntVector2> isValid = null, int radiusValue = 1)
        {
            if (radiusValue <= 0)
            {
                ApplicationDebugger.ThrowException("IntVector2 radiusValue cannot be less than 1");
            }

            var resultList = new List <IntVector2>();
            var b          = GetPointsInRange(point, isValid, radiusValue);
            var s          = GetPointsInRange(point, isValid, radiusValue - 1);

            b.ForEach(i =>
            {
                if (!s.Contains(i))
                {
                    resultList.Add(i);
                }
            });

            return(resultList);
        }