import cs1705.*; // ------------------------------------------------------------------------- /** * This robot adds extra behaviors to a NavigatorBot so that it can trace * out a pattern of beepers and relay commands to another robot to * duplicate the pattern. * * @author Stephen Edwards * @version 2003.09.21 */ public class StencilBot extends NavigatorBot { //~ Variables ............................................................. NavigatorBot copier; //~ Constructors .......................................................... // ---------------------------------------------------------- /** * Construct a stencil robot by specifying its starting state. * The parameters are just passed to the corresponding NavigatorBot * constructor. */ public StencilBot( int street, int avenue, Direction facing, int numBeepers, NavigatorBot buddy ) { super( street, avenue, facing, numBeepers ); copier = buddy; } //~ Methods ............................................................... // ---------------------------------------------------------- /** * Trace through all the intersections in the specified area, giving * commands to the copier to duplicate any beeper piles found. * * @ param height the height of the area in streets * @ param width the width of the area in streets */ public void duplicatePattern( int height, int width ) { int street = 1; int avenue = 1; while ( avenue <= width ) { street = 1; while ( street <= height ) { moveTo( street, avenue ); if ( nextToABeeper() ) { copier.moveTo( street, avenue ); copier.putBeeper(); } street++; } avenue++; } } }