-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:
parent
b89f594fdf
commit
1bd81d97bd
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -2,6 +2,8 @@ package net.grosinger.nomads;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
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
|
* 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
|
* the next drone, the previous drone, and the drone object
|
||||||
@ -51,7 +53,7 @@ public class DroneListItem {
|
|||||||
private int y;
|
private int y;
|
||||||
private int waiting; // Is the drone building another drone or house?
|
private int waiting; // Is the drone building another drone or house?
|
||||||
private boolean wanted; // Is the drone wanted by the police?
|
private boolean wanted; // Is the drone wanted by the police?
|
||||||
private ArrayList<GameObject> inventory;
|
private Inventory inventory;
|
||||||
private ArrayList<Objective> currentObjectives;
|
private ArrayList<Objective> currentObjectives;
|
||||||
|
|
||||||
// TODO - Implement max number of objectives
|
// TODO - Implement max number of objectives
|
||||||
@ -75,7 +77,7 @@ public class DroneListItem {
|
|||||||
theft = Nomads.BASE_THEFT;
|
theft = Nomads.BASE_THEFT;
|
||||||
team = theTeam;
|
team = theTeam;
|
||||||
waiting = 0;
|
waiting = 0;
|
||||||
inventory = new ArrayList<GameObject>();
|
inventory = new Inventory(this);
|
||||||
|
|
||||||
// Place itself in the world
|
// Place itself in the world
|
||||||
Nomads.awesomeWorld.placeNewDrone(this);
|
Nomads.awesomeWorld.placeNewDrone(this);
|
||||||
@ -114,6 +116,15 @@ public class DroneListItem {
|
|||||||
return current;
|
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
|
* Retrieve the distance this drone can see other drones
|
||||||
*
|
*
|
||||||
@ -248,7 +259,7 @@ public class DroneListItem {
|
|||||||
* @return <code>Boolean</code>
|
* @return <code>Boolean</code>
|
||||||
*/
|
*/
|
||||||
public boolean getInventoryIsFull() {
|
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) {
|
while (itemsToTake < 0 && !getInventoryIsFull() && victimList.inventory.size() > 0) {
|
||||||
// Min + (int)(Math.random() * ((Max - Min) + 1))
|
// Min + (int)(Math.random() * ((Max - Min) + 1))
|
||||||
int randIndex = 0 + (int) (Math.random() * (((victimList.inventory.size() - 1) - 0) + 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);
|
victimList.inventory.remove(randIndex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -534,15 +551,23 @@ public class DroneListItem {
|
|||||||
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
|
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
|
||||||
|
|
||||||
if (objectHere != null) {
|
if (objectHere != null) {
|
||||||
if (inventory.size() < cargoSpace) {
|
if (!inventory.isFull()) {
|
||||||
if (objectHere instanceof MoneyPile) {
|
if (objectHere instanceof MoneyPile) {
|
||||||
inventory.add(objectHere);
|
try {
|
||||||
|
inventory.addItem(objectHere);
|
||||||
|
} catch (FullInventoryException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else if (objectHere instanceof Objective) {
|
} else if (objectHere instanceof Objective) {
|
||||||
String objUID = ((Objective) objectHere).getUID();
|
String objUID = ((Objective) objectHere).getUID();
|
||||||
String droneUID = current.getUID();
|
String droneUID = current.getUID();
|
||||||
|
|
||||||
if (objUID.equals(droneUID)) {
|
if (objUID.equals(droneUID)) {
|
||||||
inventory.add(objectHere);
|
try {
|
||||||
|
inventory.addItem(objectHere);
|
||||||
|
} catch (FullInventoryException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -570,10 +595,14 @@ public class DroneListItem {
|
|||||||
* - <code>DroneListItem</code> to be killed
|
* - <code>DroneListItem</code> to be killed
|
||||||
*/
|
*/
|
||||||
private void killOtherDrone(DroneListItem victim) {
|
private void killOtherDrone(DroneListItem victim) {
|
||||||
while (inventory.size() < cargoSpace && !victim.inventory.isEmpty()) {
|
while (!inventory.isFull() && !victim.inventory.isEmpty()) {
|
||||||
// Take items from their inventory
|
// Take items from their inventory
|
||||||
int randIndex = 0 + (int) (Math.random() * (((victim.inventory.size() - 1) - 0) + 1));
|
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);
|
victim.inventory.remove(randIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.grosinger.nomads;
|
package net.grosinger.nomads;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A representation of a TownHall. Allows Drones to interact with this building.
|
* A representation of a TownHall. Allows Drones to interact with this building.
|
||||||
*/
|
*/
|
||||||
|
@ -5,8 +5,6 @@ import java.awt.Graphics2D;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.math.BigInteger;
|
|
||||||
import java.security.SecureRandom;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
Reference in New Issue
Block a user