Ejemplo n.º 1
0
        public void MoveTo_AnyPath_ShouldRiseMovePathComplete(List <IntVector2> path, int i1, int i2)
        {
            // Arrange
            bool movePathCompleteCalled = false;

            Mock.Arrange(() => _occupatedPossitionsMap.IsVacantPosition(Arg.IsAny <IntVector2>()))
            .Returns(true);

            _moveStepByStepController = CreateMoveStepByStepController();
            _moveStepByStepController.MovePathComplete += () => movePathCompleteCalled = true;

            // Act
            _moveStepByStepController.MoveTo(path);

            // Assert
            Assert.True(movePathCompleteCalled);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
0
 private void TargetUnitPositionChanged(IntVector2 position)
 {
     _targetUnit.UnitEvents.PositionChanged -= TargetUnitPositionChanged;
     if (_occupatedPossitionsMap.IsVacantPosition(_occupiedPoint))
     {
         MoveToDestination();
     }
     else
     {
         WaitUnitOnPosition(_occupiedPoint);
     }
 }
Ejemplo n.º 4
0
        public static List <IOneUnitController> GetUnitsInRegion(this IOccupatedPossitionsMap possitionsMap,
                                                                 IntVector2 point1, IntVector2 point2)
        {
            var units       = new List <IOneUnitController>();
            var loopParamsI = new LoopPaprams(point1.x, point2.x);

            for (int i = loopParamsI.StartValue; loopParamsI.Condition(i); i = loopParamsI.Operation(i))
            {
                var loopParamsJ = new LoopPaprams(point1.y, point2.y);
                for (int j = loopParamsJ.StartValue; loopParamsJ.Condition(j); j = loopParamsJ.Operation(j))
                {
                    if (!possitionsMap.IsVacantPosition(new IntVector2(i, j)))
                    {
                        units.Add(possitionsMap.GetUnitOnPosition(new IntVector2(i, j)));
                    }
                }
            }

            return(units);
        }
Ejemplo n.º 5
0
        private bool IsPositionOccupated(IntVector2 nextPosition)
        {
            if (!_occupatedPossitionsMap.IsVacantPosition(nextPosition))
            {
                _nextOccupiedPossition = nextPosition;

                if (_nextOccupiedPossition.Equals(_destination))
                {
                    NoWayToDestination?.Invoke(_nextOccupiedPossition);
                }
                else
                {
                    NextTileOccupied?.Invoke(_nextOccupiedPossition);
                }

                return true;
            }

            return false;
        }
Ejemplo n.º 6
0
        public static List <IntVector2> GetFreePositionsInRegion(this IOccupatedPossitionsMap possitionsMap,
                                                                 IntVector2 point1, IntVector2 point2)
        {
            var positions    = new List <IntVector2>();
            var tempPosition = IntVector2Constant.UNASSIGNET;

            var loopParamsI = new LoopPaprams(point1.x, point2.x);

            for (int i = loopParamsI.StartValue; loopParamsI.Condition(i); i = loopParamsI.Operation(i))
            {
                var loopParamsJ = new LoopPaprams(point1.y, point2.y);
                for (int j = loopParamsJ.StartValue; loopParamsJ.Condition(j); j = loopParamsJ.Operation(j))
                {
                    tempPosition = new IntVector2(i, j);
                    if (possitionsMap.IsVacantPosition(tempPosition))
                    {
                        positions.Add(tempPosition);
                    }
                }
            }

            return(positions);
        }
Ejemplo n.º 7
0
 public bool IsFreePosition(IntVector2 position)
 {
     return(_grid.GetCell(position) && _occupatedPossitionsMap.IsVacantPosition(position));
 }