[英]How to solve the 'could not find or load main class robocode.robocode' error?
[英]Robocode Enemy class setDirection() calling
我正在编程Robocode,现在有一个编码问题:
我定义了“ Enemy
类来存储敌人的信息(例如航向,方位,速度等),并且在该类中,我还定义了一个名为“方向”的私有属性。 然后,我使用公共获取器和设置器允许我的机器人调用这些属性。 但是当我使用enemy.setDirection(e.getDirection());
,NetBean IDE将其显示为不正确。 有人可以帮助解决这个问题吗?
public class Enemy {
// ...
private double direction;
public double getDirection(ScannedRobotEvent e, AdvancedRobot me) {
direction = e.getBearing() + me.getHeading();
return direction;
}
public void setDirection(double direction) {
this.direction = direction;
}
}
然后在我的机器人课上:
public class myBot extends AdvancedRobot {
private Enemy enemy = new Enemy();
public onScannedRobot(ScannedRobotEvent e) {
enemy.setDirection(e.getDirection()); // Here is the problem
}
}
当你调用e.getDirection()
它是寻找该方法ScannedRobotEvent
。 但是,仅针对Enemy类声明了getDirection()
。
调用getDirection方法时,必须输入属性,因此在这种情况下,需要输入ScannedRobotEvent和AdvancedRobot字段。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.