Advertisement
GARC923

L3A3 Carlos Garcia

Oct 20th, 2022 (edited)
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.02 KB | None | 0 0
  1. /**
  2. Carlos Garcia
  3. Lesson 3 Activity 3
  4. Field Harvester
  5. */
  6.  
  7. package Lesson3;
  8.  
  9. import kareltherobot.UrRobot;
  10. import kareltherobot.World;
  11.  
  12. import java.awt.*;
  13.  
  14.  
  15. public class Activity3 extends UrRobot {
  16.     public Activity3(int street , int avenue , Direction direction , int beeperCount){
  17.         super(street, avenue, direction, beeperCount, Color.PINK);
  18.     }
  19.  
  20.  
  21.  
  22.     public static void main(String[] args) {
  23.         World.setDelay(50);
  24.         World.setVisible();
  25.         World.setBeeperColor(Color.blue);
  26.         World.setSize(10,10);
  27.         World.showSpeedControl(true);
  28.         World.readWorld("Lesson3World3.kwld");
  29.  
  30.         Activity3 zgod = new Activity3(1,1,North,-1);
  31.  
  32.         zgod.doField();
  33.  
  34.     }
  35.  
  36.     /**
  37.      * Function to turn right
  38.      * @return void
  39.      * */
  40.     public void turnRight(){
  41.         turnLeft();
  42.         turnLeft();
  43.         turnLeft();
  44.     }
  45.  
  46.     /**
  47.      * Function to go up a line in the field
  48.      * @return void
  49.      * */
  50.     public void upLine(){
  51.         for (int i = 0; i < 3; i++) {
  52.             pickBeeper();
  53.             move();
  54.         }
  55.     }
  56.  
  57.     /**
  58.      * Function to do the entire field
  59.      * @return void
  60.      * */
  61.     public void doField() {
  62.         turnRight();
  63.         for (int i = 0; i < 3; i++) { //loop for the field
  64.             int h = 7-i; // int for horizontal distances
  65.             int v = 3-i; // int for vertical distances
  66.             for (int j = 0; j < h; j++) { // loop to run the horizontal rows (runs as many times as the variable for horizontal distance)
  67.                 move();
  68.                 pickBeeper();
  69.             }
  70.             turnLeft();
  71.             for (int k = 0; k < v; k++) { // loop to run the vertical rows (runs as many times as the variable for vertical distance)
  72.                 move();
  73.                 pickBeeper();
  74.             }
  75.             turnLeft();
  76.         }
  77.         for (int i = 0; i < 4; i++) { // loop for the final part of the field
  78.             move();
  79.             pickBeeper();
  80.         }
  81.     }
  82.  
  83. }
  84.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement