-Implemented most of creating a new drone
Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
parent
4f7140b45a
commit
bb5ab7a7aa
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -162,7 +162,7 @@ public class DroneListItem {
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the level of this drone in theiving
|
||||
* Retrieve the level of this drone in thieving
|
||||
*
|
||||
* @return <code>int</code>
|
||||
*/
|
||||
|
@ -225,4 +225,38 @@ public class DroneTeam {
|
||||
current = current.getNext();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes money from the balance
|
||||
*
|
||||
* @param price
|
||||
* - Amount to remove
|
||||
*/
|
||||
public void deductFromBalance(int price) {
|
||||
currentBalance -= price;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new drone on the same team next to the creator
|
||||
*
|
||||
* @param listItem
|
||||
* - Drone that issued the request
|
||||
*/
|
||||
public void createNewDrone(DroneListItem listItem) {
|
||||
Class<? extends Drone> c = listItem.getCurrent().getClass();
|
||||
Drone newDrone = null;
|
||||
try {
|
||||
newDrone = (Drone) c.newInstance();
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
newDrone.setName(getName());
|
||||
newDrone.setUID(InitializeGame.generateUID());
|
||||
|
||||
DroneListItem newListItem = new DroneListItem(null, last, newDrone, this);
|
||||
addToEnd(newListItem);
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ public class DroneTools {
|
||||
|
||||
private Drone referredDrone;
|
||||
private DroneListItem listItem;
|
||||
private DroneTeam currentTeam;
|
||||
private World worldReference;
|
||||
private int worldSize;
|
||||
|
||||
@ -20,6 +21,7 @@ public class DroneTools {
|
||||
listItem = droneParent;
|
||||
worldReference = theWorld;
|
||||
worldSize = worldReference.getWorldSize();
|
||||
currentTeam = listItem.getTeam();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -144,20 +146,46 @@ public class DroneTools {
|
||||
* if it can not create the house.
|
||||
*/
|
||||
public House createHouse() {
|
||||
// Check that there is enough money in the team bank
|
||||
int currentBalance = listItem.getTeam().getBalance();
|
||||
if (currentBalance < Nomads.HOUSEPRICE) {
|
||||
if (Nomads.DEBUGBUILDINGS)
|
||||
System.out.println("You do not have enough money to build a house");
|
||||
return null;
|
||||
} else {
|
||||
if (hasEnoughCash(Nomads.HOUSEPRICE)) {
|
||||
House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName());
|
||||
worldReference.placeNewBuilding(newHouse);
|
||||
currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
|
||||
return newHouse;
|
||||
}
|
||||
} else
|
||||
return null;
|
||||
|
||||
// TODO - Implement time to create house
|
||||
// Building a house should take many turns. Their drone will remain
|
||||
// immobile while house is constructed.
|
||||
}
|
||||
|
||||
/**
|
||||
* If your team has enough money, will create an exact clone of your drone.
|
||||
*/
|
||||
public void createNewDrone() {
|
||||
if (hasEnoughCash(Nomads.DRONEPRICE)) {
|
||||
currentTeam.createNewDrone(listItem);
|
||||
currentTeam.deductFromBalance(Nomads.DRONEPRICE);
|
||||
// TODO - Implement time to create new drone
|
||||
// Creating a drone should take many turns. Their drone will remain
|
||||
// immobile while drone is constructed.
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if the team has enough money for an action
|
||||
*
|
||||
* @param price
|
||||
* - Amount of money required
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
private boolean hasEnoughCash(int price) {
|
||||
int currentBalance = listItem.getTeam().getBalance();
|
||||
if (currentBalance < price) {
|
||||
if (Nomads.DEBUGMOVES)
|
||||
System.out.println("You do not have enough money!");
|
||||
return false;
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -130,7 +130,7 @@ public class InitializeGame {
|
||||
*
|
||||
* @return <code>String</code>- UID
|
||||
*/
|
||||
private static String generateUID() {
|
||||
public static String generateUID() {
|
||||
SecureRandom random = new SecureRandom();
|
||||
return new BigInteger(130, random).toString(32);
|
||||
}
|
||||
|
@ -29,6 +29,11 @@ public class Nomads {
|
||||
*/
|
||||
public static final int HOUSEPRICE = 200;
|
||||
|
||||
/**
|
||||
* How much should a new drone cost?
|
||||
*/
|
||||
public static final int DRONEPRICE = 150;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (DEBUGSTATUS)
|
||||
System.out.println("Game initialization beginning...");
|
||||
|
Reference in New Issue
Block a user