コード例 #1
0
        /**
         * parses chararray. Accepts 'L','M','R' as input, nothing else.
         */
        public void parse(String input)
        {
            char[] arrayVer = input.ToUpper().ToCharArray();

            foreach (char k in arrayVer)
            {
                if (k == 'L' || k == 'R')
                {
                    direction(k);
                }
                else if (k == 'M')
                {
                    MarsSurface.traverse(currentDirection);
                }
                else
                {
                    throw new System.ArrayTypeMismatchException("Invalid char was found: " + k);
                }
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Please enter a map size.");
            String[] mapSize = System.Console.ReadLine().Split(' ');
            if (mapSize.Length != 2)
            {
                System.Console.WriteLine("This must be at least a 2 by 2 map.");
            }
            else
            {
                try
                {
                    System.Console.WriteLine("Please enter the starting point of the rover.");
                    surface = new MarsSurface(Convert.ToInt32(mapSize[0]), Convert.ToInt32(mapSize[1]));
                    String input   = System.Console.ReadLine();
                    String initLoc = "";
                    while (input != null)
                    {
                        if (input.Contains(" "))
                        {
                            initLoc = input;
                        }
                        else
                        {
                            repeat(initLoc.Split(' '), input);
                            listAllLocations(roverLocations);
                        }

                        input = System.Console.ReadLine();
                    }
                    System.Console.WriteLine("Next");
                    listAllLocations(roverLocations);
                }
                catch (System.FormatException e)
                {
                    System.Console.WriteLine("The integers were not correctly read.");
                    System.Console.WriteLine(e.Message);
                }
            }
        }