Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * This program has alpha bot
- * by: Alejandro Antorcha
- */
- package Lesson3;
- import kareltherobot.*;
- public class Lesson3Activity3 extends UrRobot{
- //constructor from UrRobot for my alphabot
- public Lesson3Activity3(int x, int y, Direction d, int b) {
- super(x, y, d, b);
- }
- public static void main(String[] args) {
- World.readWorld("Lesson3World3.kwld");
- World.setDelay(10);
- World.setVisible();
- Lesson3Activity3 alphaBot = new Lesson3Activity3(1,1,North, 0);
- //runs program
- alphaBot.wholeHarvest();
- }
- /**
- * makes the robot appear to turn right
- * @param
- * @return void
- */
- public void turnRight() {
- //changing the delay to 0
- int delay = World.delay();
- World.setDelay(0);
- turnLeft();
- turnLeft();
- //setting the relay to what it was previously set to
- World.setDelay(delay);
- turnLeft();
- }
- /**
- * runs one harvest latitude-ly
- * @param
- * @return void
- */
- public void harvest() {
- for(int i = 0; i < 6; i++) {
- pickBeeper();
- move();
- }
- pickBeeper();
- }
- /**
- * the turn between the different harvests
- * @param turn - caries the number of which lane alphabot is in
- */
- public void harvestTurn(int turn) {
- for (int j = 0; j < 2; j++) {
- //chooses to go left or right
- if (turn % 2 == 1) {
- turnRight();
- } else {
- turnLeft();
- }
- //moves between the two turns but not after
- if (j == 0) {
- move();
- }
- }
- }
- /**
- * runs the whole harvest
- * @param
- * @return void
- */
- public void wholeHarvest() {
- turnRight();
- move();
- for(int i = 0; i < 3; i++) {
- harvest();
- harvestTurn(i);
- }
- //last harvest and orientation
- harvest();
- move();
- turnRight();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement