Harvest Around Square 4 Robots
Code
package HarvestAroundSquare4;
import cs1Lib.karel.*;
/** Use four robots to harvest beepers that are positioned
around a square. Robots take turns moving.
@author Byron Weber Becker
@version 1.0 */
public class HarvestAroundSquare4 extends KarelApplet
{
public void run()
{ // Read the specification of the world from a URL. Then add the
// world to the applet.
World world = new World(this.getDocumentBase(), "HarvestAroundSquare.txt");
this.add(world);
// Construct four robots and position them in the world.
Robot karel = new Robot();
Robot mary = new Robot();
Robot john = new Robot();
Robot suelynn = new Robot();
world.addRobot(karel, 2, 3, World.EAST);
world.addRobot(mary, 6, 2, World.NORTH);
world.addRobot(john, 7, 6, World.WEST);
world.addRobot(suelynn, 3, 7, World.SOUTH);
// Have each robot pick up 3 beepers and then turn off.
for(int numBeepers=0; numBeepers < 3; numBeepers++)
{ karel.move();
karel.pickBeeper();
mary.move();
mary.pickBeeper();
john.move();
john.pickBeeper();
suelynn.move();
suelynn.pickBeeper();
}
karel.turnOff();
mary.turnOff();
john.turnOff();
suelynn.turnOff();
}
}