-Implemented randomly generated MoneyPiles
-Continued implementing creation of drones and houses Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
parent
bb5ab7a7aa
commit
20e7ec66fe
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/net/grosinger/nomads/MoneyPile.class
Normal file
BIN
bin/net/grosinger/nomads/MoneyPile.class
Normal file
Binary file not shown.
Binary file not shown.
BIN
bin/net/grosinger/nomads/Objective.class
Normal file
BIN
bin/net/grosinger/nomads/Objective.class
Normal file
Binary file not shown.
BIN
bin/net/grosinger/nomads/Point.class
Normal file
BIN
bin/net/grosinger/nomads/Point.class
Normal file
Binary file not shown.
Binary file not shown.
@ -359,6 +359,15 @@ public class DroneListItem {
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Check to see if there is a MoneyPile or Objective there
|
||||
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
|
||||
if (objectHere instanceof MoneyPile) {
|
||||
int value = ((MoneyPile) objectHere).getValue();
|
||||
team.increaseBalance(value);
|
||||
Nomads.awesomeWorld.generateMoneyPile();
|
||||
} else if (objectHere instanceof Objective) {
|
||||
// TODO - Implement moving onto Objective
|
||||
}
|
||||
|
||||
// Make the move
|
||||
Nomads.awesomeWorld.moveObjectAt(getX(), getY(), amountN, amountE);
|
||||
|
@ -241,8 +241,9 @@ public class DroneTeam {
|
||||
*
|
||||
* @param listItem
|
||||
* - Drone that issued the request
|
||||
* @param location
|
||||
*/
|
||||
public void createNewDrone(DroneListItem listItem) {
|
||||
public void createNewDrone(DroneListItem listItem, Point location) {
|
||||
Class<? extends Drone> c = listItem.getCurrent().getClass();
|
||||
Drone newDrone = null;
|
||||
try {
|
||||
@ -252,11 +253,16 @@ public class DroneTeam {
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
|
||||
newDrone.setName(getName());
|
||||
newDrone.setUID(InitializeGame.generateUID());
|
||||
|
||||
|
||||
DroneListItem newListItem = new DroneListItem(null, last, newDrone, this);
|
||||
addToEnd(newListItem);
|
||||
|
||||
newListItem.setX(location.getX());
|
||||
newListItem.setY(location.getY());
|
||||
|
||||
Nomads.awesomeWorld.setObjectAt(location.getX(), location.getY(), newDrone);
|
||||
}
|
||||
}
|
||||
|
@ -59,10 +59,7 @@ public class DroneTools {
|
||||
* @return <code>Boolean</code> - can move
|
||||
*/
|
||||
public boolean canMoveNorth() {
|
||||
if (getY() < worldSize - 1)
|
||||
return worldReference.getWorldGrid()[getX()][getY() + 1] == null;
|
||||
else
|
||||
return false;
|
||||
return canMoveHelper(getX(), getY() + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -71,10 +68,7 @@ public class DroneTools {
|
||||
* @return <code>Boolean</code> - can move
|
||||
*/
|
||||
public boolean canMoveSouth() {
|
||||
if (getY() > 0)
|
||||
return worldReference.getWorldGrid()[getX()][getY() - 1] == null;
|
||||
else
|
||||
return false;
|
||||
return canMoveHelper(getX(), getY() - 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -83,10 +77,7 @@ public class DroneTools {
|
||||
* @return <code>Boolean</code> - can move
|
||||
*/
|
||||
public boolean canMoveEast() {
|
||||
if (getX() < worldSize - 1)
|
||||
return worldReference.getWorldGrid()[getX() + 1][getY()] == null;
|
||||
else
|
||||
return false;
|
||||
return canMoveHelper(getX() + 1, getY());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,9 +86,29 @@ public class DroneTools {
|
||||
* @return <code>Boolean</code> - can move
|
||||
*/
|
||||
public boolean canMoveWest() {
|
||||
if (getX() > 0)
|
||||
return worldReference.getWorldGrid()[getX() - 1][getY()] == null;
|
||||
else
|
||||
return canMoveHelper(getX() - 1, getY());
|
||||
}
|
||||
|
||||
/**
|
||||
* Does actual checking to see if a space is able to be occupied
|
||||
*
|
||||
* @param x
|
||||
* - X index
|
||||
* @param y
|
||||
* - Y index
|
||||
* @return <code>boolean</code>
|
||||
*/
|
||||
private boolean canMoveHelper(int x, int y) {
|
||||
// Account for being able to move onto MoneyPiles and Objectives
|
||||
|
||||
if (getY() < worldSize - 1) {
|
||||
GameObject objectHere = worldReference.getWorld()[getX()][getY() + 1];
|
||||
if (objectHere == null || objectHere instanceof MoneyPile || objectHere instanceof Objective)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -147,7 +158,11 @@ public class DroneTools {
|
||||
*/
|
||||
public House createHouse() {
|
||||
if (hasEnoughCash(Nomads.HOUSEPRICE)) {
|
||||
House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName());
|
||||
// Find the closest spot to you that is open
|
||||
Point intendedPoint = new Point(getX(), getY());
|
||||
findEmptyPoint(intendedPoint);
|
||||
|
||||
House newHouse = new House(Structure.HOUSE, intendedPoint.getX(), intendedPoint.getY(), referredDrone.getName());
|
||||
worldReference.placeNewBuilding(newHouse);
|
||||
currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
|
||||
return newHouse;
|
||||
@ -164,7 +179,8 @@ public class DroneTools {
|
||||
*/
|
||||
public void createNewDrone() {
|
||||
if (hasEnoughCash(Nomads.DRONEPRICE)) {
|
||||
currentTeam.createNewDrone(listItem);
|
||||
Point location = new Point(getX(), getY());
|
||||
currentTeam.createNewDrone(listItem, location);
|
||||
currentTeam.deductFromBalance(Nomads.DRONEPRICE);
|
||||
// TODO - Implement time to create new drone
|
||||
// Creating a drone should take many turns. Their drone will remain
|
||||
@ -172,6 +188,51 @@ public class DroneTools {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Find "closest" point that is available to the point provided
|
||||
*
|
||||
* @param currentPoint
|
||||
* - Location of drone
|
||||
* @return <code>Point</code>
|
||||
*/
|
||||
private Point findEmptyPoint(Point currentPoint) {
|
||||
// Current point is where the drone is
|
||||
boolean validSpace = worldReference.getObjectAt(currentPoint.getX(), currentPoint.getY()) == null;
|
||||
Point tryThis = new Point(currentPoint.getX(), currentPoint.getY());
|
||||
int outX = 1;
|
||||
int outY = 0;
|
||||
int multiplier = 1;
|
||||
|
||||
while (!validSpace) {
|
||||
tryThis.setX(currentPoint.getX() + (outX * multiplier));
|
||||
tryThis.setY(currentPoint.getY() + (outY * multiplier));
|
||||
if (worldReference.getObjectAt(tryThis.getX(), tryThis.getY()) == null)
|
||||
validSpace = true;
|
||||
else {
|
||||
if (outX == 1 && outY == 0) {
|
||||
outY = 1;
|
||||
} else if (outX == 1 && outY == 1)
|
||||
outX = 0;
|
||||
else if (outX == 0 && outY == 1)
|
||||
outX = -1;
|
||||
else if (outX == -1 && outY == 1)
|
||||
outY = 0;
|
||||
else if (outX == -1 && outY == 0)
|
||||
outY = -1;
|
||||
else if (outX == -1 && outY == -1)
|
||||
outX = 0;
|
||||
else if (outX == 0 && outY == -1)
|
||||
outX = 1;
|
||||
else if (outX == 1 && outY == -1) {
|
||||
outY = 0;
|
||||
outX = 1;
|
||||
multiplier++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return tryThis;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests to see if the team has enough money for an action
|
||||
*
|
||||
@ -188,4 +249,13 @@ public class DroneTools {
|
||||
} else
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find out how much money your team has
|
||||
*
|
||||
* @return <code>int</code> - Team Balance
|
||||
*/
|
||||
public int getTeamBalance() {
|
||||
return currentTeam.getBalance();
|
||||
}
|
||||
}
|
||||
|
@ -163,4 +163,14 @@ public class InitializeGame {
|
||||
if (Nomads.DEBUGSTATUS)
|
||||
System.out.println("Building placement complete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate the money piles and place them on the map
|
||||
*/
|
||||
public static void initializeMoneyPiles() {
|
||||
for(int i = 0; i < Nomads.MONEYPILES; i++){
|
||||
MoneyPile newPile = new MoneyPile();
|
||||
Nomads.awesomeWorld.setObjectRandom(newPile);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
41
src/net/grosinger/nomads/MoneyPile.java
Normal file
41
src/net/grosinger/nomads/MoneyPile.java
Normal file
@ -0,0 +1,41 @@
|
||||
package net.grosinger.nomads;
|
||||
|
||||
/**
|
||||
* A random pile of money with a random assigned value
|
||||
*/
|
||||
public class MoneyPile implements GameObject {
|
||||
private static String name = "MoneyPile";
|
||||
private int value;
|
||||
|
||||
/**
|
||||
* Class Constructor
|
||||
*/
|
||||
public MoneyPile() {
|
||||
value = randomValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
/**
|
||||
* How much is this money pile worth?
|
||||
*
|
||||
* @return <code>int</code> - The value of this pile.
|
||||
*/
|
||||
public int getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String newName) {
|
||||
// The name of a money pile will never need to be changed
|
||||
}
|
||||
|
||||
private int randomValue() {
|
||||
// Min + (int)(Math.random() * ((Max - Min) + 1))
|
||||
return 100 + (int) (Math.random() * ((400 - 100) + 1));
|
||||
}
|
||||
|
||||
}
|
@ -34,6 +34,16 @@ public class Nomads {
|
||||
*/
|
||||
public static final int DRONEPRICE = 150;
|
||||
|
||||
/**
|
||||
* How many turns does it take to create a drone or house?
|
||||
*/
|
||||
public static final int CREATIONTIME = 200;
|
||||
|
||||
/**
|
||||
* How many randomly generated money piles should there be?
|
||||
*/
|
||||
public static final int MONEYPILES = 30;
|
||||
|
||||
public static void main(String[] args) {
|
||||
if (DEBUGSTATUS)
|
||||
System.out.println("Game initialization beginning...");
|
||||
|
15
src/net/grosinger/nomads/Objective.java
Normal file
15
src/net/grosinger/nomads/Objective.java
Normal file
@ -0,0 +1,15 @@
|
||||
package net.grosinger.nomads;
|
||||
|
||||
public class Objective implements GameObject {
|
||||
// TODO - Implement Objective
|
||||
@Override
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String newName) {
|
||||
|
||||
}
|
||||
|
||||
}
|
30
src/net/grosinger/nomads/Point.java
Normal file
30
src/net/grosinger/nomads/Point.java
Normal file
@ -0,0 +1,30 @@
|
||||
package net.grosinger.nomads;
|
||||
|
||||
/**
|
||||
* Just used to transport locations between two methods
|
||||
*/
|
||||
public class Point {
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
public Point(int newX, int newY) {
|
||||
x = newX;
|
||||
y = newY;
|
||||
}
|
||||
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setX(int newX) {
|
||||
x = newX;
|
||||
}
|
||||
|
||||
public void setY(int newY) {
|
||||
y = newY;
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@ public class World {
|
||||
/**
|
||||
* The 2D array of the entire world
|
||||
*/
|
||||
private GameObject theWorld[][];
|
||||
private GameObject[][] theWorld;
|
||||
|
||||
/**
|
||||
* All drones will start at Y=20. Will then move East from X=40
|
||||
@ -74,7 +74,7 @@ public class World {
|
||||
*
|
||||
* @return theWorld
|
||||
*/
|
||||
public GameObject[][] getWorldGrid() {
|
||||
public GameObject[][] getWorld() {
|
||||
return theWorld;
|
||||
}
|
||||
|
||||
@ -218,6 +218,14 @@ public class World {
|
||||
// TODO - Implement buildingsInRange
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a new MoneyPile at random location
|
||||
*/
|
||||
public void generateMoneyPile(){
|
||||
MoneyPile newPile = new MoneyPile();
|
||||
setObjectRandom(newPile);
|
||||
}
|
||||
|
||||
/**
|
||||
* Outputs an HTML file showing the world
|
||||
@ -251,6 +259,9 @@ public class World {
|
||||
g2d.drawLine(i, 0, i, 1000);
|
||||
g2d.drawLine(0, i, 1000, i);
|
||||
}
|
||||
g2d.drawLine(999, 0, 999, 1000);
|
||||
g2d.drawLine(0, 999, 1000, 999);
|
||||
|
||||
for (int i = 0; i < WORLDSIZE; i++) {
|
||||
for (int j = 0; j < WORLDSIZE; j++) {
|
||||
GameObject objectHere = theWorld[j][i];
|
||||
@ -266,6 +277,8 @@ public class World {
|
||||
// World owned buildings should be black
|
||||
g2d.setColor(Color.black);
|
||||
g2d.fillRect(j * 10, i * 10, 10, 10);
|
||||
} else if (objectHere instanceof MoneyPile) {
|
||||
// TODO - Implement mapping of MoneyPiles
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user