Beispiel #1
0
        public void Should_FindNeighbourTile_When_RequestedDirectionIsNorth()
        {
            var x    = 5;
            var y    = 5;
            var tile = new Tile(x, y);

            var neighbourTilePosition = tile.FindNeighbourTilePosition(directionManager.GetDirections().First(d => d.Code == "N"));

            Assert.AreEqual(y + 1, neighbourTilePosition.Y);
            Assert.AreEqual(x, neighbourTilePosition.X);
        }
Beispiel #2
0
        public void Should_LandAtOriginTile_When_NoSpesificPositionGiven()
        {
            var planet    = new Planet().With(10, 20, "TestPlanet");
            var direction = directionManager.GetDirections().First(d => d.Code == "N");
            var rover     = context.Resolve <Rover>();

            var roverLocation = rover.Land(planet, direction);

            Assert.AreEqual(planet.GetOriginTile().Position, roverLocation.Position);
            Assert.AreEqual(direction, roverLocation.Direction);
        }
        public void Should_MoveNorth_When_TargetTileIsExist()
        {
            int x = 5, y = 5;
            var planet    = new Planet().With(10, 20, "TestPlanet");
            var direction = directionManager.GetDirections().First(d => d.Code == "N");
            var location  = new Location().With(new Position(x, y), direction);
            var rover     = context.Resolve <Rover>();

            rover.Land(planet, location);

            var expectedLocationAfterMove = new Location().With(new Position(x, y + 1), direction);
            var command = commandManager.GetCommands().First(c => c.Code == "M");

            commandManager.Apply(rover, command);


            Assert.AreEqual(expectedLocationAfterMove.Position, rover.Location.Position);
            Assert.AreEqual(expectedLocationAfterMove.Direction, rover.Location.Direction);
        }
Beispiel #4
0
        static Rover CreateRover(IRoverInfoConverter roverInfoConverter, Planet planet)
        {
            var position  = new Position(roverInfoConverter.PositionConverter.X, roverInfoConverter.PositionConverter.Y);
            var direction =
                DirectionManager.GetDirections()
                .First(x => x.Degree == roverInfoConverter.DirectionConverter.Degree);
            var location = new Location().With(position, direction);

            return(RoverManager.CreateRoverAndLand(planet, location));
        }
        public void Handle(RotationCommand command, ICommandOwner commandOwner)
        {
            if (commandOwner is IRotateable)
            {
                var directionOwner = ((IDirectionOwner)commandOwner);

                var newDegree = directionOwner.Direction.Degree.Add(command.Degree);

                var newDirection = directionManager.GetDirections().First(x => x.Degree == newDegree);

                directionOwner.SetDirection(newDirection);
            }
        }