Пример #1
0
        public void Run(MapCoordinates mapCoordinate)
        {
            if (mapCoordinate == null)
            {
                throw new ArgumentNullException();
            }

            foreach (var move in this.Movement)
            {
                if ((roverCoordinate.XPoint < mapCoordinate.X || roverCoordinate.YPoint < mapCoordinate.Y) &&
                    roverCoordinate.XPoint >= 0 || roverCoordinate.YPoint >= 0)
                {
                    if (move == 'M')
                    {
                        if (roverCoordinate.Heading == 'N' || roverCoordinate.Heading == 'E' || roverCoordinate.Heading == 'W' || roverCoordinate.Heading == 'S')
                        {
                            var stepcount = direction.GetStepCount(roverCoordinate.Heading);
                            if (direction.GetAxis(roverCoordinate.Heading) == 'Y')
                            {
                                roverCoordinate.YPoint = roverCoordinate.YPoint + stepcount;
                            }
                            else if (direction.GetAxis(roverCoordinate.Heading) == 'X')
                            {
                                roverCoordinate.XPoint = roverCoordinate.XPoint + stepcount;
                            }
                        }
                    }
                }

                roverCoordinate.Heading = direction.GetDirection(roverCoordinate.Heading.ToString() + move.ToString());
            }
        }