Created
September 8, 2015 22:39
-
-
Save iamlucianojr/ba143dee17ee1e0649a1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package br.edu.ifc.blu; | |
import robocode.*; | |
import robocode.Robot; | |
import java.awt.*; | |
public class Sentinel extends Robot { | |
public void run() { | |
// Initialization of the robot should be put here | |
// After trying out your robot, try uncommenting the import at the top, | |
// and the next line: | |
setBodyColor(Color.black); //cor do corpo. | |
setGunColor(Color.black); //cor da arma. | |
setRadarColor(Color.black); //cor do radar. | |
setScanColor(Color.black); //cor do scan. | |
setBulletColor(Color.black); //cor da bala. | |
// Robot main loop | |
while(true) { | |
// Replace the next 4 lines with any behavior you would like | |
this.ahead(100); | |
this.turnGunRight(180); | |
this.back(100); | |
this.turnGunRight(360); | |
} | |
} | |
/** | |
* Evento disparado quando o scan identifica um outro robô. | |
*/ | |
public void onScannedRobot(ScannedRobotEvent e) { | |
if ( ! isFriend(e.getName())) { | |
if(e.getDistance() < 3.0){ | |
fireBullet(3); | |
}else{ | |
fireBullet(1); | |
} | |
} | |
} | |
@Override | |
public void onHitByBullet(HitByBulletEvent event) { | |
fixCoordinators(event.getBearing()); | |
fire(3); | |
} | |
private double fixCoordinators(double coordinate) { | |
if ( ! ( coordinate > -180 && coordinate <= 180)) { | |
while (coordinate <= -180) { | |
coordinate += 360; | |
} | |
while (coordinate > 180) { | |
coordinate -= 360; | |
} | |
} | |
return coordinate; | |
} | |
/** | |
* 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 | |
// if ( ! isFriend(e.getName())) { | |
// this.fire(100); | |
// } | |
// | |
// this.turnRight(90); //Gira 90º para a direita. | |
// this.ahead(100); | |
// } | |
/** | |
* onHitWall: What to do when you hit a wall | |
*/ | |
public void onHitWall(HitWallEvent e) { | |
// Replace the next line with any behavior you would like | |
this.back(20); | |
} | |
private boolean isFriend(String robotName) { | |
return robotName.startsWith("br.edu.ifc.blu"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment