Пример #1
0
    public ResultObjectDto MoveRover(RoverCommandDto roverCommandDto)
    {
        ResultObjectDto result       = new ResultObjectDto();
        Point           currentPoint = new Point();

        currentPoint.CoordinateX = roverCommandDto.StartCoordinateX;
        currentPoint.CoordinateY = roverCommandDto.StartCoordinateY;
        currentPoint.Direction   = GetDirection(roverCommandDto.StartDirection.ToUpper());

        char[] commandList = roverCommandDto.Commands.ToUpper().ToCharArray();
        foreach (var command in commandList)
        {
            if (command == 'L')
            {
                currentPoint.Direction = TurnLeft(currentPoint.Direction);
            }
            else if (command == 'R')
            {
                currentPoint.Direction = TurnRight(currentPoint.Direction);
            }
            else if (command == 'M')
            {
                currentPoint = Move(currentPoint);
            }
            else
            {
                result.Message   = "Tanımsız bir komut girildiği için rover kilitlendi.";
                result.IsSuccess = false;
                break;
            }
        }

        if (currentPoint.CoordinateY > roverCommandDto.DimensionY || currentPoint.CoordinateX > roverCommandDto.DimensionX)
        {
            result.Message   = "Rover uzay boşluğuna düştü.";
            result.IsSuccess = false;
        }
        else
        {
            result.Message   = "Görev başarıyla tamamlandı.";
            result.IsSuccess = true;
            result.Result    = String.Format("Konum : {0}-{1}-{2}", currentPoint.CoordinateX, currentPoint.CoordinateY, SetDirection(currentPoint.Direction));
        }

        return(result);
    }
 public ActionResult <ResultObjectDto> MarsRover(RoverCommandDto roverCommandDto)
 {
     return(_commandService.MoveRover(roverCommandDto));
 }