Exemplo n.º 1
0
 public MarsRover(Grid map, Int32 xCoordinate, Int32 yCoordinate, Char initialDirection)
 {
     this.XCoordinate = xCoordinate;
     this.YCoordinate = yCoordinate;
     this.roverState = setInitialState(initialDirection);
     map.PlaceRover(this, xCoordinate, yCoordinate, initialDirection);
     roverController = new MarsRoverController(map);
 }
Exemplo n.º 2
0
        //method to assign grid to rover
        public void assignGrid(Grid grid)
        {
            this.grid = grid;

            if (grid.obstacles.Contains(currentPos))
            {
                Console.Write("Grid has obstacle at rover starting position. Landed rover at ");
                //verify that current position of rover is not an obstacle
                while (grid.obstacles.Contains(currentPos))
                    moveForward();

                Console.Write("(" + currentPos.X + ", " + currentPos.Y + ") instead\n");
            }
        }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            Grid grid = new Grid();
            Rover rover = new Rover();

            Console.WriteLine("Landing rover at (" + rover.currentPos.X + ", " + rover.currentPos.Y + ")... landed");
            rover.assignGrid(grid);

            string input;
            Console.WriteLine("Move forward(f), move backward(b), turn left(l), turn right(r) OR exit:");
            input = Console.ReadLine();

            while(!input.Equals("exit"))
            {
                bool lastMoveSuccess = true;

                foreach (char ch in input)
                {
                    //break out of loop if encountered obstacle
                    if(lastMoveSuccess == false)
                        break;

                    //switch ignore other non valid commands
                    switch(ch)
                    {
                        case 'f':   lastMoveSuccess = rover.moveForward();
                            break;

                        case 'b':    lastMoveSuccess = rover.moveBackward();
                            break;

                        case 'l':   rover.turnLeft();
                            break;

                        case 'r':   rover.turnRight();
                            break;
                    }
                }

                rover.displayNewPosition();

                Console.WriteLine("Move forward(f), move backward(b), turn left(l), turn right(r) OR exit:");
                input = Console.ReadLine();
            }
        }
Exemplo n.º 4
0
 public void SetUp()
 {
     grid = new Grid(5, 5);
     marsRover = new MarsRover(InitialXCoordinate, InitialYCoordinate, InitialRoverDirection);
 }
Exemplo n.º 5
0
 public void RunAllInitializations()
 {
     var defaultGrid = new Grid(5, 5);
     Assert.IsNotNull(defaultGrid);
 }
 public MarsRoverController(Grid map)
 {
     roverModel = new MarsRoverModel(map);
 }