Archived
1
0

-Created Exception for inventory being full

-Implemented Inventory Object
-Revised how Drone interacts with inventory

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-15 15:51:14 -07:00
parent b89f594fdf
commit 1bd81d97bd
8 changed files with 38 additions and 13 deletions

Binary file not shown.

View File

@ -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<GameObject> inventory;
private Inventory inventory;
private ArrayList<Objective> 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<GameObject>();
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 <code>Inventory</code>
*/
public Inventory getInventory() {
return inventory;
}
/**
* Retrieve the distance this drone can see other drones
*
@ -248,7 +259,7 @@ public class DroneListItem {
* @return <code>Boolean</code>
*/
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 {
* - <code>DroneListItem</code> 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);
}

View File

@ -1,7 +1,5 @@
package net.grosinger.nomads;
import java.util.ArrayList;
/**
* A representation of a TownHall. Allows Drones to interact with this building.
*/

View File

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