Skip to content

Instantly share code, notes, and snippets.

@fsouza
Created June 10, 2011 04:48
Show Gist options
  • Save fsouza/1018245 to your computer and use it in GitHub Desktop.
Save fsouza/1018245 to your computer and use it in GitHub Desktop.
package torneio;
import robocode.*;
import java.awt.Color;
/**
* Rosquinha - um robô carrossel!
*
* Robô utilizado no campeonato de Robocode do IFES, em 2008.
*/
public class Rosquinha extends AdvancedRobot
{
public void run() {
this.setColors(Color.white,Color.black,Color.white);
this.setBulletColor(Color.red);
while(true) {
this.setAhead(2000);
this.setTurnRight(200);
this.waitFor(new TurnCompleteCondition(this));
}
}
public void onScannedRobot(ScannedRobotEvent e) {
if(this.getGunHeat() == 0) {
if(e.getDistance() < 50)
this.fire(Math.min(3, getEnergy() - 0.5));
else
this.fire(Math.min(2, getEnergy() - 0.5));
this.scan();
} else {
this.doNothing();
}
}
public void onHitByBullet(HitByBulletEvent e) {
if(this.getEnergy() < 10) {
this.setBack(1500);
this.setTurnRight(90);
this.waitFor(new TurnCompleteCondition(this));
} else {
this.scan();
}
}
public void onHitRobot(HitRobotEvent e) {
if(e.isMyFault()) {
this.turnRight(e.getBearing());
this.scan();
} else {
this.scan();
}
}
public void onHitWall(HitWallEvent e) {
this.setBack(1500);
this.setTurnRight(e.getBearing());
this.waitFor(new TurnCompleteCondition(this));
this.scan();
}
public void onWin(WinEvent e) {
while(true) {
this.back(150);
this.ahead(100);
}
}
public void chorar() {
System.out.println("Buáááá!");
}
public void onDeath(DeathEvent e) {
this.chorar();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment