コード例 #1
0
        internal static void MovingRover(Plateau plateau, ref RoverPostion rover)
        {
            while (true)
            {
                Console.WriteLine("Please enter moving command or enter 'exit' for closing application.");
                var command = Console.ReadLine();
                if (command.ToUpper() == "EXIT")
                {
                    Environment.Exit(0);
                }

                rover.StartRoverMoving(plateau, command, ref rover);
                if (!rover.IsMoveSuccess)
                {
                    break;
                }
                Console.WriteLine(String.Format("Rover current position is {0}", rover.CurrentPosition));
            }
        }
コード例 #2
0
        public RoverPostion SetInitialPosition(Plateau platueCordinates, ref RoverPostion rover)
        {
            while (true)
            {
                Console.WriteLine("Enter start position in <x,y,Directio> format where direction can be N, S, E, W");
                try
                {
                    var intialPosition = Console.ReadLine().Trim().Split(',');
                    if (intialPosition.Count() == 3)
                    {
                        int x = Convert.ToInt32(intialPosition[0]);
                        int y = Convert.ToInt32(intialPosition[1]);
                        if ((x < 0 || x > platueCordinates.Wiidth) || (y < 0 || y > platueCordinates.Height))
                        {
                            rover.IsMoveSuccess = false;
                            rover.ErrorMessage  = $"Rover can not be moved out of boundries 0,0 and {platueCordinates.Wiidth},{platueCordinates.Height}";
                            break;
                        }

                        Directions direction = (Directions)Enum.Parse(typeof(Directions), intialPosition[2]);
                        rover.X         = x;
                        rover.Y         = y;
                        rover.Direction = direction;
                    }
                    else
                    {
                        throw new Exception();
                    }

                    break;
                }
                catch (Exception)
                {
                    Console.WriteLine("Please provide input in corrrect formatin <x,y,Directio> format where direction can be N, S, E, W");
                }
            }
            rover.IsMoveSuccess = true;
            rover.ErrorMessage  = "";
            return(rover);
        }
コード例 #3
0
ファイル: Plateau.cs プロジェクト: Harshil12/RobotRover
        internal static Plateau SetPlateauBoundries()
        {
            Console.WriteLine("Please enter boundris for Plateau in <width,height> e.g. 2,5");
            while (true)
            {
                try
                {
                    var boundries = Console.ReadLine().Trim().Split(',').Select(int.Parse).ToList();

                    if (boundries.Count != 2)
                    {
                        throw new Exception("Please provide in correct format");
                    }

                    // Set max height and max width
                    Plateau plateau = new Plateau(boundries[0], boundries[1]);
                    return(plateau);
                }
                catch (Exception)
                {
                    Console.WriteLine("Please provide input in corrrect format.<width,height> e.g. 2,5");
                }
            }
        }