Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- //This program is meant to harvest a field of beepers (pick them up) by using functions in an effective manner.
- import kareltherobot.UrRobot;
- import kareltherobot.World;
- public class Activity3Main extends UrRobot{
- public Activity3Main(int a, int s, Direction d, int b){
- super(a,s,d,b);
- }
- public static void main(String[] args){
- //Imports world map
- World.readWorld("Lesson3World3.kwld");
- World.setDelay(20);
- World.setVisible();
- //Declares object gary
- Activity3Main gary = new Activity3Main(1,1,North,0);
- //Functions in the order they have to be to efficiently harvest beepers
- //Starts --> harvests -->shifts row --> harvests-->shifts row a different way --> ...
- gary.start();
- gary.harvest();
- gary.shift();
- gary.harvest();
- gary.shiftTwo();
- gary.harvest();
- gary.shift();
- gary.harvest();
- }
- /**
- * Allows the robot to turn right
- * @ param - none
- * @ return - void
- */
- public void turnRight(){
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- turnLeft();
- World.setDelay(delay);
- }
- /**
- * Starts the movement of robot by turning it and allowing it to move a space w/o picking up beeper
- * @ param - none
- * @ return - void
- */
- public void start(){
- turnRight();
- move();
- }
- /**
- * Allows robot to pick up beeper every time it moves to harvest them
- * @ param - none
- * @ return - void
- */
- public void harvest(){
- for(int i=0;i<7;i++){
- pickBeeper();
- move();
- }
- }
- /**
- * Allows robot to change rows when its on the right side of the beepers
- * @ param - none
- * @ return - void
- */
- public void shift(){
- turnLeft();
- move();
- turnLeft();
- move();
- }
- /**
- * Allows robot to change rows when its on the left side of the beepers
- * @ param - none
- * @ return - void
- */
- public void shiftTwo(){
- turnRight();
- move();
- turnRight();
- move();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement