示例#1
0
 public Rover(string name, Plateau plateau, Position position)
 {
     _plateau = plateau;
     _movements = new List<Position>();
     Name = name;
     Apply(position);
 }
示例#2
0
        static void Main(string[] args)
        {
            var plateau = new Plateau(5, 5);

            var dispatcher = new DefaultInstructionDispatcher();

            var rover1 = new Rover("Rover 1", plateau, new Position(1, 2, Direction.N));

            dispatcher.Dispatch(rover1, "LMLMLMLMM");

            var rover2 = new Rover("Rover 2", plateau, new Position(3, 3, Direction.E));

            dispatcher.Dispatch(rover2, "MMRMMRMRRM");

            Clear();

            Print(plateau);

            Print(rover1);

            Clear();

            //Print(plateau);

            //Print(rover2);

            Console.WriteLine(rover1);

            Console.WriteLine(rover2);

            Console.ReadLine();
        }
示例#3
0
        static void Print(Plateau plateau)
        {
            for (int i = 0; i <= plateau.Width; i++)
            {
                for (int j = 0; j <= plateau.Height; j++)
                {
                    Console.SetCursorPosition(i, j);

                    Console.Write("#");
                }
            }
        }
示例#4
0
        static void Main(string[] args)
        {
            var surface = new Plateau(5, 5);
            var rover1  = new RoverOperation(surface, "1 2 N", "LMLMLMLMM");
            var rover2  = new RoverOperation(surface, "3 3 E", "MMRMMRMRRM");

            Console.WriteLine("Rover 1");

            Console.WriteLine("XCoordinate : " + rover1.XCoordinate);
            Console.WriteLine("YCoordinate : " + rover1.YCoordinate);
            Console.WriteLine("Direction : " + rover1.Direction);

            Console.WriteLine("Rover 2");

            Console.WriteLine("XCoordinate : " + rover2.XCoordinate);
            Console.WriteLine("YCoordinate : " + rover2.YCoordinate);
            Console.WriteLine("Direction : " + rover2.Direction);
        }
示例#5
0
文件: Program.cs 项目: Thejraj/Rover
        static void Main(string[] args)
        {
            Console.WriteLine("Enter top right corner of plateu");
            var line = Console.ReadLine();
            if (line != null)
            {
                string[] topRightCoOrdinate = line.Split(' ');
                var plateau = new Plateau(StringToInt(topRightCoOrdinate[0]), StringToInt(topRightCoOrdinate[1]));

                while (true)
                {
                    Console.WriteLine("Enter current position of rover");
                    var readLine = Console.ReadLine();

                    if (readLine != null)
                    {
                        var position = readLine.Split(' ');
                        var currentPosition = new CoOrdinates(StringToInt(position[0]), StringToInt(position[1]));
                        var currentDirection = Direction.N.StringToEnum(position[2]);

                        var rover = new RoverObject(currentPosition, currentDirection, plateau);

                        Console.WriteLine("Enter command string");
                        var command = Console.ReadLine();

                        rover.Run(command);
                    }
                    else
                    {
                        Console.WriteLine("Invalid position");
                    }

                    Console.WriteLine("Do you want to exit: (Y/N)");
                    line = Console.ReadLine();
                    if (line == "Y")
                        break;
                }
            }
            Console.ReadKey();
        }
示例#6
0
 public RoverObject(CoOrdinates currentPosition, Direction currentDirection, Plateau plateau)
 {
     CurrentDirection = currentDirection;
     CurrentPosition  = currentPosition;
     Plateau          = plateau;
 }