/* * SE1011 Lab 8 Driver * 10/2009 */ package msoe.se1011.gobots; import java.awt.Color; import edu.msoe.se1010.winPlotter.WinPlotter; /** * RobotProgram - The main class that creates and controls Gobot objects * * @author hornick */ public class RobotProgram { public static void main(String[] args) { // Create a WinPlotter object for the Gobots to use WinPlotter plotter = new WinPlotter(); plotter.setWindowSize(500, 500); plotter.setBackgroundColor(0, 0, 0); plotter.setPlotBoundaries(-100, -100, 100, 100); plotter.setWindowTitle("Gobots!"); // Create a Gobot that will plot its moves in red. Gobot r2d2 = new Gobot("R2D2", 100, Color.RED, plotter ); r2d2.setSpeed(10); // set the speed to 10 (m/s) // Create a Gobot that will plot its moves in green. Gobot wallE = new Gobot("Wall-E", 200, Color.GREEN, plotter ); wallE.setSpeed(2); // wallE is slower than r2d2 boolean status; // used to receive the status of move() calls below boolean is_r2d2Dead = false; // indicates if r2d2' battery died boolean is_wallEDead = false; // similar Gobot.displayCoordinates(true); // turn on coordinate display // move both Gobots alternately, in ever-widening rectangles for( int i=1; i<50; i++ ) { status = r2d2.move( Gobot.NORTH, 5+i ); // move N for 5+i (s) status = wallE.move( Gobot.SOUTH, 10+i); // similar Gobot.displayCoordinates(false); // turn off coordinate display status = r2d2.move( Gobot.EAST, 5+i ); status = wallE.move( Gobot.WEST, 10+i); status = r2d2.move( Gobot.SOUTH, 5+i ); status = wallE.move( Gobot.NORTH, 10+i); status = r2d2.move( Gobot.WEST, 5+i ); if( !status ) { // r2d2 stopped moving at some point in this iteration if( !is_r2d2Dead ) { // dead flag set yet? is_r2d2Dead = true; // it is now! System.out.printf("r2d2's battery died in iteration %4d \n", i); } } status = wallE.move( Gobot.EAST, 10+i); if( !status ) { // wallE stopped moving at some point in this iteration if( !is_wallEDead ) { // dead flag set yet? is_wallEDead = true; // it is now! System.out.printf("wallE's battery died in iteration %4d \n\n", i); } } } String report1 = r2d2.toString(); // get the current status of the r2d2 System.out.println(report1); String report2 = wallE.toString(); // get the current status of the wallE System.out.println(report2); } // end main() } // end RobotProgram