-Created and implemented ObjectReferenceOutdated Exception
Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
parent
b2bd321784
commit
efdf505f3e
Binary file not shown.
Binary file not shown.
@ -1,24 +1,22 @@
|
|||||||
package net.grosinger.nomads;
|
package net.grosinger.nomads;
|
||||||
|
|
||||||
|
import net.grosinger.nomads.exceptions.ObjectReferenceOutdated;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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, DroneListItem drone) {
|
public TownHall(int x, int y, String name, Building building, DroneListItem drone) {
|
||||||
super(x, y, name, building, drone);
|
super(x, y, name, building, drone);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Will sell all items in inventory that are able to be sold to the Town
|
* Will deposit all money piles and turn in all Objectives to Town Hall.
|
||||||
* Hall.
|
|
||||||
*
|
*
|
||||||
* @param inventory
|
* @throws ObjectReferenceOutdated
|
||||||
* @param team
|
|
||||||
*/
|
*/
|
||||||
public void cashInventory() {
|
public void cashInventory() throws ObjectReferenceOutdated {
|
||||||
if (verifyObjectValidity()) {
|
if (verifyObjectValidity()) {
|
||||||
Inventory inventory = drone.getInventory();
|
Inventory inventory = drone.getInventory();
|
||||||
DroneTeam team = drone.getTeam();
|
DroneTeam team = drone.getTeam();
|
||||||
@ -35,7 +33,7 @@ public class TownHall extends NeighborBuilding {
|
|||||||
inventory.remove(currentObject);
|
inventory.remove(currentObject);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Object not valid, do Nothing
|
throw new ObjectReferenceOutdated();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,13 +42,14 @@ public class TownHall extends NeighborBuilding {
|
|||||||
*
|
*
|
||||||
* @return <code>Point</code> Will return null if the NeighborBuilding was
|
* @return <code>Point</code> Will return null if the NeighborBuilding was
|
||||||
* created in a previous turn.
|
* created in a previous turn.
|
||||||
|
*
|
||||||
|
* @throws ObjectReferenceOutdated
|
||||||
*/
|
*/
|
||||||
public Point requestNewObjective() {
|
public Point requestNewObjective() throws ObjectReferenceOutdated {
|
||||||
if (verifyObjectValidity()) {
|
if (verifyObjectValidity()) {
|
||||||
return Nomads.awesomeWorld.generateObjective(drone);
|
return Nomads.awesomeWorld.generateObjective(drone);
|
||||||
} else {
|
} else {
|
||||||
// Object not valid, do nothing
|
throw new ObjectReferenceOutdated();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
package net.grosinger.nomads.exceptions;
|
||||||
|
|
||||||
|
public class ObjectReferenceOutdated extends Exception {
|
||||||
|
|
||||||
|
public ObjectReferenceOutdated() {
|
||||||
|
super("This object was created in a previous turn and is no longer valid");
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user