import cs1705.*; // ------------------------------------------------------------------------- /** * This robot adds extra behaviors to a VPIRobot, so that it can harvest * a field of beepers using other helper robots. * * @author Stephen Edwards * @version 2003.09.16 */ public class HarvesterForeman extends VPIRobot { //~ Instance variables .................................................... VPIRobot buddy = null; //~ Constructors .......................................................... // ---------------------------------------------------------- /** * Construct a harvester foreman by specifying its starting state. * The parameters are just passed to the corresponding VPIRobot * constructor. */ public HarvesterForeman( int street, int avenue, Direction facing, int numBeepers, VPIRobot myBuddy ) { super( street, avenue, facing, numBeepers ); buddy = myBuddy; } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Collect all the beepers in the field. */ public void harvestField() { harvestOneRow(); goToNextRow(); harvestOneRow(); } // ---------------------------------------------------------- /** * Pick up one row of beepers. */ public void harvestOneRow() { while ( nextToABeeper() ) { pickBeeper(); move(); } } // ---------------------------------------------------------- /** * Pick up one row of beepers. */ public void goToNextRow() { turnLeft(); move(); turnLeft(); move(); } // ---------------------------------------------------------- /** * Move, and also ask buddy to move. */ public void move() { super.move(); buddy.move(); } // ---------------------------------------------------------- /** * Pick up a beeper, and also ask buddy to do the same. */ public void pickBeeper() { super.pickBeeper(); buddy.pickBeeper(); } // ---------------------------------------------------------- /** * Turn left, and also ask buddy to do the same. */ public void turnLeft() { super.turnLeft(); buddy.turnLeft(); } }