예제 #1
0
        public void Test_Rover_Turns_North()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "W";
            Navigation navigation = new Navigation(rover);

            rover.Command_Parser("R");

            Assert.AreEqual("N", navigation.GetDirectionalHeading());
        }
예제 #2
0
        public void Test_For_Obstacle_Detection()
        {
            Rover rover = new Rover();
            rover.PositionHeading = "E";
            Navigation navigation = new Navigation(rover);
            string headingIndex = navigation.GetDirectionalHeading();
            rover.PositionY = 0;
            rover.PositionX = 0;

            rover.LandscapeHeight = 5;
            rover.LandscapeWidth = 5;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(false);

            //set obstacle
            Coordinates crd = new Coordinates{

                 xCoordinate = 1,
                 yCoordinate =0
            };
            Coordinates coor = (from Coordinates in rover.gridCoordinates
                                where Coordinates.xCoordinate == 1 && Coordinates.yCoordinate == 0
                                select Coordinates).FirstOrDefault<Coordinates>();
            bool notNull = coor != null;
            int indexOf = -1;
            if(coor != null)
            {
                indexOf = rover.gridCoordinates.IndexOf(coor);
            }

            //int indexOf = rover.gridCoordinates.IndexOf(crd);
            bool hasIndex = indexOf > 0;
            if (hasIndex)
            {
                rover.gridCoordinates[indexOf].containsObstacle = true;
            }

            string rtnMessage = "";
            char[] cmds = ("f").ToCharArray();
            while (!rover.ReportObstacle)
            {
                foreach (char c in cmds)
                {
                    rtnMessage = rover.Command_Parser(c.ToString());
                }
                //break;
            }

            Assert.AreEqual(true, rtnMessage.Contains("Obst"));
        }
예제 #3
0
        static void Main(string[] args)
        {
            string commands = "'F','B','L','R', or 'Q' to quit";
            Console.WriteLine("Hello Rover\r");
            Console.WriteLine("Enter 'Q' to quit.\n");
            Console.WriteLine(string.Format("Accepted commands are: {0}\n", commands));
            Console.WriteLine("Please enter Rover's first command: \r");
            string keyInput = Console.ReadLine();

            //init rover
            Rover rover = new Rover();

            rover.PositionHeading = "N";
            rover.PositionX = 0;
            rover.PositionY = 0;

            rover.LandscapeWidth = 15;
            rover.LandscapeHeight = 5;
            Landscape landscape = new Landscape(rover);
            landscape.BuildLandscapeGrid(true);

            while (keyInput != "q" && keyInput != "Q")
            {
                char[] cmds = keyInput.ToCharArray();
                string outputMessage = "";
                while (!rover.ObstacleFound)
                {
                    foreach (char c in cmds)
                    {
                        if (!rover.acceptedCommands.Contains(c.ToString()))
                        {
                            Console.WriteLine(string.Format("Invalid command recieved will ingore command: {0}", c));
                        }
                        else
                        {
                            outputMessage = rover.Command_Parser(c.ToString());
                        }
                    }
                    break;
                }
                rover.ObstacleFound = false;
                Console.WriteLine(outputMessage + "\n");
                Console.WriteLine(string.Format("\rRover ready for command ({0}):", commands));
                keyInput = Console.ReadLine();

            }

            Console.WriteLine("\nEXIT");
        }