简体   繁体   中英

Robocode Enemy class setDirection() calling

I'm programming Robocode and now I have a coding question:

I defined class Enemy to store enemy information (such as heading, bearing, velocity etc.) and in this class I also defined a private attribute named direction. Then I use the public getters and setters to allow my bot to call those properties. But when I use enemy.setDirection(e.getDirection()); , NetBean IDE shows it as incorrect. Could someone help solve this problem?

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;
    }
}

Then in my robot class:

public class myBot extends AdvancedRobot {
    private Enemy enemy = new Enemy();

    public onScannedRobot(ScannedRobotEvent e) {
        enemy.setDirection(e.getDirection()); // Here is the problem
    }
}

When you call e.getDirection() it is looking for that method in ScannedRobotEvent . But getDirection() has only been declared for the Enemy class.

调用getDirection方法时,必须输入属性,因此在这种情况下,需要输入ScannedRobotEvent和AdvancedRobot字段。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM