Archived
1
0

-Overhauled Upgrade

-Created InsufficientFundsException
-Renamed other exceptions

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-16 10:32:59 -07:00
parent bfa517dc49
commit 651b6c2999
16 changed files with 146 additions and 81 deletions

View File

@ -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)

View File

@ -10,6 +10,6 @@ public class PoliceStation extends NeighborBuilding {
super(x, y, name, building, drone);
}
// Implement Police Station
// TODO - Implement Police Station
}

View File

@ -10,6 +10,6 @@ public class RepairShop extends NeighborBuilding {
super(x, y, name, building, drone);
}
// Implement Police Station
// TODO - Implement Repair Shop
}

View File

@ -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 <code>Point</code> 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();
}
}
}

View File

@ -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 <code>UpgradeType</code>
*/
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 <code>int</code>
*/
public int getPrice() {
double multiplier;
double currentLevel;
double originalLevel;
Hashtable<String, Double> 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 <code>boolean</code>
*/
public boolean isMaxLevel() {
// TODO - Implement max levels
return false;
Hashtable<String, Double> 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 <code>HashTable(string, double)</code>
*/
private Hashtable<String, Double> statInfo(UpgradeType type) {
Hashtable<String, Double> allInfo = new Hashtable<String, Double>();
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;
}
}

View File

@ -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();
}
}
}

View File

@ -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.");
}
}

View File

@ -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");
}
}