Archived
1
0

-Implemented most of creating a new drone

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-04-26 13:47:41 -07:00
parent 4f7140b45a
commit bb5ab7a7aa
9 changed files with 77 additions and 10 deletions

View File

@ -162,7 +162,7 @@ public class DroneListItem {
} }
/** /**
* Retrieve the level of this drone in theiving * Retrieve the level of this drone in thieving
* *
* @return <code>int</code> * @return <code>int</code>
*/ */

View File

@ -225,4 +225,38 @@ public class DroneTeam {
current = current.getNext(); current = current.getNext();
} }
} }
/**
* Removes money from the balance
*
* @param price
* - Amount to remove
*/
public void deductFromBalance(int price) {
currentBalance -= price;
}
/**
* Creates a new drone on the same team next to the creator
*
* @param listItem
* - Drone that issued the request
*/
public void createNewDrone(DroneListItem listItem) {
Class<? extends Drone> c = listItem.getCurrent().getClass();
Drone newDrone = null;
try {
newDrone = (Drone) c.newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
}
newDrone.setName(getName());
newDrone.setUID(InitializeGame.generateUID());
DroneListItem newListItem = new DroneListItem(null, last, newDrone, this);
addToEnd(newListItem);
}
} }

View File

@ -12,6 +12,7 @@ public class DroneTools {
private Drone referredDrone; private Drone referredDrone;
private DroneListItem listItem; private DroneListItem listItem;
private DroneTeam currentTeam;
private World worldReference; private World worldReference;
private int worldSize; private int worldSize;
@ -20,6 +21,7 @@ public class DroneTools {
listItem = droneParent; listItem = droneParent;
worldReference = theWorld; worldReference = theWorld;
worldSize = worldReference.getWorldSize(); worldSize = worldReference.getWorldSize();
currentTeam = listItem.getTeam();
} }
/** /**
@ -144,20 +146,46 @@ public class DroneTools {
* if it can not create the house. * if it can not create the house.
*/ */
public House createHouse() { public House createHouse() {
// Check that there is enough money in the team bank if (hasEnoughCash(Nomads.HOUSEPRICE)) {
int currentBalance = listItem.getTeam().getBalance();
if (currentBalance < Nomads.HOUSEPRICE) {
if (Nomads.DEBUGBUILDINGS)
System.out.println("You do not have enough money to build a house");
return null;
} else {
House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName()); House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName());
worldReference.placeNewBuilding(newHouse); worldReference.placeNewBuilding(newHouse);
currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
return newHouse; return newHouse;
} } else
return null;
// TODO - Implement time to create house // TODO - Implement time to create house
// Building a house should take many turns. Their drone will remain // Building a house should take many turns. Their drone will remain
// immobile while house is constructed. // immobile while house is constructed.
} }
/**
* If your team has enough money, will create an exact clone of your drone.
*/
public void createNewDrone() {
if (hasEnoughCash(Nomads.DRONEPRICE)) {
currentTeam.createNewDrone(listItem);
currentTeam.deductFromBalance(Nomads.DRONEPRICE);
// TODO - Implement time to create new drone
// Creating a drone should take many turns. Their drone will remain
// immobile while drone is constructed.
}
}
/**
* Tests to see if the team has enough money for an action
*
* @param price
* - Amount of money required
* @return <code>boolean</code>
*/
private boolean hasEnoughCash(int price) {
int currentBalance = listItem.getTeam().getBalance();
if (currentBalance < price) {
if (Nomads.DEBUGMOVES)
System.out.println("You do not have enough money!");
return false;
} else
return true;
}
} }

View File

@ -130,7 +130,7 @@ public class InitializeGame {
* *
* @return <code>String</code>- UID * @return <code>String</code>- UID
*/ */
private static String generateUID() { public static String generateUID() {
SecureRandom random = new SecureRandom(); SecureRandom random = new SecureRandom();
return new BigInteger(130, random).toString(32); return new BigInteger(130, random).toString(32);
} }

View File

@ -29,6 +29,11 @@ public class Nomads {
*/ */
public static final int HOUSEPRICE = 200; public static final int HOUSEPRICE = 200;
/**
* How much should a new drone cost?
*/
public static final int DRONEPRICE = 150;
public static void main(String[] args) { public static void main(String[] args) {
if (DEBUGSTATUS) if (DEBUGSTATUS)
System.out.println("Game initialization beginning..."); System.out.println("Game initialization beginning...");