Esempio n. 1
0
 public static void InitRover()
 {
     Rover = new UltimateRover
     {
         CurrPosition = new Position {
             X = 1, Y = 1
         },
         Landscape = new Position {
             X = 10, Y = 10
         },
         Orientation = Orientation.N
     };
 }
Esempio n. 2
0
        static void Main(string[] args)
        {
            string moves = "";

            try
            {
                UltimateRover Rover = FileParser.Parsefile(out moves);
                Rover.ExecuteCommand(moves);

                Console.Write($"Final Position - {Rover.CurrPosition.X},{Rover.CurrPosition.Y} Orientation - {Rover.Orientation}");
                Console.Read();
            }
            catch (Exception ex)
            {
                Console.Write(ex.Message);
                Console.Read();
            }
        }
Esempio n. 3
0
        public static UltimateRover Parsefile(out string moves)
        {
            try
            {
                string path     = ConfigurationManager.AppSettings["filePath"];
                var    readText = File.ReadAllLines(path);

                UltimateRover Rover = new UltimateRover()
                {
                    CurrPosition = new Position(),
                    Landscape    = new Position(),
                    Orientation  = Orientation.Undefined
                };

                string landScape = readText[0].Trim();
                int    coDigits  = landScape.Length / 2;

                Rover.Landscape.X = Convert.ToInt32(landScape.Substring(0, coDigits));
                Rover.Landscape.Y = Convert.ToInt32(landScape.Substring(coDigits));

                string   currPos      = readText[1].Trim();
                string[] currPosSplit = currPos.Split(' ');

                Rover.CurrPosition.X = Convert.ToInt32(currPosSplit[0].Substring(0, coDigits));
                Rover.CurrPosition.Y = Convert.ToInt32(currPosSplit[0].Substring(coDigits));

                Rover.Orientation = (Contracts.Orientation)Enum.Parse(typeof(Contracts.Orientation), currPosSplit[1]);

                moves = readText[2].Trim();

                return(Rover);
            }
            catch (Exception ex)
            {
                throw new Exception("File parsing failed - " + ex.Message);
            }
        }