Beispiel #1
0
        /// <summary>
        /// Creates and initializes new rover
        /// </summary>
        /// <param name="initialPosition"></param>
        /// <param name="pathValue"></param>
        /// <returns></returns>
        protected RoverBase GetRover(string initialPosition, string pathValue)
        {
            var values = StringOperations.GetSplittedArray <string>(initialPosition);

            var xPosition = Convert.ToInt32(values.ElementAt(0));
            var yPosition = Convert.ToInt32(values.ElementAt(1));
            var direction = DirectionAdapter.GetDirectionByLetter(values.ElementAt(2));

            var path = StringOperations.GetSplittedArray <StepDirection>(pathValue);

            return(new Rover(xPosition, yPosition, direction, path));
        }
Beispiel #2
0
        /// <summary>
        /// Moves the Rover by it's path
        /// </summary>
        public void MoveRover()
        {
            for (int i = 0; i < Rover.Path.Count(); i++)
            {
                if (Rover.Path.ElementAt(i) == StepDirection.MoveForward)
                {
                    Rover.MoveForward();
                }

                var path = Rover.Path.ElementAt(i);
                Console.WriteLine($"Position: {Rover.Position.X}, {Rover.Position.Y}\t Direction {Rover.Direction}\t Path {path.ToString()}");
                var nextDirection = DirectionAdapter.GetNextDirectionByStepDirection(Rover.Direction, path);
                Console.WriteLine($"Next direction: {nextDirection}");
                Rover.Direction = nextDirection;
            }
            Console.WriteLine($"Last Position and Direction:");
            Console.WriteLine($"{Rover.Position.X} {Rover.Position.Y} {Rover.Direction.ToString().Substring(0, 1)}");
        }