Archived
1
0

-Continue Attack

-Implement Kill/Die

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-06-04 23:16:41 -07:00
parent b7c5991a7a
commit 7ab6479ad4
4 changed files with 64 additions and 4 deletions

View File

@ -11,6 +11,10 @@ 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;
@ -49,6 +53,7 @@ public class DroneListItem {
private int x; private int x;
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 ArrayList<GameObject> inventory; private ArrayList<GameObject> inventory;
/* /*
@ -202,6 +207,15 @@ public class DroneListItem {
return y; return y;
} }
/**
* Returns if the drone is wanted
*
* @return <code>boolean</code>
*/
public boolean getWanted() {
return wanted;
}
/** /**
* Retrieve reference to the team this drone belongs to * Retrieve reference to the team this drone belongs to
* *
@ -211,9 +225,15 @@ public class DroneListItem {
return team; return team;
} }
/**
* Find if the inventory is full
*
* @return <code>Boolean</code>
*/
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
@ -224,6 +244,7 @@ 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
@ -294,6 +315,13 @@ public class DroneListItem {
// Actions // Actions
/**
* Removes this drone from the team
*/
public void die() {
team.removeDrone(this);
}
/** /**
* Will ask the Drone what direction it would like to move * Will ask the Drone what direction it would like to move
* *
@ -381,11 +409,19 @@ public class DroneListItem {
newRand += rand; newRand += rand;
// If number is <= 35, drone becomes wanted // If number is <= 35, drone becomes wanted
// If number is <= 70, steal fails // If number is <= 70, attack fails
// If number is > 70, steal // If number is > 70, kill
// Depending on how much higher than 70, more items will be stolen
// TODO - Continue implementing attack if (newRand <= 35) {
// TODO - Implement wanted
} else if (newRand <= 70) {
// Attack Failed
} else if (newRand > 70) {
// Drone Killed
killOtherDrone(victimList);
} else {
// Not sure what happened here
}
} }
/** /**
@ -444,6 +480,12 @@ public class DroneListItem {
} }
} }
/**
* Move the drone in a specified direction
*
* @param direction
* <code>Direction</code> to move
*/
private void moveDrone(Direction direction) { private void moveDrone(Direction direction) {
if (waiting != 0) { if (waiting != 0) {
waiting--; waiting--;
@ -501,4 +543,22 @@ public class DroneListItem {
if (amountE != 0) if (amountE != 0)
setX(getX() + amountE); setX(getX() + amountE);
} }
/**
* Kills another drone. Will take a random assortment of the items in their
* inventory.
*
* @param victim
* - <code>DroneListItem</code> to be killed
*/
private void killOtherDrone(DroneListItem victim) {
while (inventory.size() < cargoSpace && !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));
victim.inventory.remove(randIndex);
}
victim.die();
}
} }