Archived
1
0

Created method for finding nearby buildings with in a drone's sight range

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-12 15:54:45 -07:00
parent ff8cbae761
commit fda0029f82
4 changed files with 32 additions and 18 deletions

View File

@ -131,20 +131,46 @@ public class DroneTools {
*/
public Point getTownCenter() {
if (townCenter == null) {
townCenter = new Point(30, 50);
townCenter = new Point(40, 50);
}
return townCenter;
}
public ArrayList<Building> checkBuildings() {
return worldReference.buildingsInRange(getX(), getY(), listItem.getVisibleDistance());
/**
* Retrieve a list of all Buildings that are visible within your sight
* range. (Sight range can be upgraded)
*
* @return <code>ArrayList</code> of NeigborBuildings
*/
public ArrayList<NeighborBuilding> checkBuildings() {
ArrayList<NeighborBuilding> neighbors = new ArrayList<NeighborBuilding>();
int maxDistance = listItem.getVisibleDistance();
for (int i = maxDistance * -1; i <= maxDistance; i++) {
for (int j = maxDistance * -1; j <= maxDistance; j++) {
if (getX() + i >= worldSize - 1 || getX() + i < 0
|| getY() + j >= worldSize - 1 || getY() + j < 0) {
} else if (i != 0 && j != 0) {
GameObject objectHere = worldReference.getObjectAt(getX()
+ i, getY() + j);
if (objectHere instanceof Building) {
Building buildingHere = (Building) objectHere;
NeighborBuilding aWildNeighbor = new NeighborBuilding(
buildingHere.getX(), buildingHere.getY(),
buildingHere.getName(), buildingHere);
neighbors.add(aWildNeighbor);
}
}
}
}
return neighbors;
}
/**
* Retrieve a list of all Drones that are visible within your sight range.
* (Sight range can be upgraded)
*
* @return ArrayList of Neighbors
* @return ArrayList of Neighbor Drones
*/
public ArrayList<NeighborDrone> checkRadar() {
ArrayList<NeighborDrone> neighbors = new ArrayList<NeighborDrone>();

View File

@ -11,7 +11,6 @@ public class NeighborBuilding implements GameObject {
private String name;
private int x;
private int y;
private String UID;
private Building building;
/**
@ -24,12 +23,10 @@ public class NeighborBuilding implements GameObject {
* @param name
* - Name of the Building
*/
public NeighborBuilding(int x, int y, String name, String UID,
Building building) {
public NeighborBuilding(int x, int y, String name, Building building) {
this.x = x;
this.y = y;
this.name = name;
this.UID = UID;
this.building = building;
}
@ -65,15 +62,6 @@ public class NeighborBuilding implements GameObject {
return building.getType();
}
/**
* Retrieve UID of this Neighbor
*
* @return <code>String</code> - UID
*/
public String getUID() {
return UID;
}
@Override
public void setName(String newName) {
name = newName;