Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package roboti.sebastian;
- import java.awt.Color;
- import robocode.AdvancedRobot;
- import robocode.HitByBulletEvent;
- import robocode.HitRobotEvent;
- import robocode.HitWallEvent;
- import robocode.ScannedRobotEvent;
- // API help : http://robocode.sourceforge.net/docs/robocode/robocode/Robot.html
- /**
- * AB123 - a robot by (your name here)
- */
- public class Masakrator extends AdvancedRobot {
- private byte scanDirection = 1;
- /**
- * run: AB123's default behavior
- */
- public void run() {
- // Colors
- setBodyColor(Color.red);
- setGunColor(Color.black);
- setRadarColor(Color.black);
- setBulletColor(Color.red);
- setScanColor(Color.red);
- // Initialization of the robot should be put here
- // After trying out your robot, try uncommenting the import at the top,
- // and the next line:
- // setColors(Color.red,Color.blue,Color.green); // body,gun,radar
- while(true) {
- setAdjustRadarForRobotTurn(true);
- setTurnRadarRight(36000);
- execute ();
- // Robot main loop
- }
- }
- /**
- * onScannedRobot: What to do when you see another robot
- */
- public void onScannedRobot(ScannedRobotEvent e) {
- // Lock on to our target (this time for sure)
- setTurnRight(e.getBearing());
- // move a little closer
- if (e.getDistance() > 200)
- setAhead(e.getDistance() / 2);
- // but not too close
- if (e.getDistance() < 100)
- setBack(e.getDistance());
- // shoot at him
- setFire(3);
- // wobble the radar to generate another scan event
- scanDirection *= -1;
- setTurnRadarRight(36000 * scanDirection);
- }
- /**
- * onHitByBullet: What to do when you're hit by a bullet
- */
- public void onHitByBullet(HitByBulletEvent e) {
- // Replace the next line with any behavior you would like
- back(20);
- }
- /**
- * onHitWall: What to do when you hit a wall
- */
- public void onHitWall(HitWallEvent e) {
- // Replace the next line with any behavior you would like
- back(20);
- }
- public void onHitRobot (HitRobotEvent e) {
- // Replace the next line with any behavior you would like
- back (20);
- ahead (100);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement