Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Lesson3;
- import kareltherobot.*;
- public class Lesson3Activity1 extends UrRobot{
- //constructor from UrRobot for my alphabot
- public Lesson3Activity1(int x, int y, Direction d, int b) {
- super(x, y, d, b);
- }
- public static void main(String[] args) {
- World.readWorld("Lesson3World1.kwld");
- World.setDelay(15);
- World.setVisible();
- Lesson3Activity1 alphaBot = new Lesson3Activity1(4,3,North, 0);
- //runs the program
- alphaBot.shuttleRun();
- }
- /**
- * compiles all of the other functions to do the entire shuttle run
- * @param
- * @return void
- */
- public void shuttleRun() {
- for(int i = 0; i < 3; i++){
- //so that the robot doesn't instantly move to the right one row
- if(i > 0){
- moveRight();
- }
- shuttleGrab();
- }
- }
- /**
- * allows the robot to "turn right" in the source code
- * rather than turn left 3 times
- * @param
- * @return void
- */
- public void moveRight() {
- turnLeft();
- turnLeft();
- turnLeft();
- move();
- turnLeft();
- }
- /**
- * a single shuttle run, from the beeper and back
- * @param
- * @return void
- */
- public void shuttleGrab() {
- //runs 5 times to pick up all the beepers in a row
- for(int i = 0; i < 5; i++) {
- run();
- pickBeeper();
- turnLeft();
- turnLeft();
- run();
- turnLeft();
- turnLeft();
- putBeeper();
- }
- }
- /**
- * makes the run to the beeper a single line
- * @return void
- */
- public void run() {
- for(int i = 0; i < 3; i++ ){
- move();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement