Archived
1
0

-Started implementing Inventory object

-Revised how Objectives are generated

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-15 14:42:32 -07:00
parent 8d6840ac87
commit b89f594fdf
8 changed files with 33 additions and 35 deletions

Binary file not shown.

View File

@ -52,12 +52,15 @@ public class DroneListItem {
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 ArrayList<GameObject> inventory;
private ArrayList<Objective> currentObjectives;
// TODO - Implement max number of objectives
/* /*
* Default constructor, includes all references * Default constructor, includes all references
*/ */
public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, Drone theCurrent,
Drone theCurrent, DroneTeam theTeam) { DroneTeam theTeam) {
next = theNext; next = theNext;
previous = thePrevious; previous = thePrevious;
current = theCurrent; current = theCurrent;
@ -404,8 +407,7 @@ public class DroneListItem {
return; return;
} }
DroneListItem victimList = Nomads DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID());
.UIDToListItem(victimNeighbor.getUID());
int victimDefence = victimList.getDefenses(); int victimDefence = victimList.getDefenses();
@ -444,8 +446,7 @@ public class DroneListItem {
return; return;
} }
DroneListItem victimList = Nomads DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID());
.UIDToListItem(victimNeighbor.getUID());
int victimDefence = victimList.getDefenses(); int victimDefence = victimList.getDefenses();
@ -481,13 +482,10 @@ public class DroneListItem {
// Not sure what happened here // Not sure what happened here
} }
int itemsToTake = (int) Math.ceil(itemsInVictimInventory int itemsToTake = (int) Math.ceil(itemsInVictimInventory * percentToTake);
* percentToTake); 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 int randIndex = 0 + (int) (Math.random() * (((victimList.inventory.size() - 1) - 0) + 1));
.size() - 1) - 0) + 1));
inventory.add(victimList.inventory.get(randIndex)); inventory.add(victimList.inventory.get(randIndex));
victimList.inventory.remove(randIndex); victimList.inventory.remove(randIndex);
} }
@ -526,16 +524,14 @@ public class DroneListItem {
} }
} }
if (getX() + amountE > Nomads.awesomeWorld.getWorldSize() - 1 if (getX() + amountE > Nomads.awesomeWorld.getWorldSize() - 1 || getX() + amountE < 0
|| getX() + amountE < 0
|| getY() + amountN > Nomads.awesomeWorld.getWorldSize() - 1 || getY() + amountN > Nomads.awesomeWorld.getWorldSize() - 1
|| getY() + amountN < 0) { || getY() + amountN < 0) {
return; return;
} }
// Check to see if there is a MoneyPile or Objective there // Check to see if there is a MoneyPile or Objective there
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
+ amountE, getY() + amountN);
if (objectHere != null) { if (objectHere != null) {
if (inventory.size() < cargoSpace) { if (inventory.size() < cargoSpace) {
@ -576,8 +572,7 @@ public class DroneListItem {
private void killOtherDrone(DroneListItem victim) { private void killOtherDrone(DroneListItem victim) {
while (inventory.size() < cargoSpace && !victim.inventory.isEmpty()) { while (inventory.size() < cargoSpace && !victim.inventory.isEmpty()) {
// Take items from their inventory // Take items from their inventory
int randIndex = 0 + (int) (Math.random() * (((victim.inventory int randIndex = 0 + (int) (Math.random() * (((victim.inventory.size() - 1) - 0) + 1));
.size() - 1) - 0) + 1));
inventory.add(victim.inventory.get(randIndex)); inventory.add(victim.inventory.get(randIndex));
victim.inventory.remove(randIndex); victim.inventory.remove(randIndex);
} }

View File

@ -11,7 +11,7 @@ public class NeighborBuilding implements GameObject {
private int x; private int x;
private int y; private int y;
private Building building; private Building building;
private DroneListItem drone; protected DroneListItem drone;
/** /**
* Class Constructor * Class Constructor

View File

@ -9,8 +9,7 @@ public class TownHall extends NeighborBuilding {
// TODO - Rewrite class to make more accessible to Drones // TODO - Rewrite class to make more accessible to Drones
public TownHall(int x, int y, String name, Building building, public TownHall(int x, int y, String name, Building building, DroneListItem drone) {
DroneListItem drone) {
super(x, y, name, building, drone); super(x, y, name, building, drone);
} }
@ -21,17 +20,19 @@ public class TownHall extends NeighborBuilding {
* @param inventory * @param inventory
* @param team * @param team
*/ */
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) { public void cashInventory() {
if (verifyObjectValidity()) { if (verifyObjectValidity()) {
Inventory inventory = drone.getInventory();
DroneTeam team = drone.getTeam();
while (!inventory.isEmpty()) { while (!inventory.isEmpty()) {
GameObject currentObject = inventory.get(0); GameObject currentObject = inventory.getItem(0);
if (currentObject instanceof MoneyPile) { if (currentObject instanceof MoneyPile) {
int value = ((MoneyPile) currentObject).getValue(); int value = ((MoneyPile) currentObject).getValue();
team.increaseBalance(value); team.increaseBalance(value);
Nomads.awesomeWorld.generateMoneyPile(); Nomads.awesomeWorld.generateMoneyPile();
} else if (currentObject instanceof Objective) { } else if (currentObject instanceof Objective) {
team.increaseBalance(((Objective) currentObject) team.increaseBalance(((Objective) currentObject).getBounty());
.getBounty());
} }
inventory.remove(currentObject); inventory.remove(currentObject);
} }
@ -43,14 +44,12 @@ public class TownHall extends NeighborBuilding {
/** /**
* Will generate a new objective for the drone that requests it. * Will generate a new objective for the drone that requests it.
* *
* @param UID
* Depreciated and going away soon.
* @return <code>Point</code> Will return null if the NeighborBuilding was * @return <code>Point</code> Will return null if the NeighborBuilding was
* created in a previous turn. * created in a previous turn.
*/ */
public Point requestNewObjective(String UID) { public Point requestNewObjective() {
if (verifyObjectValidity()) { if (verifyObjectValidity()) {
return Nomads.awesomeWorld.generateObjective(UID); return Nomads.awesomeWorld.generateObjective(drone);
} else { } else {
// Object not valid, do nothing // Object not valid, do nothing
return null; return null;

View File

@ -5,11 +5,12 @@ 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;
/** /**
* Main class where information about the world is stored * Main class where information about the world is stored
* *
@ -233,9 +234,11 @@ public class World {
GameObject objectHere = theWorld[x + i][y + j]; GameObject objectHere = theWorld[x + i][y + j];
if (objectHere != null) { if (objectHere != null) {
String name = objectHere.getName(); String name = objectHere.getName();
if (name.equalsIgnoreCase("TownHall") || name.equalsIgnoreCase("PoliceStation")) { if (name.equalsIgnoreCase("TownHall")
|| name.equalsIgnoreCase("PoliceStation")) {
return true; return true;
} else if ((name.equalsIgnoreCase("RepairShop") || name.equalsIgnoreCase("UpgradeShop")) && i <= 2 && j <= 2) { } else if ((name.equalsIgnoreCase("RepairShop") || name
.equalsIgnoreCase("UpgradeShop")) && i <= 2 && j <= 2) {
return true; return true;
} }
} }
@ -297,7 +300,7 @@ public class World {
* - The UID of the Drone that is allowed to pick it up. * - The UID of the Drone that is allowed to pick it up.
* @return - <code>Point</code> - Within 20x20 of the Objective. * @return - <code>Point</code> - Within 20x20 of the Objective.
*/ */
public Point generateObjective(String UID) { public Point generateObjective(DroneListItem drone) {
// Min + (int)(Math.random() * ((Max - Min) + 1)) // Min + (int)(Math.random() * ((Max - Min) + 1))
int randX = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1)); int randX = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
int randY = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1)); int randY = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
@ -305,9 +308,10 @@ public class World {
int varY = -10 + (int) (Math.random() * ((10 - -10) + 1)); int varY = -10 + (int) (Math.random() * ((10 - -10) + 1));
int varX = -10 + (int) (Math.random() * ((10 - -10) + 1)); int varX = -10 + (int) (Math.random() * ((10 - -10) + 1));
int bounty = Nomads.MINOBJECTIVEBOUNTY + (int) (Math.random() * ((Nomads.MAXOBJECTIVEBOUNTY - Nomads.MINOBJECTIVEBOUNTY) + 1)); int bounty = Nomads.MINOBJECTIVEBOUNTY
+ (int) (Math.random() * ((Nomads.MAXOBJECTIVEBOUNTY - Nomads.MINOBJECTIVEBOUNTY) + 1));
Objective newObjective = new Objective(bounty, UID); Objective newObjective = new Objective(bounty, drone.getCurrent().getUID());
setObjectAt(randX, randY, newObjective); setObjectAt(randX, randY, newObjective);
// Create a point to return that is somewhere nearby the actual location // Create a point to return that is somewhere nearby the actual location