java robot api_java机器人API学习笔记

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 not

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值