diff --git a/bin/net/grosinger/nomads/DroneTeam.class b/bin/net/grosinger/nomads/DroneTeam.class
index b28ebb9..98562c9 100644
Binary files a/bin/net/grosinger/nomads/DroneTeam.class and b/bin/net/grosinger/nomads/DroneTeam.class differ
diff --git a/bin/net/grosinger/nomads/DroneTools.class b/bin/net/grosinger/nomads/DroneTools.class
index fb203e4..e034ab5 100644
Binary files a/bin/net/grosinger/nomads/DroneTools.class and b/bin/net/grosinger/nomads/DroneTools.class differ
diff --git a/bin/net/grosinger/nomads/InitializeGame.class b/bin/net/grosinger/nomads/InitializeGame.class
index dec170b..d597a08 100644
Binary files a/bin/net/grosinger/nomads/InitializeGame.class and b/bin/net/grosinger/nomads/InitializeGame.class differ
diff --git a/bin/net/grosinger/nomads/Nomads.class b/bin/net/grosinger/nomads/Nomads.class
index ab6289c..d37e9b2 100644
Binary files a/bin/net/grosinger/nomads/Nomads.class and b/bin/net/grosinger/nomads/Nomads.class differ
diff --git a/src/net/grosinger/nomads/DroneListItem.java b/src/net/grosinger/nomads/DroneListItem.java
index ad9ad27..c2896dd 100644
--- a/src/net/grosinger/nomads/DroneListItem.java
+++ b/src/net/grosinger/nomads/DroneListItem.java
@@ -162,7 +162,7 @@ public class DroneListItem {
}
/**
- * Retrieve the level of this drone in theiving
+ * Retrieve the level of this drone in thieving
*
* @return int
*/
diff --git a/src/net/grosinger/nomads/DroneTeam.java b/src/net/grosinger/nomads/DroneTeam.java
index 26cf58f..e1603ce 100644
--- a/src/net/grosinger/nomads/DroneTeam.java
+++ b/src/net/grosinger/nomads/DroneTeam.java
@@ -225,4 +225,38 @@ public class DroneTeam {
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);
+ }
}
diff --git a/src/net/grosinger/nomads/DroneTools.java b/src/net/grosinger/nomads/DroneTools.java
index 248232d..bb5b0ce 100644
--- a/src/net/grosinger/nomads/DroneTools.java
+++ b/src/net/grosinger/nomads/DroneTools.java
@@ -12,6 +12,7 @@ public class DroneTools {
private Drone referredDrone;
private DroneListItem listItem;
+ private DroneTeam currentTeam;
private World worldReference;
private int worldSize;
@@ -20,6 +21,7 @@ public class DroneTools {
listItem = droneParent;
worldReference = theWorld;
worldSize = worldReference.getWorldSize();
+ currentTeam = listItem.getTeam();
}
/**
@@ -144,20 +146,46 @@ public class DroneTools {
* if it can not create the house.
*/
public House createHouse() {
- // Check that there is enough money in the team bank
- 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 {
+ if (hasEnoughCash(Nomads.HOUSEPRICE)) {
House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName());
worldReference.placeNewBuilding(newHouse);
+ currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
return newHouse;
- }
+ } else
+ return null;
// TODO - Implement time to create house
// Building a house should take many turns. Their drone will remain
// 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 boolean
+ */
+ 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;
+ }
}
diff --git a/src/net/grosinger/nomads/InitializeGame.java b/src/net/grosinger/nomads/InitializeGame.java
index 8ada0eb..1ec397c 100644
--- a/src/net/grosinger/nomads/InitializeGame.java
+++ b/src/net/grosinger/nomads/InitializeGame.java
@@ -130,7 +130,7 @@ public class InitializeGame {
*
* @return String
- UID
*/
- private static String generateUID() {
+ public static String generateUID() {
SecureRandom random = new SecureRandom();
return new BigInteger(130, random).toString(32);
}
diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java
index 96c3fdd..e0803b6 100644
--- a/src/net/grosinger/nomads/Nomads.java
+++ b/src/net/grosinger/nomads/Nomads.java
@@ -29,6 +29,11 @@ public class Nomads {
*/
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) {
if (DEBUGSTATUS)
System.out.println("Game initialization beginning...");