package example; import java.awt.Color; import robocode.*; /** */ public class Sentry_WallKiller_Clock extends Robot { boolean peek; // Don't turn if there's a robot there double moveAmount; // How much to move /** * run: Move around the walls */ public void run() { // Set colors setColors(Color.white,Color.white,Color.white); // Initialize moveAmount to the maximum possible for this battlefield. moveAmount = Math.max(getBattleFieldWidth(), getBattleFieldHeight()); // Initialize peek to false peek = false; // turnLeft to face a wall. // getHeading() % 90 means the remainder of // getHeading() divided by 90. turnLeft(getHeading() % 90); ahead(moveAmount); //Have the gun point along the wall peek = true; turnGunRight(0); //Turn Left so we travel anticlockwise around the edge of the arena turnRight(90); while (true) { // Look before we turn when ahead() completes. if (getOthers()>3) { peek = true; // Move up the wall ahead(moveAmount); // Don't look now peek = false; // Turn Left to move to the next wall turnRight(90); } } } public void onHitRobot(HitRobotEvent e) { // If he's in front of us, set back up a bit. if (e.getName().startsWith("example.Sentry") || e.getName().startsWith("example.sentry")) { if (e.getBearing() > -90 && e.getBearing() < 90) { back(moveAmount); } // else he's in back of us, so set ahead a bit. else { ahead(moveAmount); } } //if the robot is not wallkiller attack else{ if (e.getBearing() > -90 && e.getBearing() < 90) { fire(3); ahead(moveAmount); } // else he's in back of us, so set ahead a bit. else { back(moveAmount); } } } /** * onHitByBullet: What to do when you're hit by a bullet public void onHitByBullet(HitByBulletEvent e) { fire(3); } */ /** * onScannedRobot: Fire! */ public void onScannedRobot(ScannedRobotEvent e) { String name; name= e.getName(); //If the robot is wallkiller anti-clockwise back away if (e.getName().startsWith("example.Sentry") || e.getName().startsWith("example.sentry")) { back(moveAmount); } //if the robot is not wallkiller attack else{ if (e.getEnergy() > 30) { fire(3); fire(2); } else { fire(3); } if (peek) { scan(); } } } }