当前位置:文档之家› robocode_API中文参考(java)

robocode_API中文参考(java)

robocode_API中文参考(java)
robocode_API中文参考(java)

robocode部分API中文参考

ahead 向前

public void ahead(double distance)

Immediately moves your robot ahead (forward) by distance measured in pixels.

马上将你的机器人向前移动以distance 指定的多少个像素

This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.

这个函数会马上执行,并且直到完成了任务才返回,比如,当距离已前进完时。

If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is

complete if you are heading toward the other robot.

当机器人撞到墙时,动作也是完成了,意味着此时机器人将不再向前进。当你的机器人撞到其它的机器人时,如果你是头部撞到其它的机器人时动作也就完成。

Note that both positive and negative values can be given as input, where negative values means that the robot is set to move backward instead of forward.

记住正数和负数都可以作为距离的值,当距离为负值时表示机器人向后退距离的绝对值个像素。

Example:

比如:

// Move the robot 100 pixels forward

将机器人向前移动100个像素

ahead(100);

// Afterwards, move the robot 50 pixels backward

然后,向后移动50个像素ahead(-50);

Parameters:

参数:

distance - the distance to move ahead measured in pixels. If this value is negative, the robot will move back instead of ahead

distanse-向前移动的距离,单位是像素。如果其值是负数,机器人会用向后来代替向前。

See Also:

可以参考:

back(double), onHitWall(HitWallEvent), onHitRobot(HitRobotEvent)

back 向后

public void back(double distance)

Immediately moves your robot backward by distance measured in pixels.

马上将你的机器人向后移动以distance 指定的多少个像素

This call executes immediately, and does not return until it is complete, i.e. when the remaining distance to move is 0.

这个函数会马上执行,并且直到完成了任务才返回,比如,当距离已前进完时。

If the robot collides with a wall, the move is complete, meaning that the robot will not move any further. If the robot collides with another robot, the move is

complete if you are heading toward the other robot.

当机器人撞到墙时,动作也是完成了,意味着此时机器人将不再向前进。当你的机器人撞到其它的机器人时,如果你是头部撞到其它的机器人时动作也就完成。

Note that both positive and negative values can be given as input, where negative values means that the robot is set to move forward instead of backward.

记住正数和负数都可以作为距离的值,当距离为负值时表示机器人向前进距离的绝对值个像素。

Example:

比如:

// Move the robot 100 pixels backward

将机器人向后移动100个像素

back(100);

// Afterwards, move the robot 50 pixels forward

然后,向前移动50个像素ahead(-50);

back(-50);

Parameters:

参数:

distance - the distance to move back measured in pixels. If this value is negative, the robot will move ahead instead of back.

distanse-向后移动的距离,单位是像素。如果其值是负数,机器人会用向前来代替向后。

See Also:

可以参考:

ahead(double), onHitWall(HitWallEvent), onHitRobot(HitRobotEvent)

getBattleFieldWidth 得到战场宽度

public double getBattleFieldWidth()

Returns the width of the current battlefield measured in pixels.

返回值为以像素为单位表示的当前战场的宽度

Returns:

the width of the current battlefield measured in pixels.

--------------------------------------------------------------------------------

getBattleFieldHeight 得到战场高度

public double getBattleFieldHeight()

Returns the height of the current battlefield measured in pixels.

返回值为能像素为单位的当前战场的高度

Returns:

the height of the current battlefield measured in pixels.

getHeading 得到自己的方向

public double getHeading()

Returns the direction that the robot's body is facing, in degrees. The value returned will be between 0 and 360 (is excluded).

返回机器人面对的方向,用角度表示。返回值的范围是0到360之间(不含360)。

Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180 means South, and 270 means West.

记住在机器人软件中的坐标系就像一个罗盘,0表示正北,90表示正东,180表示正南,270表示正西。

Returns:

the direction that the robot's body is facing, in degrees.

返回机器人面对的方向,用角度表示

See Also:

getGunHeading(), getRadarHeading()

getHeight

public double getHeight()

Returns the height of the robot measured in pixels.

返回机器人自己的高度,单位为像素。

Returns:

the height of the robot measured in pixels.

See Also:

getWidth()

--------------------------------------------------------------------------------

getWidth

public double getWidth()

Returns the width of the robot measured in pixels.

返回机器人自己的宽度,单位为像素。

Returns:

the width of the robot measured in pixels.

See Also:

getHeight()

getName 返回自己的名字

public String getName()

Returns the robot's name.

返回机器人自己的名字

Returns:

the robot's name.

--------------------------------------------------------------------------------

getX 得到X坐标

public double getX()

Returns the X position of the robot. (0,0) is at the bottom left of the battlefield.

返回值为机器人的X坐标,(0,0)坐标在战场的左下角。(译者注:向右为X正向,向上为Y正向)。

Returns:

the X position of the robot.

See Also:

getY()

--------------------------------------------------------------------------------

getY 得到Y坐标

public double getY()

Returns the Y position of the robot. (0,0) is at the bottom left of the battlefield.

返回值为机器人的Y坐标,(0,0)坐标在战场的左下角。(译者注:向右为X正向,向上为Y正向)。

Returns:

the Y position of the robot.

See Also:

getX()

run

public void run()

The main method in every robot. You must override this to set up your robot's basic behavior.

在每个机器人中的主方法。为了你的机器人有一些基本行为,你必须重写这个方法。Example:

例如:

// A basic robot that moves around in a square

一个在一个正方形里反复行走的基本的机器人

public void run() {

while (true) {

ahead(100);

turnRight(90);

}

}

Specified by:

run in interface Runnable

可以行走的时候才会行走。

--------------------------------------------------------------------------------

turnLeft

public void turnLeft(double degrees)

Immediately turns the robot's body to the left by degrees.

马上将机器人向左转以degrees 指写的度数

This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the robot's turn is 0.

这个指令马上被调用,直到做完才会返回。比如,当角度已经转完时就会返回。

Note that both positive and negative values can be given as input, where negative values means that the robot's body is set to turn right instead of left.

正数和负数都可以作为参数,是负数意味着会向右转,转动角度的大小是一样的。Example:

// Turn the robot 180 degrees to the left

将机器人向左转180度。

turnLeft(180);

// Afterwards, turn the robot 90 degrees to the right

然后,向右转90度。

turnLeft(-90);

Parameters:

degrees - the amount of degrees to turn the robot's body to the left. If degrees > 0 the robot will turn left. If degrees < 0 the robot will turn right. If

degrees = 0 the robot will not turn, but execute.

degrees- 机器人向左转动的角度的大小。如果degrees>0,那么机器人会向左转,如果degrees<0,那么机器人会像右转。如果degrees=0,那么机器人不会转动,但指令还是执行了

的。

See Also:

可参考:

turnRight(double), turnGunLeft(double), turnGunRight(double), turnRadarLeft(double), turnRadarRight(double)

--------------------------------------------------------------------------------

turnRight 向右转

public void turnRight(double degrees)

Immediately turns the robot's body to the right by degrees.

马上将机器人向右转以degrees 指写的度数

This call executes immediately, and does not return until it is complete, i.e. when the angle remaining in the robot's turn is 0.

这个指令马上被调用,直到做完才会返回。比如,当角度已经转完时就会返回。

Note that both positive and negative values can be given as input, where negative values means that the robot's body is set to turn left instead of right.

正数和负数都可以作为参数,是负数意味着会向左转,转动角度的大小是一样的。Example:

// Turn the robot 180 degrees to the right

将机器人向右转180度。

turnRight(180);

// Afterwards, turn the robot 90 degrees to the left

然后,向左转90度。

turnRight(-90);

Parameters:

degrees - the amount of degrees to turn the robot's body to the right. If degrees > 0 the robot will turn right. If degrees < 0 the robot will turn left. If

degrees = 0 the robot will not turn, but execute.

degrees- 机器人向右转动的角度的大小。如果degrees>0,那么机器人会向右转,如果degrees<0,那么机器人会像左转。如果degrees=0,那么机器人不会转动,但指令还是执行了

的。

See Also:

turnLeft(double), turnGunLeft(double), turnGunRight(double), turnRadarLeft(double), turnRadarRight(double)

--------------------------------------------------------------------------------

doNothing 什么都不做

public void doNothing()

Do nothing this turn, meaning that the robot will skip it's turn.

在这一轮中什么都不做,其实也就表示机器人将退出这一轮的比赛。

This call executes immediately, and does not return until the turn is over.

这个指令会马上执行,直到这轮比赛结束才返回。

finalize 最后的事情

protected final void finalize()

throws ThrowableCalled by the system to 'clean up' after your robot. You may not override this method.

抛出一个一个调用给系统,当你的机器人没了的时候,它会自动做一些清理工作。你不应该重写这个方法。

Overrides:

finalize in class Object

Throws:

Throwable

--------------------------------------------------------------------------------

fire 开火

public void fire(double power) power是开火时的能量,也即子弹的能量

Immediately fires a bullet. The bullet will travel in the direction the gun is pointing.

马上射出子弹。子弹会沿着枪口的方向前进。

The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.

指定的子弹力量会从你的机器人的能量里带走。因此,你设定的的子弹的能量越大,发射时会从你的机器人里带走的能量也越多。

The bullet will do (4 * power) damage if it hits another robot. If power is greater than 1, it will do

an additional 2 * (power - 1) damage. You will get (3 * power) back if you hit the other robot. You can call Rules.getBulletDamage(double) for getting the damage that a bullet with a specific bullet power will do.

当子弹击中其它机器人时,会使那个机器人的能量损害(4*power)。如果设定的能量值大于1,还会使对方增加2*(power-1)的损害。当你的机器人击中其它机器人时,你会获得(3*power)的收益。你可以调用Rules.getBulletDamage(double)来知道一个指定的子弹能量能造成对方多大的损害(译者:当然,应该是指击中了对方时)。

The specified bullet power should be between Rules.MIN_BULLET_POWER and Rules.MAX_BULLET_POWER.

指定的子弹能量应该在Rules.MIN_BULLET_POWER和Rules.MAX_BULLET_POWER两个值之间。

Note that the gun cannot fire if the gun is overheated, meaning that getGunHeat() returns a value > 0.

请注意,当枪太热了的时候它就不能射击,意味此时getGunHeat()返回值大于0。

A event is generated when the bullet hits a robot (BulletHitEvent), wall (BulletMissedEvent), or another bullet (BulletHitBulletEvent).

当子弹击中一个机器人,墙,或者另一粒子弹时,分别会产生BulletHitEvent事件,BulletMissedEvent事件,BulletHitBulletEvent事件。

Example:

例如:

// Fire a bullet with maximum power if the gun is ready

当枪已经准备好时(不过热)射出一个最大能量的子弹

if (getGunHeat() == 0) {

fire(Rules.MAX_BULLET_POWER);

}

Parameters:

power - the amount of energy given to the bullet, and subtracted from the robot's energy.

power- 射击时给子弹的能量,并会从机器人中减去这个能量。

See Also:

fireBullet(double), getGunHeat(), getGunCoolingRate(), onBulletHit(BulletHitEvent), onBulletHitBullet(BulletHitBulletEvent), onBulletMissed(BulletMissedEvent)

--------------------------------------------------------------------------------

fireBullet

public Bullet fireBullet(double power)

Immediately fires a bullet. The bullet will travel in the direction the gun is pointing.

马上射出子弹。子弹会沿着枪口的方向前进。

The specified bullet power is an amount of energy that will be taken from the robot's energy. Hence, the more power you want to spend on the bullet, the more energy is taken from your robot.

指定的子弹力量会从你的机器人的能量里带走。因此,你设定的的子弹的能量越大,发射时会从你的机器人里带走的能量也越多。

The bullet will do (4 * power) damage if it hits another robot. If power is greater than 1, it will do an additional 2 * (power - 1) damage. You will get (3 * power) back if you hit the other robot. You can call Rules.getBulletDamage(double) for getting the damage that a bullet with a specific bullet power will do.

当子弹击中其它机器人时,会使那个机器人的能量损害(4*power)。如果设定的能量值大于1,还会使对方增加2*(power-1)的损害。当你的机器人击中其它机器人时,你会获得(3*power)的收益。你可以调用Rules.getBulletDamage(double)来知道一个指定的子弹能量能造成对方多大的损害(译者:当然,应该是指击中了对方时)。

The specified bullet power should be between Rules.MIN_BULLET_POWER and Rules.MAX_BULLET_POWER.

指定的子弹能量应该在Rules.MIN_BULLET_POWER和Rules.MAX_BULLET_POWER两个值之间。

Note that the gun cannot fire if the gun is overheated, meaning that getGunHeat() returns a value > 0.

请注意,当枪太热了的时候它就不能射击,意味此时getGunHeat()返回值大于0。

A event is generated when the bullet hits a robot (BulletHitEvent), wall (BulletMissedEvent), or another bullet (BulletHitBulletEvent).

当子弹击中一个机器人,墙,或者另一粒子弹时,分别会产生BulletHitEvent事件,BulletMissedEvent事件,BulletHitBulletEvent事件。

Example:

// Fire a bullet with maximum power if the gun is ready

当枪已经准备好时(不过热)射出一个最大能量的子弹

if (getGunHeat() == 0) {

Bullet bullet = fireBullet(Rules.MAX_BULLET_POWER);

// Get the velocity of the bullet

得到子弹的速度

if (bullet != null) {

double bulletVelocity = bullet.getVelocity();

}

}

Parameters:

power - the amount of energy given to the bullet, and subtracted from the robot's energy. power- 射击时给子弹的能量,并会从机器人中减去这个能量。

Returns:

a Bullet that contains information about the bullet if it was actually fired, which can be used for tracking the bullet after it has been fired. If the bullet was not fired, null is returned.

返回值:一个存放了一些关于子弹的信息的Bullet类型(如果子弹真的射出去了),这个返回值可以用来在已经射出后跟踪子弹。如果子弹没能射出去,返回值会是null。

See Also:

可以参考:

fire(double), Bullet, getGunHeat(), getGunCoolingRate(), onBulletHit(BulletHitEvent), onBulletHitBullet(BulletHitBulletEvent), onBulletMissed(BulletMissedEvent)

--------------------------------------------------------------------------------

getGunCoolingRate

public double getGunCoolingRate()

Returns the rate at which the gun will cool down, i.e. the amount of heat the gun heat will drop per turn.

返回枪的冷却速度,也就是说,枪的热量会每一轮减少一些。

The gun cooling rate is default 0.1 / turn, but can be changed by the battle setup. So don't count on the cooling rate being 0.1!

枪的冷却速度默认是0.1每轮,但是可以被战斗时的安装设置改变。所以不要将冷却速率看作一定是0.1!

Returns:

the gun cooling rate

返回值:

枪的冷却速率

See Also:

getGunHeat(), fire(double), fireBullet(double)

--------------------------------------------------------------------------------

getGunHeading 得到枪的方向

public double getGunHeading()

Returns the direction that the robot's gun is facing, in degrees. The value returned will be between 0 and 360 (is excluded).

Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180

means South, and 270 means West.

返回机器人的枪的指向的方向,用角度表示。返回值在0到360(不含360)之间。

请注意在机器人编程中指向就像一个罗盘,在这里0表示正北,90表示正东,180表示正南,270表示正西。

Returns:

the direction that the robot's gun is facing, in degrees.

返回值:

机器人的枪指向的方向,会用角度表示。

See Also:

getHeading(), getRadarHeading()

--------------------------------------------------------------------------------

getGunHeat 得到枪的热度

public double getGunHeat()

Returns the current heat of the gun. The gun cannot fire unless this is 0. (Calls to fire will succeed, but will not actually fire unless getGunHeat() == 0).

返回枪现在的热量。只有这个值为0时你才能开火。(值不为0时调用开火的命令会成功,但直到getGunHeat() == 0即枪的热度为0时才会真正执行)。

The amount of gun heat generated when the gun is fired is 1 + (firePower / 5). Each turn the gun heat drops by the amount returned by getGunCoolingRate(), which is a battle setup.

当枪开火时产生的热量是1 + (firePower / 5)(译者:firePower即枪开火时的能量)。每一轮枪都会减少getGunCoolingRate()返回值的那么多热量,但那是一个战斗设置值。

Note that all guns are "hot" at the start of each round, where the gun heat is 3.

请注意,在每一轮开始时所有的枪都是热的,这时枪的热量为3。

Returns:

the current gun heat

返回:

现在枪的热量

See Also:

getGunCoolingRate(), fire(double), fireBullet(double)

--------------------------------------------------------------------------------

getNumRounds

public int getNumRounds()

Returns the number of rounds in the current battle.

返回当前在当前的战斗轮数。

Returns:

the number of rounds in the current battle

返回当前在当前的战斗轮数。

See Also:

getRoundNum()

--------------------------------------------------------------------------------

getOthers

public int getOthers()

Returns how many opponents that are left in the current round.

返回当前这一轮中还有多少个对手。

Returns:

how many opponents that are left in the current round.

返回值:当前这一轮中还有多少个对手

getRadarHeading 得到雷达的角度

public double getRadarHeading()

Returns the direction that the robot's radar is facing, in degrees. The value returned will be between 0 and 360 (is excluded).

Note that the heading in Robocode is like a compass, where 0 means North, 90 means East, 180 means South, and 270 means West.

得到雷达正对着的方向,用角度表示。返回值在0到360(不含360)之间。

请注意在机器人编程中指向就像一个罗盘,在这里0表示正北,90表示正东,180表示正南,270表示正西。

Returns:

the direction that the robot's radar is facing, in degrees.

返回值:

雷达正对着的方向,用角度表示

See Also:

getHeading(), getGunHeading()

--------------------------------------------------------------------------------

getRoundNum 得到当前轮数

public int getRoundNum()

Returns the current round number (0 to getNumRounds() - 1) of the battle.

返回当前回合是第几回合,值的范围是[0,to getNumRounds() - 1],闭区间。

Returns:

the current round number of the battle

返回值:

当前的回合数

See Also:

getNumRounds()

--------------------------------------------------------------------------------

getTime 得到时间

public long getTime()

Returns the game time of the current round, where the time is equal to the current turn in the round.

A battle consists of multiple rounds.

返回当前回合的时间,这个值和这个回合的turn值是一样的。

Time is reset to 0 at the beginning of every round.

在每一个回合时间被重新设置为0。

Returns:

the game time/turn of the current round.

返回值:

当前回合的时间。

--------------------------------------------------------------------------------

getVelocity 得到速度

public double getVelocity()

Returns the velocity of the robot measured in pixels/turn.

The maximum velocity of a robot is defined by Rules.MAX_VELOCITY (8 pixels / turn).

返回这个机器人的速度,以像素/一个时间单位为单位。(译者注:在robocode中,turn表示为一个单位,可以认是一声滴答的时间)。

Returns:

the velocity of the robot measured in pixels/turn.

返回值:

机器人的速度,以像素/单位时间为单位。

See Also:

Rules.MAX_VELOCITY

--------------------------------------------------------------------------------

onBulletHit 当击中对方时

public void onBulletHit(BulletHitEvent event)

This method is called when one of your bullets hits another robot. You should override it in your robot if you want to be informed of this event.

当你的子弹击中对方时就会调用这个方法。如果你想在子弹击中对方时作处理的话,你应当重写这个方法。

Example:

例如:

public void onBulletHit(BulletHitEvent event) {

out.println("I hit " + event.getName() + "!");

}

Specified by:

onBulletHit in interface IBasicEvents

这个方法的原始定义在IBasicEvents中

Parameters:

event - the bullet-hit event set by the game

参数:

event - the bullet-hit 游戏自己设置的(译者:这应当是默认的参数吧)

See Also:

BulletHitEvent, Event

--------------------------------------------------------------------------------

onBulletHitBullet 当子弹击中子弹时

public void onBulletHitBullet(BulletHitBulletEvent event)

This method is called when one of your bullets hits another bullet. You should override it in your robot if you want to be informed of this event.

当你的子弹击中别人的子弹时这个方法会被调用。如果你想在此时作一些处理,你应当重写这个方法。

Example:

例如:

public void onBulletHitBullet(BulletHitBulletEvent event) {

out.println("I hit a bullet fired by " + event.getBullet().getName() + "!");

}

Specified by:

onBulletHitBullet in interface IBasicEvents

原始定义在IBasicEvents中

Parameters:

event - the bullet-hit-bullet event set by the game

参数是游戏默认参数。

See Also:

BulletHitBulletEvent, Event

--------------------------------------------------------------------------------

onBulletMissed 当子弹迷路时

public void onBulletMissed(BulletMissedEvent event)

This method is called when one of your bullets misses, i.e. hits a wall. You should override it in your robot if you want to be informed of this event.

当你的子弹迷路时就会调用这个方法,也就是说,此时你的子弹打到墙了。如果你想在此时做一些处理,你应当重写这个方法。

Example:

public void onBulletHit(BulletMissedEvent event) {

out.println("Drat, I missed.");

}

Specified by:

onBulletMissed in interface IBasicEvents

Parameters:

event - the bullet-missed event set by the game

参数是游戏默认的参数。

See Also:

BulletMissedEvent, Event

--------------------------------------------------------------------------------

onDeath 当死了的时候

public void onDeath(DeathEvent event)

This method is called if your robot dies.

You should override it in your robot if you want to be informed of this event. Actions will have no effect if called from this section. The intent is to allow

you to perform calculations or print something out when the robot is killed.

当你的机器人被消灭时这个方法会被调用。

如果你想在此时做一些处理,你应当重写这个方法。在这个区域写的所有的动作都没有任何效果。这个函数的目的是允许你在机器人死的时候计算或是打印一些数据。

Specified by:

onDeath in interface IBasicEvents

Parameters:

event - the death event set by the game

参数是游戏默认的参数。

See Also:

DeathEvent, Event

onHitByBullet 当被击中时

public void onHitByBullet(HitByBulletEvent event)

This method is called when your robot is hit by a bullet. You should override it in your robot if you want to be informed of this event.

当你的机器人被子弹击中时这个方法会被调用。如果你想在此时做一些处理,你应当重写这个方法。

Example:

void onHitByBullet(HitByBulletEvent event) {

out.println(event.getRobotName() + " hit me!");

}

Specified by:

onHitByBullet in interface IBasicEvents

Parameters:

event - the hit-by-bullet event set by the game

参数是游戏的默认参数

See Also:

HitByBulletEvent, Event

--------------------------------------------------------------------------------

onHitRobot 当撞到别的机器人时

public void onHitRobot(HitRobotEvent event)

This method is called when your robot collides with another robot. You should override it in your robot if you want to be informed of this event.

当你的机器人撞到别的机器人时,这个方法就会被调用。如果你想在此时做一些处理,你应当重写这个方法。

Example:

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.

这个角度(译者:此处应指event.getBearing()返回的角度)和你的机器人的面向有关。所以若是0的话就是在你的正前方。

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.isMyFault()方法会返回false值。此时,你不会被游戏自动停止行走。但是如果你继续向这个机器人前进的话你就会撞到它(然后形成另一个事件)。如果你离开,你就不会撞到它了。

Specified by:

onHitRobot in interface IBasicEvents

Parameters:

event - the hit-robot event set by the game

游戏默认的参数。

See Also:

HitRobotEvent, Event

--------------------------------------------------------------------------------

onHitWall 当撞到墙时

public void onHitWall(HitWallEvent event)

This method is called when your robot collides with a wall. You should override it in your robot if you want to be informed of this event.

The wall at the top of the screen is 0 degrees, right is 90 degrees, bottom is 180 degrees, left is 270 degrees. But this event is relative to your heading, so: The bearing is such that turnRight (event.getBearing()) will point you perpendicular to the wall.

当你的机器人撞到墙时这个事件会发生。如果你想在些时做一些处理,你应当重写这个方法。在顶上的墙是0度,在右边的是90度,在左边的是270度,。当是这个事件也和你的面向有关,所以:turnRight (event.getBearing())调用会让你的机器人向墙垂直走。

Example:

void onHitWall(HitWallEvent event) {

out.println("Ouch, I hit a wall bearing " + event.getBearing() + " degrees.");

}

Specified by:

onHitWall in interface IBasicEvents

Parameters:

event - the hit-wall event set by the game

参数是游戏默认的参数。

See Also:

HitWallEvent, Event

--------------------------------------------------------------------------------

onRobotDeath 当其它机器人死时

public void onRobotDeath(RobotDeathEvent event)

This method is called when another robot dies. You should override it in your robot if you want to be informed of this event.

当其它机器人被消灭时这个方法会被调用。如果你想做一些处理的话你应当重写这个方法。

Specified by:

onRobotDeath in interface IBasicEvents

Parameters:

event - The robot-death event set by the game

这是游戏默认的参数。

See Also:

RobotDeathEvent, Event

--------------------------------------------------------------------------------

onScannedRobot 当发现有其它机器人时

public 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. You should override it in your robot if you want to be informed of this event. (Almost all robots should override this!)

This event is automatically called if there is a robot in range of your radar.

当你的机器人发现了其它机器人时这个方法会被调用,也就是此时你的雷达扫描到了其它的机器人。如果你想在些时做一些处理,你应当重写这个方法。

(几乎所有机器人都应当重写这个方法!)

当有机器人进入你的雷达的范围时这个方法会被自动调用。

Note that the robot's radar can only see robot within the range defined by Rules.RADAR_SCAN_RADIUS (1200 pixels).

请注意,机器人的雷达只能看到以Rules.RADAR_SCAN_RADIUS(1200像素)定义的范围。

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:

请注意:

The game assists Robots in firing, as follows:

在开火时会有游戏帮助,规则如下:

If the gun and radar are aligned (and were aligned last turn),

and the event is current,

and you call fire() before taking any other actions, fire() will fire directly at the robot.

In essence, this means that if you can see a robot, and it doesn't move, then fire will hit it.

如果枪和雷达是对齐的(并且上一时刻也是对齐的),

并且这个事件是同时发生的,

并且在你调用fire() 之前没有做其它任何动作,fire()会直接向那个机器人开火。

本质上说,这意味着如你扫描到了一个机器人,并且它不动,那么就会击中它。

AdvancedRobots will NOT be assisted in this manner, and are expected to examine the event to determine if 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).

高级机器人不会以这个方式被帮助,它们想去检查这个事件看fire()能否击中。(也就是说,你在旋转你的枪,但当你得到这个事件的消息时,你的枪与机器人偏离了5度)。

Specified by:

onScannedRobot in interface IBasicEvents

Parameters:

event - the scanned-robot event set by the game

参数是游戏默认的参数。

See Also:

ScannedRobotEvent, Event, Rules.RADAR_SCAN_RADIUS

onWin 当胜利时

public void onWin(WinEvent event)

This method is called if your robot wins a battle.

Your robot could perform a victory dance here! :-)

当你的机器人赢了战斗时这个方法会被调用,你的机器人能在这时跳一个支胜利之舞!

Specified by:

onWin in interface IBasicEvents

Parameters:

event - the win event set by the game

参数值是游戏设定的

See Also:

相关主题
文本预览
相关文档 最新文档