Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- import kareltherobot.*;
- /**
- * Francesco Di Mise
- * Program to collect a field of beepers
- * To be efficient, it collects them in rows
- * Uses functions and some loops
- */
- public class Lesson3Activity3 extends UrRobot{
- /**
- * Constructor
- * @param x
- * @param y
- * @param d
- * @param b
- */
- public Lesson3Activity3 (int x, int y, Direction d, int b) {
- super(x, y, d, b);
- }
- /**
- * Main function. Performs a couple actions before the more complicated harvest functions. Collects every beeper
- * @param args
- */
- public static void main(String[] args) {
- World.setDelay(15);
- World.setVisible();
- Lesson3Activity3 MrDaddy = new Lesson3Activity3(1,1,North, 0);
- World.readWorld("Lesson3World3.kwld");
- MrDaddy.turnRight();
- MrDaddy.move();
- MrDaddy.pickBeeper();
- MrDaddy.harvestBeepers();
- MrDaddy.turnRight();
- }
- /**
- * Turn right function to instantaneously turn right
- */
- public void turnRight(){
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- turnLeft();
- }
- /**
- * For loop to collect a single row of beepers
- */
- public void collectRow(){
- for (int index = 0; index < 6; index++){
- move();
- pickBeeper();
- }
- }
- /**
- * Go to the next lane. Specifically when the next lane is to the left
- */
- public void goNextLeft(){
- turnLeft();
- move();
- pickBeeper();
- turnLeft();
- }
- /**
- * Go to next lane, specifically when the next lane is on the right
- */
- public void goNextRight(){
- turnRight();
- move();
- pickBeeper();
- turnRight();
- }
- /**
- * Puts the turning and collection functions together to collect the whole field of beepers
- */
- public void harvestBeepers(){
- collectRow();
- goNextLeft();
- collectRow();
- goNextRight();
- collectRow();
- goNextLeft();
- collectRow();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement