Re: Importing Custom Classes
Mike Oliver <[email protected]> Wed, 22 Jul 2015 00:34:37 -0700 (PDT)
| Newsgroups | gmane.comp.java.robocode |
|---|---|
| Message-ID | <[email protected]> |
Ok, I did more research into properly setting up my Java files and looked
into constructors as Johannes suggested but I'm still missing something. I
still cant seem to access my BotData information inside my EnemyData class.
I have a sneaky suspicion that its because I'm overloading my
constructors. Maybe that's the issue?
Also I apologize for what I can assume is very newbish Java questions,
opposed to actual Robocode stuff, its just easier to bounce ideas off you
guys since you have likely dealt with this before.
Thanks again for all your help. Eventually I will get this =D
PewPew.java
package mo;
import java.awt.Graphics2D;
import mo.Data.*;
import mo.Utils.*;
import robocode.*;
public class PewPew extends AdvancedRobot {
BotData myBot;
EnemyData enemy = new EnemyData();
RadarData radar = new RadarData();
PaintUtils paint = new PaintUtils();
public void run() {
myBot = new BotData(this);
while (true) {
//System.out.println("PewPew: " + myBot.getPos());
setTurnRadarRightRadians(radar.getRadarDir() * Double.POSITIVE_INFINITY);
scan();
}
}
public void onScannedRobot(ScannedRobotEvent e) {
//myBot.update();
enemy.update(e);
// radar.update(e);
}
public void onRobotDeath(RobotDeathEvent e) {
enemy.update(e);
}
public void onPaint(Graphics2D g) {
/*
if (enemy.getPos() != null) {
paint.drawPos(g, enemy.getPos());
}
*/
}
}
BotData.java
package mo.Data;
import robocode.*;
import java.awt.geom.Point2D;
public class BotData{
//VARIABLES
private AdvancedRobot myBot;
private Point2D.Double myPos;
private double headingRadians;
private double radarHeadingRadians;
private int getOthers;
// CONSTRUCTORS
public BotData() {
}
public BotData(AdvancedRobot robot) {
myBot = robot;
myPos = new Point2D.Double(myBot.getX(), myBot.getY());
headingRadians = myBot.getHeadingRadians();
radarHeadingRadians = myBot.getRadarHeadingRadians();
getOthers = myBot.getOthers();
}
// ACCESSORS
public Point2D.Double getPos() {
return this.myPos;
}
public double getHeadingRadians() {
return this.headingRadians;
}
public double getRadarHeadingRadians() {
return this.radarHeadingRadians;
}
public int getOthers() {
return this.getOthers;
}
// METHODS
/*
public void update() {
myPos = new Point2D.Double(myBot.getX(), myBot.getY());
headingRadians = myBot.getHeadingRadians();
radarHeadingRadians = myBot.getRadarHeadingRadians();
getOthers = myBot.getOthers();
}
*/
}
EnemyData.java
package mo.Data;
import robocode.*;
import java.awt.geom.Point2D;
import java.util.HashMap;
import java.util.LinkedHashMap;
import mo.Utils.*;
public class EnemyData {
// VARIABLES
BotData myBot = new BotData();
BotUtils utils = new BotUtils();
private String eName;
private double eAbsBearing;
private double eBearing;
private double eDistance;
private double eVelocity;
private Point2D.Double ePos;
private LinkedHashMap<String, HashMap<String, Object>> eMap = new
LinkedHashMap<String, HashMap<String, Object>>(5, 2, true);
// ACCESSORS
public String getName() {
return this.eName;
}
public double getAbsBearing() {
return this.eAbsBearing;
}
public double getBearing() {
return this.eBearing;
}
public double getVelocity() {
return this.eVelocity;
}
public Point2D.Double getPos() {
return this.ePos;
}
public LinkedHashMap<String, HashMap<String, Object>> getMap() {
return this.eMap;
}
// METHODS
public void update(ScannedRobotEvent e) {
/*
eName = e.getName();
eDistance = e.getDistance();
eVelocity = e.getVelocity();
eBearing = e.getBearingRadians();
eAbsBearing = myBot.getHeadingRadians() + e.getBearingRadians();
ePos = utils.getPos(myBot.getPos(), eAbsBearing, eDistance);
// Add enemy information to Map
eMap.put(eName, new HashMap<String, Object>());
eMap.get(eName).put("eVelocity", eVelocity);
eMap.get(eName).put("eAbsBearing", eAbsBearing);
eMap.get(eName).put("eBearing", eBearing);
eMap.get(eName).put("ePos", ePos);
*/
System.out.println("EnemyData: " + myBot.getPos());
}
public void update(RobotDeathEvent e) {
eMap.remove(e.getName());
}
}
--
You received this message because you are subscribed to the Google Groups "robocode" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
For more options, visit https://groups.google.com/d/optout.