Ejemplo n.º 1
0
 public void testGetplateauYlength()
 {
     //Arrange
                                                 plateau plateau = new plateau();
                                                 //Act
                                                 plateau.getplateauYlength();
                                                 //Assert
                                                 Assert.IsTrue(plateau.getplateauYlength() == 0);
 }
Ejemplo n.º 2
0
        public static void Main(String [] args)
        {
            //Creating Objects from class
                                rover rover = new rover() ;
                                plateau plateau = new plateau () ;
                                movement movement = new movement () ;
                                constant constant = new constant() ;

                                //user input plateau size X
                                while(true){
                                    Console.WriteLine(constant.plateauXlength);
                                try{
                                    int plateausizeX = int.Parse(Console.ReadLine());
                                    plateau.setplateauXlength(plateausizeX);
                                    break;
                                }catch(FormatException ){
                                    Console.WriteLine("Enter a valid Plateau length for its X Length");
                            }
                        }

                                //user input plateau size Y
                                while(true){
                                   Console.WriteLine(constant.plateauYlength);
                                try{
                                    int plateausizeY = int.Parse(Console.ReadLine());
                                    plateau.setplateauYlength(plateausizeY);
                                    break;
                                }catch(FormatException  ){
                                    Console.WriteLine("Enter a valid Plateau length for its Y Length");
                            }
                        }

                              do{

                                //user input coordinate X of rover
                                while(true){
                                    Console.WriteLine(constant.messageroverX);
                                try{
                                    int xaxis = int.Parse(Console.ReadLine());
                                    if(xaxis == movement.CodX){
                                        Console.WriteLine("a Rover is already in the position");
                                    }else{

                                    if(xaxis > plateau.getplateauXlength() ){
                                        Console.WriteLine("Out of bound");
                                    }else{

                                    rover.setcoodX(xaxis);
                                    break;
                                    }}
                                }catch(FormatException  ){
                                    Console.WriteLine("Invalid X-Coordinate");
                                }
                            }

                                //user input from user for Coordinate Y for the rover
                                while(true){
                                    Console.WriteLine(constant.messageroverY);
                                try{
                                    int yaxis = int.Parse(Console.ReadLine());
                                    if(yaxis == movement.CodY){
                                      Console.WriteLine("a Rover is already in the position");
                                    }else{

                                     if(yaxis > plateau.getplateauYlength() ){
                                     Console.WriteLine("Out of bound");
                                     }else{
                                    rover.setcoodY(yaxis);
                                    break;
                                     }}
                                }catch(FormatException  ){
                                    Console.WriteLine("Invalid Y-Coordinate");
                            }
                        }

                                //user input where the rover is facing
                                while(true){
                          Console.WriteLine(constant.roverdirection);
                                    String roverfacing = Console.ReadLine();
                                    if( roverfacing.Equals("N")||roverfacing.Equals("S")||roverfacing.Equals("E")||roverfacing.Equals("W")){
                                    rover.setposition(roverfacing);
                                    break;
                                }else{
                                   Console.WriteLine("Enter Valid Position (i.e) N,S,E,W");
                            }
                        }

                                //rover movement on the plateau
                                movement.move(rover, plateau);

                                //wish to send another rover
                                Console.WriteLine("Do you want to send another rover on Mars? (yes/no)");
                              }while(Console.ReadLine().Equals("yes"));
        }
Ejemplo n.º 3
0
 public void testSetplateauXlength()
 {
     //Arrange
                                             plateau plateau = new plateau();
                                             //Act
                                             plateau.setplateauXlength(5);
                                             //Assert
                                             Assert.IsTrue(plateau.getplateauXlength() == 5);
 }
Ejemplo n.º 4
0
 public void testSetPlateauXAbnormalSymbol()
 {
     //Arrange
                                                     plateau plateau = new plateau();
                                                     //Act
                                                     int a = int.Parse("#%$^&^%$^%");
                                                     plateau.setplateauXlength(a);
                                                     //Assert
                                                     Assert.IsTrue(plateau.getplateauXlength() == a);
 }
Ejemplo n.º 5
0
 public void testSetPlateauXAbnormal()
 {
     //Arrange
                                                     plateau plateau = new plateau();
                                                     //Act
                                                     plateau.setplateauXlength(999999999);
                                                     //Assert
                                                     Assert.IsTrue(plateau.getplateauXlength() == 999999999);
 }
Ejemplo n.º 6
0
        public void move(rover rover,plateau plateau)
        {
            //Call the values x , y , and position thr rover is facing by creating an their objects

                                    int coordinateXrover = rover.getcoodX();
                                    int coordinateYrover = rover.getcoodY();
                                    CodX = coordinateXrover;
                                    CodY = coordinateYrover ;
                                    String roverfacingposition = rover.getposition();

                                    //Call the values of the plateau
                                    int lengthXplateau = plateau.getplateauXlength();
                                    int lengthYplateau = plateau.getplateauYlength();

                                    //declare a boolean that will contain TRUE or FALSE to be use in a while loop
                                    Boolean stop = false ;

                                    loop:while( stop != true){

                                    //continue to prompt user to enter command till stop is not equal to true
                                    Console.WriteLine("Enter your Command");
                                    String command = Console.ReadLine();

                                    //switch statment to check values 1 by 1
                                    switch(command){

                                                                  case "M" :
                                                                  {   if(roverfacingposition.Equals("N")){
                                                                                    if(coordinateYrover < lengthYplateau ){
                                                                                       coordinateYrover++;
                                                                                       }else{
                                                                                       Console.WriteLine("Error out of bound");
                                                                                            }

                                                                                }else if(roverfacingposition.Equals("E")){
                                                                                    if(coordinateXrover < lengthXplateau){
                                                                                            coordinateXrover++;
                                                                                        }else{
                                                                                                Console.WriteLine("Error out of bound");
                                                                                             }

                                                                                 }else if(roverfacingposition.Equals("S")){
                                                                                     if(coordinateYrover > 0 ){
                                                                                         coordinateYrover -- ;
                                                                                        }else{
                                                                                                Console.WriteLine("Error out of bound");
                                                                                             }
                                                                                 }else if(roverfacingposition.Equals("W")){
                                                                                      if(coordinateXrover > 0 )
                                                                                          coordinateXrover -- ;
                                                                                          }else{
                                                                                               Console.WriteLine("Error out of bound");
                                                                                               }

                                                                                 break ;
                                                                                }

                                                                  case "L": {            if(roverfacingposition.Equals("N")){
                                                                                        roverfacingposition = "W" ;
                                                                                        }else if(roverfacingposition.Equals("E")){
                                                                                        roverfacingposition = "N" ;
                                                                                        }else if(roverfacingposition.Equals("S")){
                                                                                        roverfacingposition = "E" ;
                                                                                        }else if(roverfacingposition.Equals("W")){
                                                                                        roverfacingposition = "S" ;
                                                                                        }

                                                                                    break ;
                                                                  }

                                                                  case "R":          {    if(roverfacingposition.Equals("N")){
                                                                                        roverfacingposition = "E" ;
                                                                                        }else if(roverfacingposition.Equals("E")){
                                                                                        roverfacingposition = "S" ;
                                                                                        }else if(roverfacingposition.Equals("S")){
                                                                                        roverfacingposition = "W" ;
                                                                                        }else if(roverfacingposition.Equals("W")){
                                                                                        roverfacingposition = "N" ;
                                                                                        }

                                                                                         break ;
                                                                                     }

                                                                  case "Q":
                                                                                 {
                                                                                     stop = true;
                                                                                     goto loop;

                                                                                 }

                                                                  default :  Console.WriteLine("Enter valid Command(i.e) Either R or L or M " );
                                                                                 break;
                                                                }

                                                       Console.WriteLine("rover is @ point (" +coordinateXrover+ ","+coordinateYrover+ " and facing "+roverfacingposition+" )");

                                                        }
        }