Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Please provide upper-right coordinates of the plateau");
            Plateau plateau = InputParser.CreatePlateau();

            InsertRoverInformation();
            Console.WriteLine("Would you like to add another rover? Y/N");


            while (Console.ReadKey().KeyChar == 'Y' || Console.ReadKey().KeyChar == 'y')
            {
                Console.WriteLine();
                InsertRoverInformation();
                Console.WriteLine("Would you like to add another rover? Y/N");
            }

            Console.WriteLine();
            foreach (var roverCommand in roversCommands)
            {
                RoverController controller = new RoverController(roverCommand.Item1, plateau);
                controller.Travel(roverCommand.Item2);
                roverCommand.Item1.PrintState();
            }
            Console.ReadLine();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            // notes
            // if try to move outside bounds of perimiter, it will move to the edge in that direction and not throw an error
            // default plateau size is 0,0 to infinity unless set

            var plateau = new Plateau();

            plateau.SetGridSize(40, 30);

            // this needed to handle multiple rovers
            var RoverController = new RoverController(plateau);

            var rover = new Rover(RoverController);

            rover.SetPosition(10, 10, "N");
            rover.Move("R1R3L2L1");

            Console.WriteLine(rover.ToString());

            // if uncommented this will throw excepton as robots crash
            // var rover2 = new Rover(RoverController);
            // rover2.SetPosition(10, 10, "N");
            // rover2.Move("R1R3L2L3");
            // Console.WriteLine(rover2.ToString());

            Console.ReadLine();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            var rover = new RoverController();

            Console.Write("Enter the upper right coordinates: ");
            rover.UpperRightCoordinates = Console.ReadLine();

            Console.Write($"Enter the number of rovers you want to deploy on the plateau (Max = {rover.MaxNumberOfRovers}): ");
            rover.NumberOfRovers = int.Parse(Console.ReadLine());

            Console.WriteLine("Position format: X Y O");
            Console.WriteLine("Please take note of the Rover Id#\n");

            for (int i = 0; i < rover.NumberOfRovers; i++)
            {
                Console.Write($"Enter the position for Rover Id# {i + 1}: ");
                var position = Console.ReadLine();
                rover.Deploy(position);
            }

            while (true)
            {
                Console.Clear();
                Console.WriteLine();
                rover.Plateau.Draw(rover.ListOfRovers, rover.UpperRightCoordinates);
                Console.WriteLine();
                DisplayControlInstructions();

                var command = Console.ReadLine().ToUpper();
                if (command == "Q")
                {
                    break;
                }

                var spaceIndex = command.IndexOf(" ");
                var roverId    = int.Parse(command.Substring(0, spaceIndex));
                if (roverId < 1 || roverId > rover.ListOfRovers.Count)
                {
                    Console.WriteLine($"Invalid Rover Id#. Should be between 1 and {rover.ListOfRovers.Count}.\n");
                    continue;
                }

                var instructions = command.Substring(spaceIndex + 1);
                rover.ListOfRovers[roverId - 1].Explore(instructions);

                for (int i = 0; i < rover.ListOfRovers.Count; i++)
                {
                    Console.WriteLine($"Rover Id#{i + 1}: {rover.ListOfRovers[i].Position}");
                }
            }

            Console.Clear();
            for (int i = 0; i < rover.ListOfRovers.Count; i++)
            {
                Console.WriteLine($"Rover Id#{i + 1}: {rover.ListOfRovers[i].Position}");
            }
            Console.WriteLine();
            rover.Plateau.Draw(rover.ListOfRovers, rover.UpperRightCoordinates);
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            string path = "instructions.txt";

            string[] instructions = File.ReadAllLines(path);

            RoverController rc       = new RoverController();
            string          response = rc.ReadInstructions(instructions);

            Console.WriteLine(response);

            Console.ReadLine();
        }
Ejemplo n.º 5
0
        static void Main(string[] args)
        {
            #region First Rover details


            var rover1      = new RoverData();
            var coordinates = new Coordinates
            {
                X = 1,
                Y = 1
            };

            var route = new Route
            {
                Time        = DateTime.Now,
                Coordinates = new List <Coordinates>()
                {
                    coordinates
                }
            };


            var roverStrategy1   = new RoverMovementStrategy(rover1, coordinates);
            var roverController1 = new RoverController(rover1, roverStrategy1, null);


            var rover1Commands = "";

            do
            {
                Console.WriteLine("\tW");
                Console.WriteLine("\tA");
                Console.WriteLine("\tS");
                Console.WriteLine("\tD");
                Console.WriteLine();
                Console.Write("Enter command:");
                rover1Commands = Console.ReadLine();
                roverController1.Move(rover1Commands);

                Console.WriteLine($"Rover one ->: ({DateTime.Now}) " +
                                  $"Coordinates are :({coordinates.X},{coordinates.Y})");

                InitializeRoverToDB(rover1);
            } while (rover1Commands.CompareTo("x") < 0);

            // InitializeRoverToDB(rover1);

            #endregion

            /*   roverController1.Move(rover1Commands);
             *
             *
             * Console.WriteLine($"Rover one final position is " +
             *                   $"({rover1.Position.X},{rover1.Position.Y}) " +
             *                   $"and orientation {rover1.Orientation.ToDescription()}");
             #endregion
             * /*
             #region Second Rover details
             * var rover2 = new Rover();
             * var roverStrategy2 = new RoverMovementStrategy(rover1);
             * var roverController2 = new RoverController(rover1, roverStrategy2, map);
             * rover1.Position = new Coordinates { X = map.ElementAt(3).ElementAt(3).X, Y = map.ElementAt(3).ElementAt(3).Y };
             * rover1.Orientation = Orientation.E;
             *
             * var rover2Commands = "MMRMMRMRRM";
             * roverController2.Move(rover2Commands);
             * Console.WriteLine($"Rover two final position is " +
             *                   $"({rover1.Position.X},{rover1.Position.Y}) " +
             *                   $"and orientation {rover1.Orientation.ToDescription()}");
             *
             #endregion
             *
             * Console.WriteLine("\nExploring Mars!");
             * Console.ReadKey();
             * }
             */
            Console.ReadKey();
        }
Ejemplo n.º 6
0
 public Rover(RoverController roverController)
 {
     RoverController = roverController;
     roverController.AddRover(this);
     //Plateau = plateau;
 }