Esempio n. 1
0
        public void Run()
        {
            Console.WriteLine("Running study case process...");
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Mars right and top coordinate: 5 and 5");
            var localMars = new Mars(5, 5);

            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Add first rover on position: 1 2 N");
            localMars.AddRover(1, 2, Direction.N);

            Console.WriteLine("Run control command in first rover: LMLMLMLMM");
            localMars.ProcessControlCommands("LMLMLMLMM");

            Console.Write("First rover current position: ");
            Console.WriteLine(localMars.GetRoverPosition());

            Console.WriteLine("-----------------------------------");
            Console.WriteLine("Add second rover on position: 3 3 E");
            localMars.AddRover(3, 3, Direction.E, true);

            Console.WriteLine("Run control command in second rover: MMRMMRMRRM");
            localMars.ProcessControlCommands("MMRMMRMRRM");

            Console.Write("Second rover current position: ");
            Console.WriteLine(localMars.GetRoverPosition());
            Console.WriteLine("-----------------------------------");
        }
Esempio n. 2
0
        private void AddNewRover()
        {
            Console.WriteLine("-----------------------------------");
            Console.WriteLine("2 - Add New Rover");
            ValidateMars(false);

            Console.Write("Please enter x coordinate: ");
            string xString = Console.ReadLine();

            Console.Write("Please enter y coordinate: ");
            string yString = Console.ReadLine();

            Console.Write("Please enter facing direction (N,S,E,W): ");
            string facingString = Console.ReadLine();

            Console.Write("Mark new vehicle actively? (Y/N): ");
            string activeString = Console.ReadLine();

            bool widthParse = int.TryParse(xString, out var x);

            bool heightParse = int.TryParse(yString, out var y);

            bool facingParse = Enum.TryParse(facingString, out Direction facing);

            bool active = activeString == "Y";

            if (!widthParse || !heightParse || !facingParse)
            {
                throw new Exception("x - y coordinate or facing is invalid, please try again.");
            }

            mars.AddRover(x, y, facing, active);
            Console.WriteLine("-----------------------------------");
        }