|
|||||||||
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 IRadarFunctions
angle
- The angle you want to turn the radar towards the left in degrees.public void setTurnRadarRightDegrees(double angle)
setTurnRadarRightDegrees
in interface IRadarFunctions
angle
- The angle you want to turn the radar towards the right in degrees.public void setTurnRadarLeftRadians(double angle)
setTurnRadarLeftRadians
in interface IRadarFunctions
angle
- The angle you want to turn the radar towards the left in radians.public void setTurnRadarRightRadians(double angle)
setTurnRadarRightRadians
in interface IRadarFunctions
angle
- The angle you want to turn the radar towards the right in radians.public double getRadarHeadingRadians()
getRadarHeadingRadians
in interface IRadarFunctions
public double getRadarHeadingDegrees()
getRadarHeadingDegrees
in interface IRadarFunctions
public double getRadarTurnRemainingRadians()
getRadarTurnRemainingRadians
in interface IRadarFunctions
public double getRadarTurnRemainingDegrees()
getRadarTurnRemainingDegrees
in interface IRadarFunctions
public void setTurnFrontCannonLeftDegrees(double angle)
setTurnFrontCannonLeftDegrees
in interface IFrontCannonFunctions
angle
- The angle in degrees you want to rotate your front cannon to the left.public void setTurnFrontCannonRightDegrees(double angle)
setTurnFrontCannonRightDegrees
in interface IFrontCannonFunctions
angle
- The angle in degrees you want to rotate your front cannon to the right.public void setTurnFrontCannonLeftRadians(double angle)
setTurnFrontCannonLeftRadians
in interface IFrontCannonFunctions
angle
- The angle in radians you want to rotate your front cannon to the left.public void setTurnFrontCannonRightRadians(double angle)
setTurnFrontCannonRightRadians
in interface IFrontCannonFunctions
angle
- The angle in radians you want to rotate your front cannon to the right.public double getFrontCannonHeadingRadians()
getFrontCannonHeadingRadians
in interface IFrontCannonFunctions
public double getFrontCannonHeadingDegrees()
getFrontCannonHeadingDegrees
in interface IFrontCannonFunctions
public BlindSpot getCopyOfBlindSpotFrontCannon()
getCopyOfBlindSpotFrontCannon
in interface IFrontCannonFunctions
Furthest you can move to the left
,
Furthest you can move to the right
,
Returns whether the destination is within the BlindSpot
public boolean getFrontCannonAtBlindSpot()
getFrontCannonAtBlindSpot
in interface IFrontCannonFunctions
public double getFrontCannonTurnRemainingRadians()
getFrontCannonTurnRemainingRadians
in interface IFrontCannonFunctions
public double getFrontCannonTurnRemainingDegrees()
getFrontCannonTurnRemainingDegrees
in interface IFrontCannonFunctions
public void setTurnBackCannonLeftDegrees(double angle)
setTurnBackCannonLeftDegrees
in interface IBackCannonFunctions
angle
- The angle in degrees you want to rotate your back cannon to the left.public void setTurnBackCannonRightDegrees(double angle)
setTurnBackCannonRightDegrees
in interface IBackCannonFunctions
angle
- The angle in degrees you want to rotate your back cannon to the right.public void setTurnBackCannonLeftRadians(double angle)
setTurnBackCannonLeftRadians
in interface IBackCannonFunctions
angle
- The angle in radians you want to rotate your back cannon to the left.public void setTurnBackCannonRightRadians(double angle)
setTurnBackCannonRightRadians
in interface IBackCannonFunctions
angle
- The angle in radians you want to rotate your back cannon to the right.public double getBackCannonHeadingRadians()
getBackCannonHeadingRadians
in interface IBackCannonFunctions
public double getBackCannonHeadingDegrees()
getBackCannonHeadingDegrees
in interface IBackCannonFunctions
public BlindSpot getCopyOfBlindSpotBackCannon()
getCopyOfBlindSpotBackCannon
in interface IBackCannonFunctions
Furthest you can move to the left
,
Furthest you can move to the right
,
Returns whether the destination is within the BlindSpot
public boolean getBackCannonAtBlindSpot()
getBackCannonAtBlindSpot
in interface IBackCannonFunctions
public double getBackCannonTurnRemainingRadians()
getBackCannonTurnRemainingRadians
in interface IBackCannonFunctions
public double getBackCannonTurnRemainingDegrees()
getBackCannonTurnRemainingDegrees
in interface IBackCannonFunctions
public void fireFrontCannon(double power)
fireFrontCannon
in interface IFrontCannonFunctions
power
- 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 IBackCannonFunctions
power
- 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 IShip
angle
- The angle in degrees to which we want to set course. (0 = North, 90 = East, etc)public void setBodyColor(Color color)
setBodyColor
in interface IShip
color
- The color you wish your ship to bepublic void setFrontCannonColor(Color color)
setFrontCannonColor
in interface IFrontCannonFunctions
color
- The color you want your front cannon to be.public void setRadarColor(Color color)
setRadarColor
in interface IRadarFunctions
color
- The color you want your radar to be.public void setBackCannonColor(Color color)
setBackCannonColor
in interface IBackCannonFunctions
color
- 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 IBackCannonFunctions
color
- The Color you want the Bullets the Back Cannon shoots to be.public void setBulletColorFront(Color color)
setBulletColorFront
in interface IFrontCannonFunctions
color
- The Color you want the Bullets the Front Cannon shoots to be.public void setScanColor(Color color)
setScanColor
in interface IRadarFunctions
color
- The color you want your scan to be.public void setTurnLeftRadians(double radians)
setTurnLeftRadians
in interface IShip
radians
- The angle in radians we want to rotate to the left.public void setTurnRightRadians(double radians)
setTurnRightRadians
in interface IShip
radians
- The angle in radians we want to rotate to the right.public void setTurnLeftDegrees(double angle)
setTurnLeftDegrees
in interface IShip
angle
- The angle in degrees we want to rotate to the left.public void setTurnRightDegrees(double angle)
setTurnRightDegrees
in interface IShip
angle
- The angle in degrees we want to rotate to the right.public void setAdjustComponentForShipTurn(int index, boolean independent)
setAdjustComponentForShipTurn
in interface IShip
index
- The index of the componentindependent
- True for independent movement. False of dependent movement.public void setMaxKnots(double maxKnots)
setMaxKnots
in interface IShip
public double getFirePower(int index)
index
-
public void scan()
scan
in interface IShip
public void execute()
IShip.setAhead(double)
,
IShip.setTurnLeftDegrees(double)
etc. Otherwise,
these calls will never get executed.
execute
in interface IShip
public void onBattleEnded(BattleEndedEvent event)
public void onBattleEnded(BattleEndedEvent event) { out.println("The battle has ended"); }
onBattleEnded
in interface IBasicEvents2
event
- the BattleEndedEvent set by the gameBattleEndedEvent
,
IBasicEvents3.onRoundEnded(RoundEndedEvent)
,
WinEvent
,
DeathEvent
,
Event
public void onBulletHit(BulletHitEvent event)
public void onBulletHit(BulletHitEvent event) { out.println("I hit " + event.getName() + "!"); }
onBulletHit
in interface IBasicEvents
event
- the bullet-hit event set by the gameBulletHitEvent
,
Event
public void onBulletHitBullet(BulletHitBulletEvent event)
public void onBulletHitBullet(BulletHitBulletEvent event) { out.println("I hit a bullet fired by " + event.getBullet().getName() + "!"); }
onBulletHitBullet
in interface IBasicEvents
event
- the bullet-hit-bullet event set by the gameBulletHitBulletEvent
,
Event
public void onBulletMissed(BulletMissedEvent event)
public void onBulletMissed(BulletMissedEvent event) { out.println("Drat, I missed."); }
onBulletMissed
in interface IBasicEvents
event
- the bullet-missed event set by the gameBulletMissedEvent
,
Event
public void onDeath(DeathEvent event)
onDeath
in interface IBasicEvents
event
- the death event set by the gameDeathEvent
,
WinEvent
,
RoundEndedEvent
,
BattleEndedEvent
,
Event
public void onHitByBullet(HitByBulletEvent event)
void onHitByBullet(HitByBulletEvent event) { out.println(event.getRobotName() + " hit me!"); }
onHitByBullet
in interface IBasicEvents
event
- the hit-by-bullet event set by the gameHitByBulletEvent
,
Event
public 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 IBasicEvents
event
- the hit-robot event set by the gameHitRobotEvent
,
Event
public 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 IBasicEvents
event
- the hit-wall event set by the gameHitWallEvent
,
Event
public void onPaint(Graphics2D g)
onPaint
in interface IPaintEvents
g
- the graphics context to use for painting graphical items for the
robot.Graphics2D
public void onRobotDeath(RobotDeathEvent event)
onRobotDeath
in interface IBasicEvents
event
- The robot-death event set by the gameRobotDeathEvent
,
Event
public void onRoundEnded(RoundEndedEvent event)
public void onRoundEnded(RoundEndedEvent event) { out.println("The round has ended"); }
onRoundEnded
in interface IBasicEvents3
event
- the RoundEndedEvent event set by the gameRoundEndedEvent
,
IBasicEvents2.onBattleEnded(BattleEndedEvent)
,
WinEvent
,
DeathEvent
,
Event
public 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 IBasicEvents4
event
- the scanned-robot event set by the gameIBasicEvents.onScannedRobot(ScannedRobotEvent)
,
ScannedRobotEvent
,
Event
,
Rules.RADAR_SCAN_RADIUS
public 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 IBasicEvents
event
- the event containing the robot status at the time it occurred.StatusEvent
,
Event
public void onWin(WinEvent event)
onWin
in interface IBasicEvents
event
- the win event set by the gameDeathEvent
,
RoundEndedEvent
,
BattleEndedEvent
,
Event
public void onMineHitMine(MineHitMineEvent event)
onMineHitMine
in interface IBasicEvents4
event
- 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 IBasicEvents4
event
- 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 IBasicEvents4
event
- Contains the Mine that hit you, not much else.public void onScannedRobot(ScannedRobotEvent event)
onScannedShip(ScannedShipEvent event)
instead.
IBasicEvents
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).
onScannedRobot
in interface IBasicEvents
event
- the scanned-robot event set by the gameScannedRobotEvent
,
Event
,
Rules.RADAR_SCAN_RADIUS
public double getVelocity()
getVelocity
in interface IShip
public void setAhead(double distance)
// Move the robot 100 pixels forward ahead(100); // Afterwards, move the robot 50 pixels backward ahead(-50);
setAhead
in interface IShip
distance
- 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 IShip
distance
- The distance you want to move backwards in pixels.public double getDistanceRemaining()
getDistanceRemaining
in interface IShip
public double getBodyHeadingRadians()
getBodyHeadingRadians
in interface IShip
public double getBodyHeadingDegrees()
getBodyHeadingDegrees
in interface IShip
public double getGunHeatComponent(int index)
getGunHeatComponent
in interface IShip
index
- The index of the component you want to know the gunHeat of.
public double getComponentHeadingDegrees(int index)
getComponentHeadingDegrees
in interface IShip
index
- The index of the component you want to know the heading of.
public double getComponentHeadingRadians(int index)
getComponentHeadingRadians
in interface IShip
index
- The index of the component you want to know the heading of.
public double getX()
getX
in interface IShip
IShip.getY()
,
IShip.getXMiddle()
public double getXMiddle()
getXMiddle
in interface IShip
IShip.getX()
public double getXFrontCannon()
IFrontCannonFunctions
getXFrontCannon
in interface IFrontCannonFunctions
public double getXBackCannon()
IBackCannonFunctions
getXBackCannon
in interface IBackCannonFunctions
public double getXRadar()
IRadarFunctions
getXRadar
in interface IRadarFunctions
public double getY()
getY
in interface IShip
IShip.getX()
,
IShip.getYMiddle()
public double getYMiddle()
getYMiddle
in interface IShip
IShip.getY()
public double getYFrontCannon()
IFrontCannonFunctions
getYFrontCannon
in interface IFrontCannonFunctions
public double getYBackCannon()
IBackCannonFunctions
getYBackCannon
in interface IBackCannonFunctions
public double getYRadar()
IRadarFunctions
getYRadar
in interface IRadarFunctions
public double getBattleFieldWidth()
getBattleFieldWidth
in interface IShip
public double getBattleFieldHeight()
getBattleFieldHeight
in interface IShip
public double getBodyTurnRemainingDegrees()
getBodyTurnRemainingDegrees
in interface IShip
getTurnRemainingRadians()
,
getDistanceRemaining()
,
getGunTurnRemaining()
,
getGunTurnRemainingRadians()
,
getRadarTurnRemaining()
,
getRadarTurnRemainingRadians()
public double getBodyTurnRemainingRadians()
getBodyTurnRemainingRadians
in interface IShip
public long getTime()
getTime
in interface IShip
public double getEnergy()
getEnergy
in interface IShip
public 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:
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).WinEvent
: 100 (reserved)SkippedTurnEvent
: 100 (reserved)StatusEvent
: 99CustomEvent
: 80MessageEvent
: 75RobotDeathEvent
: 70BulletMissedEvent
: 60BulletHitBulletEvent
: 55BulletHitEvent
: 50HitByBulletEvent
: 40HitWallEvent
: 30HitRobotEvent
: 20ScannedRobotEvent
: 10PaintEvent
: 5DeathEvent
: -1 (reserved)
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 IBasicRobot
Runnable.run()
public IBasicEvents getBasicEventListener()
IBasicEvents
listener.
getBasicEventListener
in interface IBasicRobot
null
if this robot should
not receive the notifications.public void run()
run
in interface Runnable
public final IPaintEvents getPaintEventListener()
IPaintRobot
IPaintEvents
listener.
getPaintEventListener
in interface IPaintRobot
null
if this robot should
not receive the notifications.public void onSkippedTurn(SkippedTurnEvent event)
onSkippedTurn
in interface IAdvancedEvents
event
- the skipped turn event set by the gameSkippedTurnEvent
,
Event
public void onCustomEvent(CustomEvent event)
sample.Target
robot.
onCustomEvent
in interface IAdvancedEvents
event
- the custom event that occurredAdvancedRobot.addCustomEvent(robocode.Condition)
,
CustomEvent
,
Event
public final IAdvancedEvents getAdvancedEventListener()
IAdvancedEvents
listener.
getAdvancedEventListener
in interface IAdvancedRobot
null
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
,
RobocodeFileWriter
public 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
,
RobocodeFileWriter
public 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 IShip
angle
- 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 |