Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- Carlos Garcia
- Lesson 3 Activity 3
- Field Harvester
- */
- package Lesson3;
- import kareltherobot.UrRobot;
- import kareltherobot.World;
- import java.awt.*;
- public class Activity3 extends UrRobot {
- public Activity3(int street , int avenue , Direction direction , int beeperCount){
- super(street, avenue, direction, beeperCount, Color.PINK);
- }
- public static void main(String[] args) {
- World.setDelay(50);
- World.setVisible();
- World.setBeeperColor(Color.blue);
- World.setSize(10,10);
- World.showSpeedControl(true);
- World.readWorld("Lesson3World3.kwld");
- Activity3 zgod = new Activity3(1,1,North,-1);
- zgod.doField();
- }
- /**
- * Function to turn right
- * @return void
- * */
- public void turnRight(){
- turnLeft();
- turnLeft();
- turnLeft();
- }
- /**
- * Function to go up a line in the field
- * @return void
- * */
- public void upLine(){
- for (int i = 0; i < 3; i++) {
- pickBeeper();
- move();
- }
- }
- /**
- * Function to do the entire field
- * @return void
- * */
- public void doField() {
- turnRight();
- for (int i = 0; i < 3; i++) { //loop for the field
- int h = 7-i; // int for horizontal distances
- int v = 3-i; // int for vertical distances
- for (int j = 0; j < h; j++) { // loop to run the horizontal rows (runs as many times as the variable for horizontal distance)
- move();
- pickBeeper();
- }
- turnLeft();
- for (int k = 0; k < v; k++) { // loop to run the vertical rows (runs as many times as the variable for vertical distance)
- move();
- pickBeeper();
- }
- turnLeft();
- }
- for (int i = 0; i < 4; i++) { // loop for the final part of the field
- move();
- pickBeeper();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement