protected void GivenRoverWithDirection(IDirectionState direction)
        {
            var coordinate = new Coordinate(5, 5);
            var plateau = new Plateau(100, 100);

            Rover = new Rover(plateau, coordinate, direction);
        }
Exemplo n.º 2
0
 public StateMachine(IDirectionState directionManager)
 {
     _directionManager = directionManager;
     _occupiedGrids    = new List <GridPosition>();
     GridBoundary      = new GridPosition {
         XPos = int.MaxValue, YPos = int.MaxValue
     };
 }
Exemplo n.º 3
0
        private Rover GetRover(MarsArea marsArea, string locationText)
        {
            RoverLocation roverLocation = GetRoverLocation(locationText);

            IDirectionState directionState = GetDirectionState(locationText);
            ILocation       location       = new Location(marsArea, roverLocation);

            return(new Rover(directionState, location));
        }
Exemplo n.º 4
0
 private string GetDirectionStateKey(IDirectionState directionState)
 {
     return(directionState switch
     {
         NorthState => Constant.NORTH_KEY,
         EastState => Constant.EAST_KEY,
         WestState => Constant.WEST_KEY,
         SouthState => Constant.SOUTH_KEY,
         _ => throw new Exception(Constant.UNDEFINED_DIRECTION)
     });
Exemplo n.º 5
0
        public void FirstLocation_WhenMoveForward_ThenLastLocation(IDirectionState directionState, RoverLocation expectedRoverLocation)
        {
            //Given
            ILocation location = new Location(_defaultMarsArea, _defaultRoverLocation);

            //When
            location.MoveForward(directionState);

            //Then
            location.GetRoverLocation().Should().BeEquivalentTo(expectedRoverLocation);
        }
Exemplo n.º 6
0
        public void Direction_WhenTurnDirection_ThenExpectedDirection(IDirectionState directionState, Type leftDirectionType, Type rightDirectionType)
        {
            //Given from parameter

            //When
            IDirectionState turnedLeftDirectionState  = directionState.TurnLeft();
            IDirectionState turnedRightDirectionState = directionState.TurnRight();

            //Then
            Assert.AreEqual(turnedLeftDirectionState.GetType(), leftDirectionType);
            Assert.AreEqual(turnedRightDirectionState.GetType(), rightDirectionType);
        }
Exemplo n.º 7
0
        public void MoveForward(IDirectionState directionState)
        {
            switch (directionState)
            {
            case NorthState: MoveNorth();
                break;

            case EastState: MoveEast();
                break;

            case WestState: MoveWest();
                break;

            case SouthState: MoveSouth();
                break;

            default:
                throw new Exception(Constant.UNDEFINED_DIRECTION);
            }
            ;
        }
        void IEcsRunSystem.Run()
        {
            if (!_restartEventFilter.IsEmpty())
            {
                foreach (var index in _filter)
                {
                    ref var turtlePath = ref _filter.Get1(index);
                    var     paths      = turtlePath.Path;
                    paths.Clear();

                    _direction = new RightDirectionState();

                    for (var i = 0; i < _turtleConfiguration.PathsCount; i++)
                    {
                        paths.Add(GeneratePath());
                    }

                    var     entity          = _filter.GetEntity(index);
                    ref var updateTextEvent = ref entity.Get <UpdateTextEvent>();
                    updateTextEvent.Text = string.Join("", paths[0]);

                    turtlePath.CurrentPath   = 0;
                    turtlePath.CurrentSymbol = 0;
                }
Exemplo n.º 9
0
 protected void UpdateStatus(Position position, Direction direction, IDirectionState state)
 {
     OnchangeDirectionEvent?.Invoke(position, direction, state);
 }
Exemplo n.º 10
0
 void UpdateStatus(Position position, Direction direction, IDirectionState state)
 {
     Position  = position;
     Direction = direction;
     UpdateEvents(state);
 }
Exemplo n.º 11
0
 public void TurnRight()
 {
     _directionState = _directionState.TurnRight();
 }
Exemplo n.º 12
0
 public Rover(IDirectionState directionState, ILocation location)
 {
     _directionState = directionState;
     _location       = location;
 }
Exemplo n.º 13
0
 public void TurnRight()
 {
     Direction = Direction.Right();
 }
Exemplo n.º 14
0
 public void TurnLeft()
 {
     _directionState = _directionState.TurnLeft();
 }
Exemplo n.º 15
0
 public void TurnLeft()
 {
     Direction = Direction.Left();
 }
Exemplo n.º 16
0
 public Rover(Plateau plateau, Coordinate coordinate, IDirectionState direction)
 {
     this.Coordinate = coordinate;
     this.Direction = direction;
     this.plateau = plateau;
 }
 public RoverPosition(Coordinate coordinate, IDirectionState direction)
 {
     this.Coordinate = coordinate;
     this.Direction = direction;
 }
Exemplo n.º 18
0
 void UpdateEvents(IDirectionState newstate)
 {
     MachineState.OnchangeDirectionEvent -= UpdateStatus;
     MachineState = newstate;
     MachineState.OnchangeDirectionEvent += UpdateStatus;
 }
Exemplo n.º 19
0
 public void Setup()
 {
     _directionManager = new DirectionManager();
     stateMachine      = new StateMachine.StateMachine(_directionManager);
 }