![](/img/trans.png)
[英]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.