|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectrobocode._RobotBase
robocode.Ship
public class Ship
This is the improved version of the Ship which acts far more like a ship.
| Field Summary |
|---|
| Fields inherited from class robocode._RobotBase |
|---|
out |
| Constructor Summary | |
|---|---|
Ship()
|
|
| Method Summary | |
|---|---|
void |
addCustomEvent(Condition condition)
Registers a custom event to be called when a condition is met. |
void |
clearAllEvents()
Clears out any pending events in the robot's event queue immediately. |
void |
execute()
Executes any pending actions, or continues executing actions that are in process. |
void |
fireBackCannon(double power)
Fires the a bullet/missile from the back cannon with the given power |
void |
fireFrontCannon(double power)
Fires the a bullet/missile from the front cannon with the given power |
IAdvancedEvents |
getAdvancedEventListener()
Do not call this method! |
Vector<Event> |
getAllEvents()
Returns a vector containing all events currently in the robot's queue. |
boolean |
getBackCannonAtBlindSpot()
Returns true when the blindSpot has been reached for the backCannon |
double |
getBackCannonHeadingDegrees()
Retrieve the angle the back cannon is heading in degrees. |
double |
getBackCannonHeadingRadians()
Retrieve the angle the back cannon is heading in radians. |
double |
getBackCannonTurnRemainingDegrees()
Returns the amount the Back Cannon still has to turn in degrees. |
double |
getBackCannonTurnRemainingRadians()
Returns the amount the Back Cannon still has to turn in radians. |
IBasicEvents |
getBasicEventListener()
This method is called by the game to notify this robot about basic robot event. |
double |
getBattleFieldHeight()
Returns the height of the current battlefield measured in pixels. |
double |
getBattleFieldWidth()
Returns the width of the current battlefield measured in pixels. |
double |
getBodyHeadingDegrees()
Returns the heading of the Ship in Degrees. |
double |
getBodyHeadingRadians()
Returns the heading of the Ship in Radians. |
double |
getBodyTurnRemainingDegrees()
Deprecated to avoid confusion Returns the angle remaining in the robots's turn, in degrees. |
double |
getBodyTurnRemainingRadians()
Returns the angle remaining in the robot's turn, in radians. |
Vector<BulletHitBulletEvent> |
getBulletHitBulletEvents()
Returns a vector containing all BulletHitBulletEvents currently in the robot's queue. |
Vector<BulletHitEvent> |
getBulletHitEvents()
Returns a vector containing all BulletHitEvents currently in the robot's queue. |
Vector<BulletMissedEvent> |
getBulletMissedEvents()
Returns a vector containing all BulletMissedEvents currently in the robot's queue. |
double |
getComponentHeadingDegrees(int index)
Returns the absolute heading of the component in degrees. |
double |
getComponentHeadingRadians(int index)
Returns the absolute heading of the component in radians. |
BlindSpot |
getCopyOfBlindSpotBackCannon()
Returns a copy of the BlindSpot that the back cannon has. |
BlindSpot |
getCopyOfBlindSpotFrontCannon()
Returns a copy of the BlindSpot that the back cannon has. |
File |
getDataDirectory()
Returns a file representing a data directory for the robot, which can be written to using RobocodeFileOutputStream or
RobocodeFileWriter. |
File |
getDataFile(String filename)
Returns a file in your data directory that you can write to using RobocodeFileOutputStream or RobocodeFileWriter. |
long |
getDataQuotaAvailable()
Returns the data quota available in your data directory, i.e. the amount of bytes left in the data directory for the robot. |
double |
getDistanceRemaining()
Returns the distance remaining in the robot's current move measured in pixels. |
double |
getEnergy()
Returns the robot's current energy. |
int |
getEventPriority(String eventClass)
Returns the current priority of a class of events. |
double |
getFirePower(int index)
Returns the FirePower of the specified component. |
boolean |
getFrontCannonAtBlindSpot()
Returns true when the blindSpot has been reached for the backCannon |
double |
getFrontCannonHeadingDegrees()
Retrieve the angle the front cannon is heading in degrees. |
double |
getFrontCannonHeadingRadians()
Retrieve the angle the front cannon is heading in radians. |
double |
getFrontCannonTurnRemainingDegrees()
Returns the amount the Front Cannon still has to turn in degrees. |
double |
getFrontCannonTurnRemainingRadians()
Returns the amount the Front Cannon still has to turn in radians. |
double |
getGunHeatComponent(int index)
Returns the gunHeat of the given component. |
Vector<HitByBulletEvent> |
getHitByBulletEvents()
Returns a vector containing all HitByBulletEvents currently in the robot's queue. |
Vector<HitRobotEvent> |
getHitRobotEvents()
Returns a vector containing all HitRobotEvents currently in the robot's queue. |
Vector<HitWallEvent> |
getHitWallEvents()
Returns a vector containing all HitWallEvents currently in the robot's queue. |
int |
getOthers()
Returns how many opponents that are left in the current round. |
IPaintEvents |
getPaintEventListener()
This method is called by the game to notify this robot about painting events. |
double |
getRadarHeadingDegrees()
Retrieve the angle the radar is heading in degrees. |
double |
getRadarHeadingRadians()
Retrieve the angle the radar is heading in radians. |
double |
getRadarTurnRemainingDegrees()
Returns the amount the Radar still has to turn in degrees. |
double |
getRadarTurnRemainingRadians()
Returns the amount the Radar still has to turn in radians. |
Vector<RobotDeathEvent> |
getRobotDeathEvents()
Returns a vector containing all RobotDeathEvents currently in the robot's queue. |
Runnable |
getRobotRunnable()
This method is called by the game to invoke the run() method of your robot, where the program
of your robot is implemented. |
Vector<ScannedRobotEvent> |
getScannedRobotEvents()
Returns a vector containing all ScannedRobotEvents currently in the robot's queue. |
Vector<StatusEvent> |
getStatusEvents()
Returns a vector containing all StatusEvents currently in the robot's queue. |
long |
getTime()
Returns the game time of the current round, where the time is equal to the current turn in the round. |
double |
getVelocity()
Returns the velocity the Ship is going at in knots (pixels per second) |
double |
getX()
Returns the X position of the robot. (0,0) is at the bottom left of the battlefield. |
double |
getXBackCannon()
Returns the current X-coordinate of your back cannon |
double |
getXFrontCannon()
Returns the current X-coordinate of your front cannon |
double |
getXMiddle()
Returns the X coordinate of the middle of the Ship. |
double |
getXRadar()
Returns the current X-coordinate of the Radar |
double |
getY()
Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield. |
double |
getYBackCannon()
Returns the current Y-coordinate of your back cannon |
double |
getYFrontCannon()
Returns the current Y-coordinate of your front cannon |
double |
getYMiddle()
Returns the Y coordinate of the middle of the Ship. |
double |
getYRadar()
Returns the current Y-coordinate of the Radar |
void |
onBattleEnded(BattleEndedEvent event)
This method is called after the end of the battle, even when the battle is aborted. |
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 |
onCustomEvent(CustomEvent event)
This method is called when a custom condition is met. |
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 |
onHitByMine(HitByMineEvent event)
Triggers when your Ship get hit by a Mine. |
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 |
onMineHit(MineHitEvent event)
Triggers when your Mine has hit a Ship (Can be your own Ship) |
void |
onMineHitMine(MineHitMineEvent event)
Triggers when your Mine has hit another Mine. |
void |
onPaint(Graphics2D g)
This method is called every time the robot is painted. |
void |
onRobotDeath(RobotDeathEvent event)
This method is called when another robot dies. |
void |
onRoundEnded(RoundEndedEvent event)
This method is called after the end of a round. |
void |
onScannedRobot(ScannedRobotEvent event)
Deprecated. Use onScannedShip(ScannedShipEvent event) instead. |
void |
onScannedShip(ScannedShipEvent event)
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. |
void |
onSkippedTurn(SkippedTurnEvent event)
This method is called if the robot is using too much time between actions. |
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. |
Mine |
placeMine(double power)
|
void |
removeCustomEvent(Condition condition)
Removes a custom event that was previously added by calling addCustomEvent(Condition). |
void |
resume()
Immediately resumes the movement you stopped by stop(), if any. |
void |
run()
This is the method you have to override to create your own ship. |
void |
scan()
|
void |
setAdjustComponentForShipTurn(int index,
boolean independent)
Sets whether the component moves dependently from the Ship or not. |
void |
setAhead(double distance)
Immediately moves your robot ahead (forward) by distance measured in pixels. |
void |
setBack(double distance)
Moves your Ship back by the given number of pixels. |
void |
setBackCannonColor(Color color)
Sets the color of the back cannon. |
void |
setBodyColor(Color color)
Sets the color of the body of the ship |
void |
setBulletColor(Color color)
Sets the BulletColor for both Front and Back Cannon. |
void |
setBulletColorBack(Color color)
Sets the Bullet Color for the Back Cannon |
void |
setBulletColorFront(Color color)
Sets the Bullet Color for the Front Cannon |
void |
setCourseDegrees(double angle)
Sets the course towards the specified heading. |
void |
setCourseRadians(double angle)
Sets the course towards the specified heading. |
void |
setEventPriority(String eventClass,
int priority)
Sets the priority of a class of events. |
void |
setFrontCannonColor(Color color)
Sets the color of the front cannon. |
void |
setInterruptible(boolean interruptible)
Call this during an event handler to allow new events of the same priority to restart the event handler. |
void |
setMaxKnots(double maxKnots)
Sets the maximum amount of knots you want to travel per turn. |
void |
setMineComponentColor(Color color)
|
void |
setRadarColor(Color color)
Sets the color of the radar. |
void |
setResume()
Sets the robot to resume the movement stopped by stop()
or setStop(), if any. |
void |
setScanColor(Color color)
Sets the Color of your scan |
void |
setStop()
This call is identical to stop(), but returns immediately, and
will not execute until you call execute() or take an action that
executes. |
void |
setStop(boolean overwrite)
This call is identical to stop(boolean), but
returns immediately, and will not execute until you call
execute() or take an action that executes. |
void |
setTurnBackCannonLeftDegrees(double angle)
Turns the back cannon towards the left by the amount given in degrees. |
void |
setTurnBackCannonLeftRadians(double angle)
Turns the back cannon towards the left by the amount given in radians. |
void |
setTurnBackCannonRightDegrees(double angle)
Turns the back cannon towards the right by the amount given in degrees. |
void |
setTurnBackCannonRightRadians(double angle)
Turns the back cannon towards the right by the amount given in radians. |
void |
setTurnFrontCannonLeftDegrees(double angle)
Turns the front cannon towards the left by the amount given in degrees. |
void |
setTurnFrontCannonLeftRadians(double angle)
Turns the front cannon towards the left by the amount given in radians. |
void |
setTurnFrontCannonRightDegrees(double angle)
Turns the front cannon towards the right by the amount given in degrees. |
void |
setTurnFrontCannonRightRadians(double angle)
Turns the front cannon towards the right by the amount given in radians. |
void |
setTurnLeftDegrees(double angle)
Attempts to turn your Ship by the given angle in degrees towards the left. |
void |
setTurnLeftRadians(double radians)
Attempts to turn your Ship by the given angle in radians towards the left. |
void |
setTurnRadarLeftDegrees(double angle)
Set the angle the Radar needs to turn towards the left in degrees. |
void |
setTurnRadarLeftRadians(double angle)
Set the angle the Radar needs to turn towards the Left in radians. |
void |
setTurnRadarRightDegrees(double angle)
Set the angle the Radar needs to turn towards the right in degrees. |
void |
setTurnRadarRightRadians(double angle)
Set the angle the Radar needs to turn towards the Left in radians. |
void |
setTurnRightDegrees(double angle)
Attempts to turn your Ship by the given angle in degrees towards the right. |
void |
setTurnRightRadians(double radians)
Attempts to turn your Ship by the given angle in radians towards the right. |
void |
stop()
Immediately stops all movement, and saves it for a call to resume(). |
void |
stop(boolean overwrite)
Immediately stops all movement, and saves it for a call to resume(). |
void |
waitFor(Condition condition)
Does not return until a condition is met, i.e. when a Condition.test() returns true. |
| Methods inherited from class robocode._RobotBase |
|---|
finalize, setOut, setPeer |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface robocode.robotinterfaces.IBasicRobot |
|---|
setOut, setPeer |
| Constructor Detail |
|---|
public Ship()
| Method Detail |
|---|
public void setTurnRadarLeftDegrees(double angle)
setTurnRadarLeftDegrees in interface IRadarFunctionsangle - The angle you want to turn the radar towards the left in degrees.public void setTurnRadarRightDegrees(double angle)
setTurnRadarRightDegrees in interface IRadarFunctionsangle - The angle you want to turn the radar towards the right in degrees.public void setTurnRadarLeftRadians(double angle)
setTurnRadarLeftRadians in interface IRadarFunctionsangle - The angle you want to turn the radar towards the left in radians.public void setTurnRadarRightRadians(double angle)
setTurnRadarRightRadians in interface IRadarFunctionsangle - The angle you want to turn the radar towards the right in radians.public double getRadarHeadingRadians()
getRadarHeadingRadians in interface IRadarFunctionspublic double getRadarHeadingDegrees()
getRadarHeadingDegrees in interface IRadarFunctionspublic double getRadarTurnRemainingRadians()
getRadarTurnRemainingRadians in interface IRadarFunctionspublic double getRadarTurnRemainingDegrees()
getRadarTurnRemainingDegrees in interface IRadarFunctionspublic void setTurnFrontCannonLeftDegrees(double angle)
setTurnFrontCannonLeftDegrees in interface IFrontCannonFunctionsangle - The angle in degrees you want to rotate your front cannon to the left.public void setTurnFrontCannonRightDegrees(double angle)
setTurnFrontCannonRightDegrees in interface IFrontCannonFunctionsangle - The angle in degrees you want to rotate your front cannon to the right.public void setTurnFrontCannonLeftRadians(double angle)
setTurnFrontCannonLeftRadians in interface IFrontCannonFunctionsangle - The angle in radians you want to rotate your front cannon to the left.public void setTurnFrontCannonRightRadians(double angle)
setTurnFrontCannonRightRadians in interface IFrontCannonFunctionsangle - The angle in radians you want to rotate your front cannon to the right.public double getFrontCannonHeadingRadians()
getFrontCannonHeadingRadians in interface IFrontCannonFunctionspublic double getFrontCannonHeadingDegrees()
getFrontCannonHeadingDegrees in interface IFrontCannonFunctionspublic BlindSpot getCopyOfBlindSpotFrontCannon()
getCopyOfBlindSpotFrontCannon in interface IFrontCannonFunctionsFurthest you can move to the left,
Furthest you can move to the right,
Returns whether the destination is within the BlindSpotpublic boolean getFrontCannonAtBlindSpot()
getFrontCannonAtBlindSpot in interface IFrontCannonFunctionspublic double getFrontCannonTurnRemainingRadians()
getFrontCannonTurnRemainingRadians in interface IFrontCannonFunctionspublic double getFrontCannonTurnRemainingDegrees()
getFrontCannonTurnRemainingDegrees in interface IFrontCannonFunctionspublic void setTurnBackCannonLeftDegrees(double angle)
setTurnBackCannonLeftDegrees in interface IBackCannonFunctionsangle - The angle in degrees you want to rotate your back cannon to the left.public void setTurnBackCannonRightDegrees(double angle)
setTurnBackCannonRightDegrees in interface IBackCannonFunctionsangle - The angle in degrees you want to rotate your back cannon to the right.public void setTurnBackCannonLeftRadians(double angle)
setTurnBackCannonLeftRadians in interface IBackCannonFunctionsangle - The angle in radians you want to rotate your back cannon to the left.public void setTurnBackCannonRightRadians(double angle)
setTurnBackCannonRightRadians in interface IBackCannonFunctionsangle - The angle in radians you want to rotate your back cannon to the right.public double getBackCannonHeadingRadians()
getBackCannonHeadingRadians in interface IBackCannonFunctionspublic double getBackCannonHeadingDegrees()
getBackCannonHeadingDegrees in interface IBackCannonFunctionspublic BlindSpot getCopyOfBlindSpotBackCannon()
getCopyOfBlindSpotBackCannon in interface IBackCannonFunctionsFurthest you can move to the left,
Furthest you can move to the right,
Returns whether the destination is within the BlindSpotpublic boolean getBackCannonAtBlindSpot()
getBackCannonAtBlindSpot in interface IBackCannonFunctionspublic double getBackCannonTurnRemainingRadians()
getBackCannonTurnRemainingRadians in interface IBackCannonFunctionspublic double getBackCannonTurnRemainingDegrees()
getBackCannonTurnRemainingDegrees in interface IBackCannonFunctionspublic void fireFrontCannon(double power)
fireFrontCannon in interface IFrontCannonFunctionspower - The power you want to shoot your bullet/missile at. The value is a double between 0.1 and 3.0public void fireBackCannon(double power)
fireBackCannon in interface IBackCannonFunctionspower - The power you want to shoot your bullet/missile at. The value is a double between 0.1 and 3.0public void setCourseDegrees(double angle)
setCourseDegrees in interface IShipangle - The angle in degrees to which we want to set course. (0 = North, 90 = East, etc)public void setBodyColor(Color color)
setBodyColor in interface IShipcolor - The color you wish your ship to bepublic void setFrontCannonColor(Color color)
setFrontCannonColor in interface IFrontCannonFunctionscolor - The color you want your front cannon to be.public void setRadarColor(Color color)
setRadarColor in interface IRadarFunctionscolor - The color you want your radar to be.public void setBackCannonColor(Color color)
setBackCannonColor in interface IBackCannonFunctionscolor - The color you want your back cannon to be.public void setBulletColor(Color color)
color - The Color you want your bullets to be.public void setBulletColorBack(Color color)
setBulletColorBack in interface IBackCannonFunctionscolor - The Color you want the Bullets the Back Cannon shoots to be.public void setBulletColorFront(Color color)
setBulletColorFront in interface IFrontCannonFunctionscolor - The Color you want the Bullets the Front Cannon shoots to be.public void setScanColor(Color color)
setScanColor in interface IRadarFunctionscolor - The color you want your scan to be.public void setTurnLeftRadians(double radians)
setTurnLeftRadians in interface IShipradians - The angle in radians we want to rotate to the left.public void setTurnRightRadians(double radians)
setTurnRightRadians in interface IShipradians - The angle in radians we want to rotate to the right.public void setTurnLeftDegrees(double angle)
setTurnLeftDegrees in interface IShipangle - The angle in degrees we want to rotate to the left.public void setTurnRightDegrees(double angle)
setTurnRightDegrees in interface IShipangle - The angle in degrees we want to rotate to the right.
public void setAdjustComponentForShipTurn(int index,
boolean independent)
setAdjustComponentForShipTurn in interface IShipindex - The index of the componentindependent - True for independent movement. False of dependent movement.public void setMaxKnots(double maxKnots)
setMaxKnots in interface IShippublic double getFirePower(int index)
index -
public void scan()
scan in interface IShippublic void execute()
IShip.setAhead(double),
IShip.setTurnLeftDegrees(double) etc. Otherwise,
these calls will never get executed.
execute in interface IShippublic void onBattleEnded(BattleEndedEvent event)
public void onBattleEnded(BattleEndedEvent event) {
out.println("The battle has ended");
}
onBattleEnded in interface IBasicEvents2event - the BattleEndedEvent set by the gameBattleEndedEvent,
IBasicEvents3.onRoundEnded(RoundEndedEvent),
WinEvent,
DeathEvent,
Eventpublic void onBulletHit(BulletHitEvent event)
public void onBulletHit(BulletHitEvent event) {
out.println("I hit " + event.getName() + "!");
}
onBulletHit in interface IBasicEventsevent - the bullet-hit event set by the gameBulletHitEvent,
Eventpublic void onBulletHitBullet(BulletHitBulletEvent event)
public void onBulletHitBullet(BulletHitBulletEvent event) {
out.println("I hit a bullet fired by " + event.getBullet().getName() + "!");
}
onBulletHitBullet in interface IBasicEventsevent - the bullet-hit-bullet event set by the gameBulletHitBulletEvent,
Eventpublic void onBulletMissed(BulletMissedEvent event)
public void onBulletMissed(BulletMissedEvent event) {
out.println("Drat, I missed.");
}
onBulletMissed in interface IBasicEventsevent - the bullet-missed event set by the gameBulletMissedEvent,
Eventpublic void onDeath(DeathEvent event)
onDeath in interface IBasicEventsevent - the death event set by the gameDeathEvent,
WinEvent,
RoundEndedEvent,
BattleEndedEvent,
Eventpublic void onHitByBullet(HitByBulletEvent event)
void onHitByBullet(HitByBulletEvent event) {
out.println(event.getRobotName() + " hit me!");
}
onHitByBullet in interface IBasicEventsevent - the hit-by-bullet event set by the gameHitByBulletEvent,
Eventpublic void 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.
onHitRobot in interface IBasicEventsevent - the hit-robot event set by the gameHitRobotEvent,
Eventpublic void 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.");
}
onHitWall in interface IBasicEventsevent - the hit-wall event set by the gameHitWallEvent,
Eventpublic void onPaint(Graphics2D g)
onPaint in interface IPaintEventsg - the graphics context to use for painting graphical items for the
robot.Graphics2Dpublic void onRobotDeath(RobotDeathEvent event)
onRobotDeath in interface IBasicEventsevent - The robot-death event set by the gameRobotDeathEvent,
Eventpublic void onRoundEnded(RoundEndedEvent event)
public void onRoundEnded(RoundEndedEvent event) {
out.println("The round has ended");
}
onRoundEnded in interface IBasicEvents3event - the RoundEndedEvent event set by the gameRoundEndedEvent,
IBasicEvents2.onBattleEnded(BattleEndedEvent),
WinEvent,
DeathEvent,
Eventpublic void onScannedShip(ScannedShipEvent event)
onScannedRobot
event. Rather then having the bearing from the center of your ship to
the other ship. This event contains the bearings for both the front
and the back canon. The only thing you have to do is rotate them by
the given amount of degrees.
onScannedShip in interface IBasicEvents4event - the scanned-robot event set by the gameIBasicEvents.onScannedRobot(ScannedRobotEvent),
ScannedRobotEvent,
Event,
Rules.RADAR_SCAN_RADIUSpublic 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.
onStatus in interface IBasicEventsevent - the event containing the robot status at the time it occurred.StatusEvent,
Eventpublic void onWin(WinEvent event)
onWin in interface IBasicEventsevent - the win event set by the gameDeathEvent,
RoundEndedEvent,
BattleEndedEvent,
Eventpublic void onMineHitMine(MineHitMineEvent event)
onMineHitMine in interface IBasicEvents4event - You can use this event to retrieve the Mine that hit and the Mine that got hit.public void onMineHit(MineHitEvent event)
onMineHit in interface IBasicEvents4event - Has information like the Ship you hit, the Mine that hit and the energy left on that Ship.public void onHitByMine(HitByMineEvent event)
onHitByMine in interface IBasicEvents4event - Contains the Mine that hit you, not much else.public void onScannedRobot(ScannedRobotEvent event)
onScannedShip(ScannedShipEvent event) instead.
IBasicEventsRules.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).
onScannedRobot in interface IBasicEventsevent - the scanned-robot event set by the gameScannedRobotEvent,
Event,
Rules.RADAR_SCAN_RADIUSpublic double getVelocity()
getVelocity in interface IShippublic void setAhead(double distance)
// Move the robot 100 pixels forward ahead(100); // Afterwards, move the robot 50 pixels backward ahead(-50);
setAhead in interface IShipdistance - the distance to move ahead measured in pixels.
If this value is negative, the robot will move back instead of ahead.#back(double),
#onHitWall(HitWallEvent),
#onHitRobot(HitRobotEvent)public void setBack(double distance)
setBack in interface IShipdistance - The distance you want to move backwards in pixels.public double getDistanceRemaining()
getDistanceRemaining in interface IShippublic double getBodyHeadingRadians()
getBodyHeadingRadians in interface IShippublic double getBodyHeadingDegrees()
getBodyHeadingDegrees in interface IShippublic double getGunHeatComponent(int index)
getGunHeatComponent in interface IShipindex - The index of the component you want to know the gunHeat of.
public double getComponentHeadingDegrees(int index)
getComponentHeadingDegrees in interface IShipindex - The index of the component you want to know the heading of.
public double getComponentHeadingRadians(int index)
getComponentHeadingRadians in interface IShipindex - The index of the component you want to know the heading of.
public double getX()
getX in interface IShipIShip.getY(),
IShip.getXMiddle()public double getXMiddle()
getXMiddle in interface IShipIShip.getX()public double getXFrontCannon()
IFrontCannonFunctions
getXFrontCannon in interface IFrontCannonFunctionspublic double getXBackCannon()
IBackCannonFunctions
getXBackCannon in interface IBackCannonFunctionspublic double getXRadar()
IRadarFunctions
getXRadar in interface IRadarFunctionspublic double getY()
getY in interface IShipIShip.getX(),
IShip.getYMiddle()public double getYMiddle()
getYMiddle in interface IShipIShip.getY()public double getYFrontCannon()
IFrontCannonFunctions
getYFrontCannon in interface IFrontCannonFunctionspublic double getYBackCannon()
IBackCannonFunctions
getYBackCannon in interface IBackCannonFunctionspublic double getYRadar()
IRadarFunctions
getYRadar in interface IRadarFunctionspublic double getBattleFieldWidth()
getBattleFieldWidth in interface IShippublic double getBattleFieldHeight()
getBattleFieldHeight in interface IShippublic double getBodyTurnRemainingDegrees()
getBodyTurnRemainingDegrees in interface IShipgetTurnRemainingRadians(),
getDistanceRemaining(),
getGunTurnRemaining(),
getGunTurnRemainingRadians(),
getRadarTurnRemaining(),
getRadarTurnRemainingRadians()public double getBodyTurnRemainingRadians()
getBodyTurnRemainingRadians in interface IShippublic long getTime()
getTime in interface IShippublic double getEnergy()
getEnergy in interface IShippublic void addCustomEvent(Condition condition)
removeCustomEvent(Condition).
Example:
// Create the condition for our custom event
Condition triggerHitCondition = new Condition("triggerhit") {
public boolean test() {
return (getEnergy() <= trigger);
}
}
// Add our custom event based on our condition
addCustomEvent(triggerHitCondition);
condition - the condition that must be met.
NullPointerException - if the condition parameter has been set to
null.Condition,
removeCustomEvent(Condition)public void removeCustomEvent(Condition condition)
addCustomEvent(Condition).
Example:
// Create the condition for our custom event
Condition triggerHitCondition = new Condition("triggerhit") {
public boolean test() {
return (getEnergy() <= trigger);
}
}
// Add our custom event based on our condition
addCustomEvent(triggerHitCondition);
...
do something with your robot
...
// Remove the custom event based on our condition
removeCustomEvent(triggerHitCondition);
condition - the condition that was previous added and that must be
removed now.
NullPointerException - if the condition parameter has been set to
null.Condition,
addCustomEvent(Condition)public void clearAllEvents()
getAllEvents()public Vector<Event> getAllEvents()
for (Event event : getAllEvents()) {
if (event instanceof HitRobotEvent) {
// do something with the event
} else if (event instanceof HitByBulletEvent) {
// do something with the event
}
}
Event,
clearAllEvents(),
getStatusEvents(),
getScannedRobotEvents(),
getBulletHitEvents(),
getBulletMissedEvents(),
getBulletHitBulletEvents(),
getRobotDeathEvents()public Vector<BulletHitBulletEvent> getBulletHitBulletEvents()
for (BulletHitBulletEvent event : getBulletHitBulletEvents()) {
// do something with the event
}
onBulletHitBullet(BulletHitBulletEvent),
BulletHitBulletEvent,
getAllEvents()public Vector<BulletHitEvent> getBulletHitEvents()
for (BulletHitEvent event: getBulletHitEvents()) {
// do something with the event
}
onBulletHit(BulletHitEvent),
BulletHitEvent,
getAllEvents()public Vector<BulletMissedEvent> getBulletMissedEvents()
for (BulletMissedEvent event : getBulletMissedEvents()) {
// do something with the event
}
onBulletMissed(BulletMissedEvent),
BulletMissedEvent,
getAllEvents()public int getEventPriority(String eventClass)
int myHitRobotPriority = getEventPriority("HitRobotEvent");
The default priorities are, from highest to lowest:
RoundEndedEvent: 100 (reserved)BattleEndedEvent: 100 (reserved)WinEvent: 100 (reserved)SkippedTurnEvent: 100 (reserved)StatusEvent: 99 Key and mouse events: 98CustomEvent: 80 (default value)MessageEvent: 75RobotDeathEvent: 70BulletMissedEvent: 60BulletHitBulletEvent: 55BulletHitEvent: 50HitByBulletEvent: 40HitWallEvent: 30HitRobotEvent: 20ScannedRobotEvent: 10PaintEvent: 5DeathEvent: -1 (reserved)
eventClass - the name of the event class (string)
setEventPriority(String, int)public Vector<HitByBulletEvent> getHitByBulletEvents()
for (HitByBulletEvent event : getHitByBulletEvents()) {
// do something with the event
}
onHitByBullet(HitByBulletEvent),
HitByBulletEvent,
getAllEvents()public Vector<HitRobotEvent> getHitRobotEvents()
for (HitRobotEvent event : getHitRobotEvents()) {
// do something with the event
}
onHitRobot(HitRobotEvent),
HitRobotEvent,
getAllEvents()public Vector<HitWallEvent> getHitWallEvents()
for (HitWallEvent event : getHitWallEvents()) {
// do something with the event
}
onHitWall(HitWallEvent),
HitWallEvent,
getAllEvents()public Vector<RobotDeathEvent> getRobotDeathEvents()
for (RobotDeathEvent event : getRobotDeathEvents()) {
// do something with the event
}
onRobotDeath(RobotDeathEvent),
RobotDeathEvent,
getAllEvents()public Vector<ScannedRobotEvent> getScannedRobotEvents()
for (ScannedRobotEvent event : getScannedRobotEvents()) {
// do something with the event
}
onScannedRobot(ScannedRobotEvent),
ScannedRobotEvent,
getAllEvents()public Vector<StatusEvent> getStatusEvents()
for (StatusEvent event : getStatusEvents()) {
// do something with the event
}
onStatus(StatusEvent),
StatusEvent,
getAllEvents()
public void setEventPriority(String eventClass,
int priority)
setEventPriority("RobotDeathEvent", 15);
The default priorities are, from highest to lowest:
WinEvent: 100 (reserved)
SkippedTurnEvent: 100 (reserved)
StatusEvent: 99
CustomEvent: 80
MessageEvent: 75
RobotDeathEvent: 70
BulletMissedEvent: 60
BulletHitBulletEvent: 55
BulletHitEvent: 50
HitByBulletEvent: 40
HitWallEvent: 30
HitRobotEvent: 20
ScannedRobotEvent: 10
PaintEvent: 5
DeathEvent: -1 (reserved)
Note that you cannot change the priority for events with the special
priority value -1 or 100 (reserved) as these event are system events.
Also note that you cannot change the priority of CustomEvent.
Instead you must change the priority of the condition(s) for your custom
event(s).
eventClass - the name of the event class (string) to set the
priority forpriority - the new priority for that event classgetEventPriority(String),
setInterruptible(boolean)public void setInterruptible(boolean interruptible)
Example:
public void onScannedRobot(ScannedRobotEvent e) {
fire(1);
setInterruptible(true);
ahead(100); // If you see a robot while moving ahead,
// this handler will start from the top
// Without setInterruptible(true), we wouldn't
// receive scan events at all!
// We'll only get here if we don't see a robot during the move.
out.println("Ok, I can't see anyone");
}
interruptible - true if the event handler should be
interrupted if new events of the same priority occurs; false
otherwisesetEventPriority(String, int),
onScannedRobot(ScannedRobotEvent)public void setResume()
stop()
or setStop(), if any.
This call returns immediately, and will not execute until you call
execute() or take an action that executes.
resume(),
stop(),
stop(boolean),
setStop(),
setStop(boolean),
execute()public void setStop()
stop(), but returns immediately, and
will not execute until you call execute() or take an action that
executes.
If there is already movement saved from a previous stop, this will have
no effect.
This call is equivalent to calling setStop(false);
stop(),
stop(boolean),
resume(),
setResume(),
setStop(boolean),
execute()public void setStop(boolean overwrite)
stop(boolean), but
returns immediately, and will not execute until you call
execute() or take an action that executes.
If there is already movement saved from a previous stop, you can
overwrite it by calling setStop(true).
overwrite - true if the movement saved from a previous stop
should be overwritten; false otherwise.stop(),
stop(boolean),
resume(),
setResume(),
setStop(),
execute()public Runnable getRobotRunnable()
run() method of your robot, where the program
of your robot is implemented.
getRobotRunnable in interface IBasicRobotRunnable.run()public IBasicEvents getBasicEventListener()
IBasicEvents listener.
getBasicEventListener in interface IBasicRobotnull if this robot should
not receive the notifications.public void run()
run in interface Runnablepublic final IPaintEvents getPaintEventListener()
IPaintRobotIPaintEvents listener.
getPaintEventListener in interface IPaintRobotnull if this robot should
not receive the notifications.public void onSkippedTurn(SkippedTurnEvent event)
onSkippedTurn in interface IAdvancedEventsevent - the skipped turn event set by the gameSkippedTurnEvent,
Eventpublic void onCustomEvent(CustomEvent event)
sample.Target
robot.
onCustomEvent in interface IAdvancedEventsevent - the custom event that occurredAdvancedRobot.addCustomEvent(robocode.Condition),
CustomEvent,
Eventpublic final IAdvancedEvents getAdvancedEventListener()
IAdvancedEvents listener.
getAdvancedEventListener in interface IAdvancedRobotnull if this robot should
not receive the notifications.public Mine placeMine(double power)
power - The power of the mine you want to placepublic void setMineComponentColor(Color color)
public File getDataDirectory()
RobocodeFileOutputStream or
RobocodeFileWriter.
The system will automatically create the directory for you, so you do not
need to create it by yourself.
getDataFile(String),
RobocodeFileOutputStream,
RobocodeFileWriterpublic File getDataFile(String filename)
RobocodeFileOutputStream or RobocodeFileWriter.
The system will automatically create the directory for you, so you do not
need to create it by yourself.
Please notice that the max. size of your data file is set to 200000
(~195 KB).
See the sample.SittingDuck to see an example of how to use this
method.
filename - the file name of the data file for your robot
getDataDirectory(),
RobocodeFileOutputStream,
RobocodeFileWriterpublic long getDataQuotaAvailable()
getDataDirectory(),
getDataFile(String)public void waitFor(Condition condition)
Condition.test() returns true.
This call executes immediately.
See the sample.Crazy robot for how this method can be used.
condition - the condition that must be met before this call returnsCondition,
Condition.test()public int getOthers()
public void stop()
resume(). If there is already movement saved from a previous
stop, this will have no effect.
This method is equivalent to #stop(false).
resume(),
stop(boolean)public void stop(boolean overwrite)
resume(). If there is already movement saved from a previous
stop, you can overwrite it by calling stop(true).
overwrite - If there is already movement saved from a previous stop,
you can overwrite it by calling stop(true).resume(),
stop()public void resume()
stop(), if any.
This call executes immediately, and does not return until it is complete.
stop(),
stop(boolean)public void setCourseRadians(double angle)
setCourseRadians in interface IShipangle - The angle in radians to which we want to set course. (0 = North, PI/2 = East, etc)
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||