0

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
    }
}
Jason
  • 1,658
  • 3
  • 20
  • 51

2 Answers2

1

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

Shaunak D
  • 20,588
  • 10
  • 46
  • 79
0

When you call the getDirection method, you have to input the properties, so in this case, a ScannedRobotEvent and an AdvancedRobot field.

EDToaster
  • 3,160
  • 3
  • 16
  • 25