-Added method of verifiying if a NeighborBuilding was created during the current turn.
NeighborBuildings should only be used during the current turn. References to them that are used later will not function. Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
parent
500396b422
commit
77c93d6c2c
Binary file not shown.
Binary file not shown.
@ -1,6 +1,5 @@
|
|||||||
package net.grosinger.nomads;
|
package net.grosinger.nomads;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An array of NeigborBuildings will be given to a drone that is searching for
|
* An array of NeigborBuildings will be given to a drone that is searching for
|
||||||
* the buildings it is near. This is typically done from the town center.
|
* the buildings it is near. This is typically done from the town center.
|
||||||
@ -8,6 +7,7 @@ package net.grosinger.nomads;
|
|||||||
public class NeighborBuilding implements GameObject {
|
public class NeighborBuilding implements GameObject {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
private int turnCreated;
|
||||||
private int x;
|
private int x;
|
||||||
private int y;
|
private int y;
|
||||||
private Building building;
|
private Building building;
|
||||||
@ -27,6 +27,7 @@ public class NeighborBuilding implements GameObject {
|
|||||||
this.y = y;
|
this.y = y;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.building = building;
|
this.building = building;
|
||||||
|
turnCreated = Nomads.turn;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -67,4 +68,15 @@ public class NeighborBuilding implements GameObject {
|
|||||||
name = newName;
|
name = newName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks to make sure the object was created this turn. Otherwise drones
|
||||||
|
* could save a reference to the object and use it from anywhere on the map.
|
||||||
|
*
|
||||||
|
* @return <code>boolean</code>
|
||||||
|
*/
|
||||||
|
protected boolean verifyObjectValidity() {
|
||||||
|
int currentTurn = Nomads.turn;
|
||||||
|
return currentTurn == turnCreated;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,16 +2,24 @@ package net.grosinger.nomads;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of a TownHall. Allows Drones to interact with this building.
|
* A representation of a TownHall. Allows Drones to interact with this building.
|
||||||
*/
|
*/
|
||||||
public class TownHall extends NeighborBuilding {
|
public class TownHall extends NeighborBuilding {
|
||||||
|
|
||||||
|
// TODO - Rewrite class to make more accessible to Drones
|
||||||
|
|
||||||
public TownHall(int x, int y, String name, Building building) {
|
public TownHall(int x, int y, String name, Building building) {
|
||||||
super(x, y, name, building);
|
super(x, y, name, building);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will sell all items in inventory that are able to be sold to the Town
|
||||||
|
* Hall.
|
||||||
|
*
|
||||||
|
* @param inventory
|
||||||
|
* @param team
|
||||||
|
*/
|
||||||
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) {
|
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) {
|
||||||
while (!inventory.isEmpty()) {
|
while (!inventory.isEmpty()) {
|
||||||
GameObject currentObject = inventory.get(0);
|
GameObject currentObject = inventory.get(0);
|
||||||
@ -26,7 +34,19 @@ public class TownHall extends NeighborBuilding {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Will generate a new objective for the drone that requests it.
|
||||||
|
*
|
||||||
|
* @param UID
|
||||||
|
* Depreciated and going away soon.
|
||||||
|
* @return <code>Point</code> Will return null if the NeighborBuilding was
|
||||||
|
* created in a previous turn.
|
||||||
|
*/
|
||||||
public Point requestNewObjective(String UID) {
|
public Point requestNewObjective(String UID) {
|
||||||
return Nomads.awesomeWorld.generateObjective(UID);
|
if (verifyObjectValidity()) {
|
||||||
|
return Nomads.awesomeWorld.generateObjective(UID);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user