Archived
1
0

-Created Police Class

-Created Upgrade Class
-Began Implementing Upgrade

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-08-29 13:46:07 -07:00
parent 7ab6479ad4
commit 29f8d0c633
11 changed files with 66 additions and 17 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -52,5 +52,13 @@ public interface Drone extends GameObject {
* @return <code>Neighbor</code> * @return <code>Neighbor</code>
*/ */
public Neighbor attack(); public Neighbor attack();
/**
* Asks what the drone would like to upgrade. Will be called whenever the Move
* method returns Upgrade.
*
* @return <code>Upgrade</code>
*/
public Upgrade upgrade();
} }

View File

@ -11,10 +11,6 @@ import java.util.ArrayList;
* *
* Previous --> Towards the first item Next --> Towards the last item * Previous --> Towards the first item Next --> Towards the last item
*/ */
/**
* @author tgrosinger
*
*/
public class DroneListItem { public class DroneListItem {
private DroneListItem next; private DroneListItem next;
private DroneListItem previous; private DroneListItem previous;
@ -59,7 +55,8 @@ public class DroneListItem {
/* /*
* Default constructor, includes all references * Default constructor, includes all references
*/ */
public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, Drone theCurrent, DroneTeam theTeam) { public DroneListItem(DroneListItem theNext, DroneListItem thePrevious,
Drone theCurrent, DroneTeam theTeam) {
next = theNext; next = theNext;
previous = thePrevious; previous = thePrevious;
current = theCurrent; current = theCurrent;
@ -233,7 +230,6 @@ public class DroneListItem {
public boolean getInventoryIsFull() { public boolean getInventoryIsFull() {
return inventory.size() >= cargoSpace; return inventory.size() >= cargoSpace;
} }
/** /**
* Sets the next DroneListItem in the Linked List * Sets the next DroneListItem in the Linked List
@ -244,7 +240,6 @@ public class DroneListItem {
public void setNext(DroneListItem theNext) { public void setNext(DroneListItem theNext) {
next = theNext; next = theNext;
} }
/** /**
* Sets the previous DroneListItem in the Linked List * Sets the previous DroneListItem in the Linked List
@ -365,7 +360,7 @@ public class DroneListItem {
return false; return false;
} }
case Upgrade: { case Upgrade: {
// TODO - Implement upgrade doUpgrade();
return true; return true;
} }
case Attack: { case Attack: {
@ -396,7 +391,8 @@ public class DroneListItem {
return; return;
} }
DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID()); DroneListItem victimList = Nomads
.UIDToListItem(victimNeighbor.getUID());
int victimDefence = victimList.getDefenses(); int victimDefence = victimList.getDefenses();
@ -413,7 +409,7 @@ public class DroneListItem {
// If number is > 70, kill // If number is > 70, kill
if (newRand <= 35) { if (newRand <= 35) {
// TODO - Implement wanted wanted = true;
} else if (newRand <= 70) { } else if (newRand <= 70) {
// Attack Failed // Attack Failed
} else if (newRand > 70) { } else if (newRand > 70) {
@ -435,7 +431,8 @@ public class DroneListItem {
return; return;
} }
DroneListItem victimList = Nomads.UIDToListItem(victimNeighbor.getUID()); DroneListItem victimList = Nomads
.UIDToListItem(victimNeighbor.getUID());
int victimDefence = victimList.getDefenses(); int victimDefence = victimList.getDefenses();
@ -456,7 +453,7 @@ public class DroneListItem {
Double percentToTake = .00; Double percentToTake = .00;
if (newRand <= 35) { if (newRand <= 35) {
// TODO - Implement wanted wanted = true;
} else if (newRand <= 70) { } else if (newRand <= 70) {
percentToTake = .00; percentToTake = .00;
} else if (newRand > 70 && newRand <= 80) { } else if (newRand > 70 && newRand <= 80) {
@ -471,15 +468,34 @@ public class DroneListItem {
// Not sure what happened here // Not sure what happened here
} }
int itemsToTake = (int) Math.ceil(itemsInVictimInventory * percentToTake); int itemsToTake = (int) Math.ceil(itemsInVictimInventory
while (itemsToTake < 0 && !getInventoryIsFull() && victimList.inventory.size() > 0) { * percentToTake);
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)); inventory.add(victimList.inventory.get(randIndex));
victimList.inventory.remove(randIndex); victimList.inventory.remove(randIndex);
} }
} }
/**
* Finds the upgrade that the drone would like to purchase.
*/
private void doUpgrade() {
Upgrade newUpgrade = current.upgrade();
int price = newUpgrade.getPrice();
if (team.getBalance() >= price) {
// TODO - Implement purchasing upgrades
team.deductFromBalance(price);
} else {
// Not enough money, do nothing.
return;
}
}
/** /**
* Move the drone in a specified direction * Move the drone in a specified direction
* *
@ -513,7 +529,8 @@ public class DroneListItem {
} }
} }
// 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() + amountE, getY() + amountN); GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX()
+ amountE, getY() + amountN);
if (objectHere != null) { if (objectHere != null) {
if (inventory.size() < cargoSpace) { if (inventory.size() < cargoSpace) {
@ -554,7 +571,8 @@ 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.size() - 1) - 0) + 1)); int randIndex = 0 + (int) (Math.random() * (((victim.inventory
.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

@ -0,0 +1,9 @@
package net.grosinger.nomads;
/**
* Enforcer of the law. Has the ability to arrest drones that are wanted.
*
*/
public class Police {
//TODO - Implement Police
}

View File

@ -0,0 +1,14 @@
package net.grosinger.nomads;
public class Upgrade {
public enum UpgradeType {
visibleDistance, lumaLocatorDistance, objectLocatorDistance, reliability, attack, defenses, speed, cargoSpace, theft
}
private UpgradeType typeToUpgrade;
public Upgrade(UpgradeType type){
typeToUpgrade = type;
}
}