|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
public interface IBasicEvents
An event interface for receiving basic robot events with an
IBasicRobot.
IBasicRobot| Method Summary | |
|---|---|
void |
onBulletHit(BulletHitEvent event)
This method is called when one of your bullets hits another robot. |
void |
onBulletHitBullet(BulletHitBulletEvent event)
This method is called when one of your bullets hits another bullet. |
void |
onBulletMissed(BulletMissedEvent event)
This method is called when one of your bullets misses, i.e. hits a wall. |
void |
onDeath(DeathEvent event)
This method is called if your robot dies. |
void |
onHitByBullet(HitByBulletEvent event)
This method is called when your robot is hit by a bullet. |
void |
onHitRobot(HitRobotEvent event)
This method is called when your robot collides with another robot. |
void |
onHitWall(HitWallEvent event)
This method is called when your robot collides with a wall. |
void |
onRobotDeath(RobotDeathEvent event)
This method is called when another robot dies. |
void |
onScannedRobot(ScannedRobotEvent event)
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. |
void |
onStatus(StatusEvent event)
This method is called every turn in a battle round in order to provide the robot status as a complete snapshot of the robot's current state at that specific time. |
void |
onWin(WinEvent event)
This method is called if your robot wins a battle. |
| Method Detail |
|---|
void onStatus(StatusEvent event)
Robot.getTime() and then
Robot.getHeading() afterwards, as the time might change
after between the Robot.getTime() and Robot.getHeading()
call.
event - the event containing the robot status at the time it occurred.StatusEvent,
Eventvoid onBulletHit(BulletHitEvent event)
public void onBulletHit(BulletHitEvent event) {
out.println("I hit " + event.getName() + "!");
}
event - the bullet-hit event set by the gameBulletHitEvent,
Eventvoid onBulletHitBullet(BulletHitBulletEvent event)
public void onBulletHitBullet(BulletHitBulletEvent event) {
out.println("I hit a bullet fired by " + event.getBullet().getName() + "!");
}
event - the bullet-hit-bullet event set by the gameBulletHitBulletEvent,
Eventvoid onBulletMissed(BulletMissedEvent event)
public void onBulletMissed(BulletMissedEvent event) {
out.println("Drat, I missed.");
}
event - the bullet-missed event set by the gameBulletMissedEvent,
Eventvoid onDeath(DeathEvent event)
event - the death event set by the gameDeathEvent,
WinEvent,
RoundEndedEvent,
BattleEndedEvent,
Eventvoid onHitByBullet(HitByBulletEvent event)
void onHitByBullet(HitByBulletEvent event) {
out.println(event.getRobotName() + " hit me!");
}
event - the hit-by-bullet event set by the gameHitByBulletEvent,
Eventvoid onHitRobot(HitRobotEvent event)
void onHitRobot(HitRobotEvent event) {
if (event.getBearing() > -90 && event.getBearing() <= 90) {
back(100);
} else {
ahead(100);
}
}
-- or perhaps, for a more advanced robot --
public void onHitRobot(HitRobotEvent event) {
if (event.getBearing() > -90 && event.getBearing() <= 90) {
setBack(100);
} else {
setAhead(100);
}
}
The angle is relative to your robot's facing. So 0 is straight ahead of
you.
This event can be generated if another robot hits you, in which case
event.isMyFault() will return
false. In this case, you will not be automatically stopped by the
game -- but if you continue moving toward the robot you will hit it (and
generate another event). If you are moving away, then you won't hit it.
event - the hit-robot event set by the gameHitRobotEvent,
Eventvoid onHitWall(HitWallEvent event)
turnRight (event.getBearing()) will
point you perpendicular to the wall.
Example:
void onHitWall(HitWallEvent event) {
out.println("Ouch, I hit a wall bearing " + event.getBearing() + " degrees.");
}
event - the hit-wall event set by the gameHitWallEvent,
Eventvoid onScannedRobot(ScannedRobotEvent event)
Rules.RADAR_SCAN_RADIUS (1200 pixels).
Also not that the bearing of the scanned robot is relative to your
robot's heading.
Example:
void onScannedRobot(ScannedRobotEvent event) {
// Assuming radar and gun are aligned...
if (event.getDistance() < 100) {
fire(3);
} else {
fire(1);
}
}
Note:fire() will fire directly at the robot.
fire() would
hit. (i.e. you are spinning your gun around, but by the time you get the
event, your gun is 5 degrees past the robot).
event - the scanned-robot event set by the gameScannedRobotEvent,
Event,
Rules.RADAR_SCAN_RADIUSvoid onRobotDeath(RobotDeathEvent event)
event - The robot-death event set by the gameRobotDeathEvent,
Eventvoid onWin(WinEvent event)
event - the win event set by the gameDeathEvent,
RoundEndedEvent,
BattleEndedEvent,
Event
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||