diff --git a/bin/net/grosinger/nomads/Nomads.class b/bin/net/grosinger/nomads/Nomads.class index c51a5ab..ac5b0c2 100644 Binary files a/bin/net/grosinger/nomads/Nomads.class and b/bin/net/grosinger/nomads/Nomads.class differ diff --git a/bin/net/grosinger/nomads/TownHall.class b/bin/net/grosinger/nomads/TownHall.class index a435812..64d8585 100644 Binary files a/bin/net/grosinger/nomads/TownHall.class and b/bin/net/grosinger/nomads/TownHall.class differ diff --git a/bin/net/grosinger/nomads/Upgrade$UpgradeType.class b/bin/net/grosinger/nomads/Upgrade$UpgradeType.class index 231cb0b..499a6a1 100644 Binary files a/bin/net/grosinger/nomads/Upgrade$UpgradeType.class and b/bin/net/grosinger/nomads/Upgrade$UpgradeType.class differ diff --git a/bin/net/grosinger/nomads/Upgrade.class b/bin/net/grosinger/nomads/Upgrade.class index dd0f341..06f202f 100644 Binary files a/bin/net/grosinger/nomads/Upgrade.class and b/bin/net/grosinger/nomads/Upgrade.class differ diff --git a/bin/net/grosinger/nomads/UpgradeShop.class b/bin/net/grosinger/nomads/UpgradeShop.class index 0826ec2..e6280a3 100644 Binary files a/bin/net/grosinger/nomads/UpgradeShop.class and b/bin/net/grosinger/nomads/UpgradeShop.class differ diff --git a/bin/net/grosinger/nomads/exceptions/InsufficientFundsException.class b/bin/net/grosinger/nomads/exceptions/InsufficientFundsException.class new file mode 100644 index 0000000..b96e85c Binary files /dev/null and b/bin/net/grosinger/nomads/exceptions/InsufficientFundsException.class differ diff --git a/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.class b/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.class deleted file mode 100644 index 3356bcc..0000000 Binary files a/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.class and /dev/null differ diff --git a/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.class b/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.class new file mode 100644 index 0000000..dfc0dc5 Binary files /dev/null and b/bin/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.class differ diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java index 380cb2d..91b2298 100644 --- a/src/net/grosinger/nomads/Nomads.java +++ b/src/net/grosinger/nomads/Nomads.java @@ -57,6 +57,9 @@ public class Nomads { public static final int BASE_SPEED = 1; public static final int BASE_CARGOSPACE = 3; public static final int BASE_THEFT = 1; + + public static final int MAXLEVEL_RADARS = 30; + public static final int MAXLEVEL_STATS = 10; public static void main(String[] args) { if (DEBUGSTATUS) diff --git a/src/net/grosinger/nomads/PoliceStation.java b/src/net/grosinger/nomads/PoliceStation.java index 17e9286..0bee961 100644 --- a/src/net/grosinger/nomads/PoliceStation.java +++ b/src/net/grosinger/nomads/PoliceStation.java @@ -10,6 +10,6 @@ public class PoliceStation extends NeighborBuilding { super(x, y, name, building, drone); } - // Implement Police Station + // TODO - Implement Police Station } diff --git a/src/net/grosinger/nomads/RepairShop.java b/src/net/grosinger/nomads/RepairShop.java index 1105354..46fd9cc 100644 --- a/src/net/grosinger/nomads/RepairShop.java +++ b/src/net/grosinger/nomads/RepairShop.java @@ -10,6 +10,6 @@ public class RepairShop extends NeighborBuilding { super(x, y, name, building, drone); } - // Implement Police Station + // TODO - Implement Repair Shop } diff --git a/src/net/grosinger/nomads/TownHall.java b/src/net/grosinger/nomads/TownHall.java index 1829c79..2e97d06 100644 --- a/src/net/grosinger/nomads/TownHall.java +++ b/src/net/grosinger/nomads/TownHall.java @@ -1,6 +1,6 @@ package net.grosinger.nomads; -import net.grosinger.nomads.exceptions.ObjectReferenceOutdated; +import net.grosinger.nomads.exceptions.ObjectReferenceOutdatedException; /** * A representation of a TownHall. Allows Drones to interact with this building. @@ -14,9 +14,9 @@ public class TownHall extends NeighborBuilding { /** * Will deposit all money piles and turn in all Objectives to Town Hall. * - * @throws ObjectReferenceOutdated + * @throws ObjectReferenceOutdatedException */ - public void cashInventory() throws ObjectReferenceOutdated { + public void cashInventory() throws ObjectReferenceOutdatedException { if (verifyObjectValidity()) { Inventory inventory = drone.getInventory(); DroneTeam team = drone.getTeam(); @@ -33,7 +33,7 @@ public class TownHall extends NeighborBuilding { inventory.remove(currentObject); } } else { - throw new ObjectReferenceOutdated(); + throw new ObjectReferenceOutdatedException(); } } @@ -43,13 +43,13 @@ public class TownHall extends NeighborBuilding { * @return Point Will return null if the NeighborBuilding was * created in a previous turn. * - * @throws ObjectReferenceOutdated + * @throws ObjectReferenceOutdatedException */ - public Point requestNewObjective() throws ObjectReferenceOutdated { + public Point requestNewObjective() throws ObjectReferenceOutdatedException { if (verifyObjectValidity()) { return Nomads.awesomeWorld.generateObjective(drone); } else { - throw new ObjectReferenceOutdated(); + throw new ObjectReferenceOutdatedException(); } } } diff --git a/src/net/grosinger/nomads/Upgrade.java b/src/net/grosinger/nomads/Upgrade.java index ded9b2c..2e5f487 100644 --- a/src/net/grosinger/nomads/Upgrade.java +++ b/src/net/grosinger/nomads/Upgrade.java @@ -1,5 +1,6 @@ package net.grosinger.nomads; +import java.util.Hashtable; public class Upgrade { @@ -21,6 +22,15 @@ public class Upgrade { typeToUpgrade = type; } + /** + * Retrieve the type of the upgrade that should be performed. + * + * @return UpgradeType + */ + public UpgradeType getUpgradeType() { + return typeToUpgrade; + } + /** * Provides the prices for a given update type Algorithm: (((Current Level - * Original Level) + 5) * Multiplier)^2 @@ -28,73 +38,13 @@ public class Upgrade { * @return int */ public int getPrice() { - double multiplier; - double currentLevel; - double originalLevel; + Hashtable allInfo = statInfo(typeToUpgrade); - switch (typeToUpgrade) { - case visibleDistance: { - multiplier = 2; - currentLevel = oldBrokenDrone.getVisibleDistance(); - originalLevel = Nomads.BASE_VISIBLEDISTANCE; - break; - } - case lumaLocatorDistance: { - multiplier = 2.5; - currentLevel = oldBrokenDrone.getLumaLocatorDistance(); - originalLevel = Nomads.BASE_LUMALOCATORDISTANCE; - break; - } - case objectLocatorDistance: { - multiplier = 2.5; - currentLevel = oldBrokenDrone.getObjectLocatorDistance(); - originalLevel = Nomads.BASE_OBJECTLOCATORDISTANCE; - break; - } - case reliability: { - multiplier = 2.4; - currentLevel = oldBrokenDrone.getReliability(); - originalLevel = Nomads.BASE_RELIABILITY; - break; - } - case attack: { - multiplier = 2.7; - currentLevel = oldBrokenDrone.getAttack(); - originalLevel = Nomads.BASE_ATTACK; - break; - } - case defenses: { - multiplier = 2.8; - currentLevel = oldBrokenDrone.getDefenses(); - originalLevel = Nomads.BASE_DEFENSES; - break; - } - case speed: { - multiplier = 3.5; - currentLevel = oldBrokenDrone.getSpeed(); - originalLevel = Nomads.BASE_SPEED; - break; - } - case cargoSpace: { - multiplier = 3.5; - currentLevel = oldBrokenDrone.getCargoSpace(); - originalLevel = Nomads.BASE_CARGOSPACE; - break; - } - case theft: { - multiplier = 4; - currentLevel = oldBrokenDrone.getTheft(); - originalLevel = Nomads.BASE_THEFT; - break; - } - default: { - // Must specify an Upgrade Type - return (Integer) null; - } - } + double multiplier = allInfo.get("multiplier"); + double currentLevel = allInfo.get("currentLevel"); + double originalLevel = allInfo.get("originalLevel"); - double price = Math.pow( - (currentLevel - originalLevel + 5) * multiplier, 2.0); + double price = Math.pow((currentLevel - originalLevel + 5) * multiplier, 2.0); return (int) Math.ceil(price); } @@ -105,11 +55,95 @@ public class Upgrade { * @return boolean */ public boolean isMaxLevel() { - // TODO - Implement max levels - return false; + Hashtable allInfo = statInfo(typeToUpgrade); + + double maxLevel = allInfo.get("maxLevel"); + double currentLevel = allInfo.get("currentLevel"); + + return maxLevel == currentLevel; } - public UpgradeType getUpgradeType() { - return typeToUpgrade; + /** + * Retrieve general information about a particular stat + * + * @param type + * The stat to generate information about + * @return HashTable(string, double) + */ + private Hashtable statInfo(UpgradeType type) { + Hashtable allInfo = new Hashtable(); + + switch (typeToUpgrade) { + case visibleDistance: { + allInfo.put("multiplier", (double) 2); + allInfo.put("currentLevel", (double) oldBrokenDrone.getVisibleDistance()); + allInfo.put("originalLevel", (double) Nomads.BASE_VISIBLEDISTANCE); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_RADARS); + break; + } + case lumaLocatorDistance: { + + allInfo.put("multiplier", (double) 2.5); + allInfo.put("currentLevel", (double) oldBrokenDrone.getLumaLocatorDistance()); + allInfo.put("originalLevel", (double) Nomads.BASE_LUMALOCATORDISTANCE); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_RADARS); + break; + } + case objectLocatorDistance: { + allInfo.put("multiplier", (double) 2.5); + allInfo.put("currentLevel", (double) oldBrokenDrone.getObjectLocatorDistance()); + allInfo.put("originalLevel", (double) Nomads.BASE_OBJECTLOCATORDISTANCE); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_RADARS); + break; + } + case reliability: { + allInfo.put("multiplier", (double) 2.4); + allInfo.put("currentLevel", (double) oldBrokenDrone.getReliability()); + allInfo.put("originalLevel", (double) Nomads.BASE_RELIABILITY); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + case attack: { + allInfo.put("multiplier", (double) 2.7); + allInfo.put("currentLevel", (double) oldBrokenDrone.getAttack()); + allInfo.put("originalLevel", (double) Nomads.BASE_ATTACK); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + case defenses: { + allInfo.put("multiplier", (double) 2.8); + allInfo.put("currentLevel", (double) oldBrokenDrone.getDefenses()); + allInfo.put("originalLevel", (double) Nomads.BASE_DEFENSES); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + case speed: { + allInfo.put("multiplier", (double) 3.5); + allInfo.put("currentLevel", (double) oldBrokenDrone.getSpeed()); + allInfo.put("originalLevel", (double) Nomads.BASE_SPEED); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + case cargoSpace: { + allInfo.put("multiplier", (double) 3.5); + allInfo.put("currentLevel", (double) oldBrokenDrone.getCargoSpace()); + allInfo.put("originalLevel", (double) Nomads.BASE_CARGOSPACE); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + case theft: { + allInfo.put("multiplier", (double) 4); + allInfo.put("currentLevel", (double) oldBrokenDrone.getTheft()); + allInfo.put("originalLevel", (double) Nomads.BASE_THEFT); + allInfo.put("maxLevel", (double) Nomads.MAXLEVEL_STATS); + break; + } + default: { + // Must specify an Upgrade Type + return null; + } + } + + return allInfo; } } diff --git a/src/net/grosinger/nomads/UpgradeShop.java b/src/net/grosinger/nomads/UpgradeShop.java index c036845..e81f568 100644 --- a/src/net/grosinger/nomads/UpgradeShop.java +++ b/src/net/grosinger/nomads/UpgradeShop.java @@ -1,5 +1,7 @@ package net.grosinger.nomads; +import net.grosinger.nomads.exceptions.InsufficientFundsException; + /** * A representation of an UpgradeShop. Allows Drones to interact with this * building. @@ -10,6 +12,24 @@ public class UpgradeShop extends NeighborBuilding { super(x, y, name, building, drone); } - // Implement Police Station + // TODO - Implement Upgrade Shop + + /** + * Performs an upgrade on the drone if it is possible. Must be passed an + * upgrade that is not already of max level, and that has enough funds to + * purchase. + * + * @param toPerform + * An Upgrade that should be performed + * @throws InsufficientFundsException + */ + public void performUpgrade(Upgrade toPerform) throws InsufficientFundsException { + int teamBalance = drone.getTeam().getBalance(); + int upgradeCost = toPerform.getPrice(); + + if (upgradeCost > teamBalance) { + throw new InsufficientFundsException(); + } + } } diff --git a/src/net/grosinger/nomads/exceptions/InsufficientFundsException.java b/src/net/grosinger/nomads/exceptions/InsufficientFundsException.java new file mode 100644 index 0000000..625abdb --- /dev/null +++ b/src/net/grosinger/nomads/exceptions/InsufficientFundsException.java @@ -0,0 +1,8 @@ +package net.grosinger.nomads.exceptions; + +public class InsufficientFundsException extends Exception { + + public InsufficientFundsException() { + super("The team you are a part of does not have the required funds for this action."); + } +} diff --git a/src/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.java b/src/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.java similarity index 53% rename from src/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.java rename to src/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.java index 10e60eb..63d079b 100644 --- a/src/net/grosinger/nomads/exceptions/ObjectReferenceOutdated.java +++ b/src/net/grosinger/nomads/exceptions/ObjectReferenceOutdatedException.java @@ -1,8 +1,8 @@ package net.grosinger.nomads.exceptions; -public class ObjectReferenceOutdated extends Exception { +public class ObjectReferenceOutdatedException extends Exception { - public ObjectReferenceOutdated() { + public ObjectReferenceOutdatedException() { super("This object was created in a previous turn and is no longer valid"); } }