예제 #1
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // create city, robot and environment

    City thomas = new City();

    Robot tom = new Robot(thomas, 3, 1, Direction.NORTH);

    new Wall(thomas, 1, 1, Direction.NORTH);
    new Wall(thomas, 1, 1, Direction.EAST);
    new Wall(thomas, 1, 1, Direction.SOUTH);
    new Wall(thomas, 1, 1, Direction.WEST);
    new Wall(thomas, 2, 2, Direction.NORTH);
    new Wall(thomas, 2, 2, Direction.WEST);
    new Wall(thomas, 3, 2, Direction.WEST);
    new Wall(thomas, 4, 1, Direction.WEST);
    new Wall(thomas, 4, 1, Direction.NORTH);
    new Wall(thomas, 4, 1, Direction.SOUTH);
    new Wall(thomas, 4, 1, Direction.EAST);
    new Wall(thomas, 2, 3, Direction.NORTH);
    new Wall(thomas, 3, 2, Direction.SOUTH);
    new Wall(thomas, 3, 3, Direction.SOUTH);
    new Wall(thomas, 4, 4, Direction.WEST);
    new Wall(thomas, 4, 4, Direction.NORTH);
    new Wall(thomas, 4, 4, Direction.EAST);
    new Wall(thomas, 4, 4, Direction.SOUTH);
    new Wall(thomas, 3, 3, Direction.EAST);
    new Wall(thomas, 2, 3, Direction.EAST);
    new Wall(thomas, 1, 4, Direction.EAST);
    new Wall(thomas, 1, 4, Direction.SOUTH);
    new Wall(thomas, 1, 4, Direction.NORTH);
    new Wall(thomas, 1, 4, Direction.WEST);

    // a right side following robot

    // loop program
    while (true) {
      if (tom.frontIsClear()) {
        tom.turnLeft();
        tom.turnLeft();
        tom.turnLeft();

        if (tom.frontIsClear()) {
          tom.move();
        }

      } else {

        tom.turnLeft();
        tom.move();
      }
    }
  }
예제 #2
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // Make a city fot the robot to live in
    City kw = new City();

    // Make a robot to live in the city
    Robot jack = new Robot(kw, 0, 2, Direction.WEST);

    // make a wall
    new Wall(kw, 1, 1, Direction.NORTH);
    new Wall(kw, 1, 1, Direction.WEST);
    new Wall(kw, 2, 1, Direction.WEST);
    new Wall(kw, 2, 1, Direction.SOUTH);
    new Wall(kw, 2, 2, Direction.SOUTH);
    new Wall(kw, 2, 2, Direction.EAST);
    new Wall(kw, 1, 2, Direction.EAST);
    new Wall(kw, 1, 2, Direction.NORTH);
    jack.move();
    jack.move();
    jack.turnLeft();

    for (int loops = 7; loops > 0; loops--) {
      jack.move();
      jack.move();
      jack.move();
      jack.turnLeft();
    }
  }
예제 #3
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here

    // skiped
    City jw = new City();
    Robot rob = new Robot(jw, 1, 1, Direction.EAST);
    new Wall(jw, 1, 1, Direction.WEST);
    new Wall(jw, 1, 1, Direction.NORTH);
    new Wall(jw, 1, 2, Direction.NORTH);
    new Wall(jw, 1, 3, Direction.NORTH);
    new Wall(jw, 1, 4, Direction.NORTH);
    new Wall(jw, 1, 4, Direction.EAST);
    new Wall(jw, 2, 4, Direction.EAST);
    new Wall(jw, 3, 4, Direction.EAST);
    new Wall(jw, 3, 4, Direction.SOUTH);
    new Wall(jw, 3, 3, Direction.SOUTH);
    new Wall(jw, 3, 2, Direction.SOUTH);
    new Wall(jw, 3, 1, Direction.SOUTH);
    new Wall(jw, 3, 1, Direction.WEST);
    new Wall(jw, 2, 1, Direction.WEST);
    // walls for days

    new Thing(jw, 1, 2);
    new Thing(jw, 2, 2);
    new Thing(jw, 2, 3);
    new Thing(jw, 2, 4);
    new Thing(jw, 3, 4);
    new Thing(jw, 3, 1);
    // Things!!!
    rob.turnLeft();

    while (rob.frontIsClear()) {
      rob.move();
      if (rob.canPickThing()) {
        rob.pickThing();
      }
      while (!rob.frontIsClear()) {
        rob.turnLeft();
      }
    }
  }
예제 #4
0
파일: Quiz2.java 프로젝트: snowc4636/Quiz2
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // Can use Wall1.txt, Wall2.txt, or Wall3.txt
    City kw = new City("Wall1.txt");
    Robot karel = new Robot(kw, 1, 1, Direction.WEST);

    // program solutions coded under here

    while (!karel.frontIsClear()) {
      karel.turnLeft();
      karel.move();
      karel.turnLeft();
      karel.turnLeft();
      karel.turnLeft();
    }
  }
예제 #5
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // Make city
    City A3Q3 = new City();

    // Make robot
    Robot karel = new Robot(A3Q3, 2, 2, Direction.WEST);
    karel.setColor(Color.white);

    // MAKE WALLS
    // Top wall
    new Wall(A3Q3, 1, 1, Direction.NORTH);
    new Wall(A3Q3, 1, 3, Direction.NORTH);
    new Wall(A3Q3, 1, 4, Direction.NORTH);

    // Right wall
    new Wall(A3Q3, 1, 4, Direction.EAST);
    new Wall(A3Q3, 2, 4, Direction.EAST);
    new Wall(A3Q3, 3, 4, Direction.EAST);

    // Bottom wall
    new Wall(A3Q3, 3, 4, Direction.SOUTH);
    new Wall(A3Q3, 3, 3, Direction.SOUTH);
    new Wall(A3Q3, 3, 2, Direction.SOUTH);
    new Wall(A3Q3, 3, 1, Direction.SOUTH);

    // Left wall
    new Wall(A3Q3, 3, 1, Direction.WEST);
    new Wall(A3Q3, 2, 1, Direction.WEST);
    new Wall(A3Q3, 1, 1, Direction.WEST);

    // Code Solution
    while (karel.frontIsClear()) {
      karel.move();
    }
    karel.turnLeft();
    while (true) {
      karel.turnLeft();
      karel.turnLeft();
      karel.turnLeft();
      if (!karel.frontIsClear()) {
        karel.turnLeft();
        if (!karel.frontIsClear()) {
          karel.turnLeft();
        }
        karel.move();
      } else {
        karel.move();
        break;
      }
    }
  }
예제 #6
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // make city
    City kw = new City();

    // make walls
    new Wall(kw, 1, 1, Direction.NORTH);
    new Wall(kw, 1, 3, Direction.NORTH);
    new Wall(kw, 1, 4, Direction.NORTH);
    new Wall(kw, 1, 4, Direction.EAST);
    new Wall(kw, 2, 4, Direction.EAST);
    new Wall(kw, 3, 4, Direction.EAST);
    new Wall(kw, 3, 4, Direction.SOUTH);
    new Wall(kw, 3, 3, Direction.SOUTH);
    new Wall(kw, 3, 2, Direction.SOUTH);
    new Wall(kw, 3, 1, Direction.SOUTH);
    new Wall(kw, 3, 1, Direction.WEST);
    new Wall(kw, 2, 1, Direction.WEST);
    new Wall(kw, 1, 1, Direction.WEST);

    // make robot
    Robot karel = new Robot(kw, 2, 2, Direction.SOUTH);

    // make karel reach the wall
    while (true) {
      if (karel.frontIsClear()) {
        karel.move();
      } else if (karel.frontIsClear() == false) {
        break;
      }
    }

    // make karel escape the room
    while (true) {
      if (karel.frontIsClear()) {
        karel.move();
        karel.turnLeft();
        karel.turnLeft();
        karel.turnLeft();
        {
          if (karel.frontIsClear()) {
            break;
          }
        }
      } else if (karel.frontIsClear() == false) {
        karel.turnLeft();
      }
    }
    // make karel move out of the room
    karel.move();
  }
예제 #7
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // make city
    City kw = new City();

    // make robot
    Robot karel = new Robot(kw, 1, 1, Direction.EAST);

    // make walls
    new Wall(kw, 1, 1, Direction.NORTH);
    new Wall(kw, 1, 1, Direction.WEST);
    new Wall(kw, 1, 2, Direction.NORTH);
    new Wall(kw, 1, 3, Direction.NORTH);
    new Wall(kw, 1, 4, Direction.NORTH);
    new Wall(kw, 3, 1, Direction.SOUTH);
    new Wall(kw, 3, 2, Direction.SOUTH);
    new Wall(kw, 3, 3, Direction.SOUTH);
    new Wall(kw, 3, 4, Direction.SOUTH);
    new Wall(kw, 3, 1, Direction.WEST);
    new Wall(kw, 2, 1, Direction.WEST);
    new Wall(kw, 3, 4, Direction.EAST);
    new Wall(kw, 2, 4, Direction.EAST);
    new Wall(kw, 1, 4, Direction.EAST);

    // New things
    new Thing(kw, 3, 1);
    new Thing(kw, 1, 2);
    new Thing(kw, 2, 2);
    new Thing(kw, 2, 3);
    new Thing(kw, 3, 4);

    while (true) {
      if (karel.canPickThing()) {
        karel.pickThing();
      }
      if (karel.frontIsClear()) {
        karel.move();

      } else {
        if (karel.getDirection() == Direction.EAST) {
          karel.turnLeft();
          karel.turnLeft();
          karel.turnLeft();
        }
        if (karel.getDirection() == Direction.SOUTH && (!karel.frontIsClear())) {
          karel.turnLeft();
          karel.turnLeft();
        }
        if (karel.getDirection() == Direction.SOUTH) {
          karel.move();
          karel.turnLeft();
          karel.turnLeft();
          karel.turnLeft();
        }
        if (karel.getDirection() == Direction.WEST && (!karel.frontIsClear())) {
          karel.turnLeft();
          karel.move();
          karel.turnLeft();
        }
        if (karel.getDirection() == Direction.NORTH && (!karel.frontIsClear())) {
          karel.turnLeft();
        }
        if (karel.getDirection() == Direction.WEST) {
          karel.move();
        }
      }

      if (karel.getAvenue() == 1 && (karel.getStreet()) == 1) {

        karel.turnLeft();
        karel.turnLeft();
        break;
      }
    }
  }
예제 #8
0
 /** @param args the command line arguments */
 public static void main(String[] args) {
   // TODO code application logic here
   City Ajay = new City();
   new Wall(Ajay, 1, 3, Direction.WEST);
   new Wall(Ajay, 2, 3, Direction.WEST);
   new Wall(Ajay, 2, 3, Direction.SOUTH);
   Robot Jack = new Robot(Ajay, 1, 2, Direction.SOUTH);
   Robot Bob = new Robot(Ajay, 1, 3, Direction.SOUTH);
   Bob.move();
   Bob.turnLeft();
   Bob.move();
   Bob.turnLeft();
   Bob.turnLeft();
   Bob.turnLeft();
   Bob.move();
   Bob.turnLeft();
   Jack.move();
   Bob.turnLeft();
   Jack.move();
   Bob.turnLeft();
   Jack.turnLeft();
   Bob.move();
   Jack.move();
 }
예제 #9
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // make city for robot
    City a2q4 = new City();
    // make robot
    Robot lali = new Robot(a2q4, 0, 1, Direction.EAST);
    // create all walls
    new Wall(a2q4, 1, 1, Direction.SOUTH);
    new Wall(a2q4, 1, 1, Direction.NORTH);
    new Wall(a2q4, 1, 1, Direction.EAST);
    new Wall(a2q4, 1, 1, Direction.WEST);

    new Wall(a2q4, 4, 1, Direction.SOUTH);
    new Wall(a2q4, 4, 1, Direction.NORTH);
    new Wall(a2q4, 4, 1, Direction.EAST);
    new Wall(a2q4, 4, 1, Direction.WEST);

    new Wall(a2q4, 1, 4, Direction.SOUTH);
    new Wall(a2q4, 1, 4, Direction.NORTH);
    new Wall(a2q4, 1, 4, Direction.EAST);
    new Wall(a2q4, 1, 4, Direction.WEST);

    new Wall(a2q4, 4, 4, Direction.WEST);
    new Wall(a2q4, 4, 4, Direction.EAST);
    new Wall(a2q4, 4, 4, Direction.NORTH);
    new Wall(a2q4, 4, 4, Direction.SOUTH);

    new Wall(a2q4, 2, 2, Direction.NORTH);
    new Wall(a2q4, 2, 3, Direction.NORTH);

    new Wall(a2q4, 2, 2, Direction.WEST);
    new Wall(a2q4, 3, 2, Direction.WEST);

    new Wall(a2q4, 3, 2, Direction.SOUTH);
    new Wall(a2q4, 3, 3, Direction.SOUTH);

    new Wall(a2q4, 2, 3, Direction.EAST);
    new Wall(a2q4, 3, 3, Direction.EAST);

    while (lali.frontIsClear()) {
      lali.move();
      lali.turnLeft();
      lali.turnLeft();
      lali.turnLeft();
      lali.move();
      lali.turnLeft();
      lali.move();
      lali.turnLeft();

      lali.move();
      lali.turnLeft();
      lali.turnLeft();
      lali.turnLeft();
      lali.move();
      lali.move();
      lali.turnLeft();
      lali.turnLeft();
      lali.turnLeft();
      lali.move();
    }
  }
예제 #10
0
 /** @param args the command line arguments */
 public static void main(String[] args) {
   // make things
   City town = new City();
   Robot jarvis = new Robot(town, 2, 1, Direction.NORTH);
   new Wall(town, 1, 1, Direction.NORTH);
   new Wall(town, 1, 1, Direction.SOUTH);
   new Wall(town, 1, 1, Direction.EAST);
   new Wall(town, 1, 1, Direction.WEST);
   new Wall(town, 1, 4, Direction.NORTH);
   new Wall(town, 1, 4, Direction.SOUTH);
   new Wall(town, 1, 4, Direction.EAST);
   new Wall(town, 1, 4, Direction.WEST);
   new Wall(town, 4, 1, Direction.NORTH);
   new Wall(town, 4, 1, Direction.SOUTH);
   new Wall(town, 4, 1, Direction.EAST);
   new Wall(town, 4, 1, Direction.WEST);
   new Wall(town, 4, 4, Direction.NORTH);
   new Wall(town, 4, 4, Direction.SOUTH);
   new Wall(town, 4, 4, Direction.EAST);
   new Wall(town, 4, 4, Direction.WEST);
   new Wall(town, 2, 2, Direction.NORTH);
   new Wall(town, 2, 2, Direction.WEST);
   new Wall(town, 2, 3, Direction.NORTH);
   new Wall(town, 2, 3, Direction.EAST);
   new Wall(town, 3, 2, Direction.SOUTH);
   new Wall(town, 3, 2, Direction.WEST);
   new Wall(town, 3, 3, Direction.SOUTH);
   new Wall(town, 3, 3, Direction.EAST);
   // move
   while (!jarvis.frontIsClear()) {
     jarvis.turnLeft();
     jarvis.move();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.move();
     jarvis.move();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.move();
     jarvis.move();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.turnLeft();
     jarvis.move();
     jarvis.turnLeft();
     jarvis.move();
   }
 }
예제 #11
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    City Kitchener = new City();

    Robot karel = new Robot(Kitchener, 3, 3, Direction.EAST);
    Robot maria = new Robot(Kitchener, 0, 1, Direction.WEST);
    new Thing(Kitchener, 0, 0);
    new Thing(Kitchener, 1, 0);
    new Thing(Kitchener, 1, 1);
    new Thing(Kitchener, 1, 2);
    new Thing(Kitchener, 2, 2);
    new Wall(Kitchener, 3, 3, Direction.EAST);
    new Wall(Kitchener, 3, 3, Direction.SOUTH);
    new Wall(Kitchener, 2, 3, Direction.EAST);
    new Wall(Kitchener, 2, 3, Direction.WEST);
    new Wall(Kitchener, 2, 3, Direction.NORTH);

    karel.setLabel("K");
    maria.setLabel("M");
    karel.setColor(Color.green);
    maria.setColor(Color.pink);

    maria.move();
    karel.turnLeft();
    karel.turnLeft();
    karel.move();
    karel.turnLeft();
    karel.turnLeft();
    karel.turnLeft();
    karel.move();
    maria.turnLeft();
    maria.pickThing();
    karel.pickThing();
    maria.move();
    karel.move();
    karel.turnLeft();
    maria.pickThing();
    karel.pickThing();
    maria.turnLeft();
    maria.move();
    maria.pickThing();
  }
예제 #12
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    City kw = new City();
    // make walls
    new Wall(kw, 3, 2, Direction.NORTH);
    new Wall(kw, 3, 2, Direction.WEST);
    new Wall(kw, 2, 3, Direction.WEST);
    new Wall(kw, 1, 3, Direction.WEST);
    new Wall(kw, 1, 3, Direction.NORTH);
    new Wall(kw, 1, 3, Direction.EAST);
    new Wall(kw, 2, 4, Direction.NORTH);
    new Wall(kw, 2, 4, Direction.EAST);
    new Wall(kw, 3, 4, Direction.EAST);

    new Thing(kw, 3, 1);

    Robot MetalGuy = new Robot(kw, 3, 0, Direction.EAST);

    MetalGuy.move();
    MetalGuy.pickThing();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.putThing();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.turnLeft();
    MetalGuy.move();
    MetalGuy.move();
    MetalGuy.turnLeft();
  }
예제 #13
0
  /** @param args the command line arguments */
  public static void main(String[] args) {
    // TODO code application logic here
    City Kitchener = new City();

    Robot karel = new Robot(Kitchener, 0, 0, Direction.SOUTH);
    Robot bob = new Robot(Kitchener, 0, 1, Direction.SOUTH);
    new Wall(Kitchener, 0, 1, Direction.WEST);
    new Wall(Kitchener, 1, 1, Direction.SOUTH);
    new Wall(Kitchener, 1, 1, Direction.WEST);
    karel.move();
    bob.move();
    karel.move();
    bob.turnLeft();
    bob.move();
    bob.turnLeft();
    bob.turnLeft();
    bob.turnLeft();
    bob.move();
    karel.turnLeft();
    bob.turnLeft();
    bob.turnLeft();
    bob.turnLeft();
    bob.move();
    karel.move();
  }