diff --git a/bin/net/grosinger/nomads/DroneListItem$Direction.class b/bin/net/grosinger/nomads/DroneListItem$Direction.class index 810fd9e..4011d6e 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem$Direction.class and b/bin/net/grosinger/nomads/DroneListItem$Direction.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem$EnumMove.class b/bin/net/grosinger/nomads/DroneListItem$EnumMove.class index 25ad3e6..050b869 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem$EnumMove.class and b/bin/net/grosinger/nomads/DroneListItem$EnumMove.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem.class b/bin/net/grosinger/nomads/DroneListItem.class index bfe90a9..6eb13af 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem.class and b/bin/net/grosinger/nomads/DroneListItem.class differ diff --git a/bin/net/grosinger/nomads/TownHall.class b/bin/net/grosinger/nomads/TownHall.class index 01f697c..51f691c 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/World.class b/bin/net/grosinger/nomads/World.class index 9ea7016..8350017 100644 Binary files a/bin/net/grosinger/nomads/World.class and b/bin/net/grosinger/nomads/World.class differ diff --git a/src/net/grosinger/nomads/DroneListItem.java b/src/net/grosinger/nomads/DroneListItem.java index fc6a363..4457820 100644 --- a/src/net/grosinger/nomads/DroneListItem.java +++ b/src/net/grosinger/nomads/DroneListItem.java @@ -2,6 +2,8 @@ package net.grosinger.nomads; import java.util.ArrayList; +import net.grosinger.nomads.exceptions.FullInventoryException; + /** * A class that allows a drone to be part of a linked list Provides reference to * the next drone, the previous drone, and the drone object @@ -51,7 +53,7 @@ public class DroneListItem { private int y; private int waiting; // Is the drone building another drone or house? private boolean wanted; // Is the drone wanted by the police? - private ArrayList inventory; + private Inventory inventory; private ArrayList currentObjectives; // TODO - Implement max number of objectives @@ -75,7 +77,7 @@ public class DroneListItem { theft = Nomads.BASE_THEFT; team = theTeam; waiting = 0; - inventory = new ArrayList(); + inventory = new Inventory(this); // Place itself in the world Nomads.awesomeWorld.placeNewDrone(this); @@ -114,6 +116,15 @@ public class DroneListItem { return current; } + /** + * Retrieve the Inventory associated with this DroneListItem + * + * @return Inventory + */ + public Inventory getInventory() { + return inventory; + } + /** * Retrieve the distance this drone can see other drones * @@ -248,7 +259,7 @@ public class DroneListItem { * @return Boolean */ public boolean getInventoryIsFull() { - return inventory.size() >= cargoSpace; + return inventory.isFull(); } /** @@ -486,7 +497,13 @@ public class DroneListItem { while (itemsToTake < 0 && !getInventoryIsFull() && victimList.inventory.size() > 0) { // Min + (int)(Math.random() * ((Max - Min) + 1)) int randIndex = 0 + (int) (Math.random() * (((victimList.inventory.size() - 1) - 0) + 1)); - inventory.add(victimList.inventory.get(randIndex)); + + try { + inventory.addItem(victimList.inventory.getItem(randIndex)); + } catch (FullInventoryException e) { + e.printStackTrace(); + } + victimList.inventory.remove(randIndex); } } @@ -534,15 +551,23 @@ public class DroneListItem { GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN); if (objectHere != null) { - if (inventory.size() < cargoSpace) { + if (!inventory.isFull()) { if (objectHere instanceof MoneyPile) { - inventory.add(objectHere); + try { + inventory.addItem(objectHere); + } catch (FullInventoryException e) { + e.printStackTrace(); + } } else if (objectHere instanceof Objective) { String objUID = ((Objective) objectHere).getUID(); String droneUID = current.getUID(); if (objUID.equals(droneUID)) { - inventory.add(objectHere); + try { + inventory.addItem(objectHere); + } catch (FullInventoryException e) { + e.printStackTrace(); + } } else { return; } @@ -570,10 +595,14 @@ public class DroneListItem { * - DroneListItem to be killed */ private void killOtherDrone(DroneListItem victim) { - while (inventory.size() < cargoSpace && !victim.inventory.isEmpty()) { + while (!inventory.isFull() && !victim.inventory.isEmpty()) { // Take items from their inventory int randIndex = 0 + (int) (Math.random() * (((victim.inventory.size() - 1) - 0) + 1)); - inventory.add(victim.inventory.get(randIndex)); + try { + inventory.addItem(victim.inventory.getItem(randIndex)); + } catch (FullInventoryException e) { + e.printStackTrace(); + } victim.inventory.remove(randIndex); } diff --git a/src/net/grosinger/nomads/TownHall.java b/src/net/grosinger/nomads/TownHall.java index 7901906..1838145 100644 --- a/src/net/grosinger/nomads/TownHall.java +++ b/src/net/grosinger/nomads/TownHall.java @@ -1,7 +1,5 @@ package net.grosinger.nomads; -import java.util.ArrayList; - /** * A representation of a TownHall. Allows Drones to interact with this building. */ diff --git a/src/net/grosinger/nomads/World.java b/src/net/grosinger/nomads/World.java index b59dfce..94eeebb 100644 --- a/src/net/grosinger/nomads/World.java +++ b/src/net/grosinger/nomads/World.java @@ -5,8 +5,6 @@ import java.awt.Graphics2D; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; -import java.math.BigInteger; -import java.security.SecureRandom; import java.util.ArrayList; import java.util.HashMap; import java.util.Map;