diff --git a/bin/net/grosinger/nomads/DroneListItem.class b/bin/net/grosinger/nomads/DroneListItem.class index 73453b3..5590327 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem.class and b/bin/net/grosinger/nomads/DroneListItem.class differ diff --git a/bin/net/grosinger/nomads/DroneTeam.class b/bin/net/grosinger/nomads/DroneTeam.class index 98562c9..a44c47e 100644 Binary files a/bin/net/grosinger/nomads/DroneTeam.class and b/bin/net/grosinger/nomads/DroneTeam.class differ diff --git a/bin/net/grosinger/nomads/DroneTools.class b/bin/net/grosinger/nomads/DroneTools.class index e034ab5..c73747e 100644 Binary files a/bin/net/grosinger/nomads/DroneTools.class and b/bin/net/grosinger/nomads/DroneTools.class differ diff --git a/bin/net/grosinger/nomads/InitializeGame.class b/bin/net/grosinger/nomads/InitializeGame.class index d597a08..86a1557 100644 Binary files a/bin/net/grosinger/nomads/InitializeGame.class and b/bin/net/grosinger/nomads/InitializeGame.class differ diff --git a/bin/net/grosinger/nomads/MoneyPile.class b/bin/net/grosinger/nomads/MoneyPile.class new file mode 100644 index 0000000..f7687d8 Binary files /dev/null and b/bin/net/grosinger/nomads/MoneyPile.class differ diff --git a/bin/net/grosinger/nomads/Nomads.class b/bin/net/grosinger/nomads/Nomads.class index d37e9b2..886b26d 100644 Binary files a/bin/net/grosinger/nomads/Nomads.class and b/bin/net/grosinger/nomads/Nomads.class differ diff --git a/bin/net/grosinger/nomads/Objective.class b/bin/net/grosinger/nomads/Objective.class new file mode 100644 index 0000000..01b9dd2 Binary files /dev/null and b/bin/net/grosinger/nomads/Objective.class differ diff --git a/bin/net/grosinger/nomads/Point.class b/bin/net/grosinger/nomads/Point.class new file mode 100644 index 0000000..af2486f Binary files /dev/null and b/bin/net/grosinger/nomads/Point.class differ diff --git a/bin/net/grosinger/nomads/World.class b/bin/net/grosinger/nomads/World.class index 5a0d70c..82177ec 100644 Binary files a/bin/net/grosinger/nomads/World.class and b/bin/net/grosinger/nomads/World.class differ diff --git a/src/net/grosinger/nomads/DroneListItem.java b/src/net/grosinger/nomads/DroneListItem.java index c2896dd..a23b2ee 100644 --- a/src/net/grosinger/nomads/DroneListItem.java +++ b/src/net/grosinger/nomads/DroneListItem.java @@ -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); diff --git a/src/net/grosinger/nomads/DroneTeam.java b/src/net/grosinger/nomads/DroneTeam.java index e1603ce..730f1a8 100644 --- a/src/net/grosinger/nomads/DroneTeam.java +++ b/src/net/grosinger/nomads/DroneTeam.java @@ -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 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); } } diff --git a/src/net/grosinger/nomads/DroneTools.java b/src/net/grosinger/nomads/DroneTools.java index bb5b0ce..6d3ecb2 100644 --- a/src/net/grosinger/nomads/DroneTools.java +++ b/src/net/grosinger/nomads/DroneTools.java @@ -59,10 +59,7 @@ public class DroneTools { * @return Boolean - 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 Boolean - 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 Boolean - 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 Boolean - 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 boolean + */ + 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 Point + */ + 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 int - Team Balance + */ + public int getTeamBalance() { + return currentTeam.getBalance(); + } } diff --git a/src/net/grosinger/nomads/InitializeGame.java b/src/net/grosinger/nomads/InitializeGame.java index 1ec397c..2ae8980 100644 --- a/src/net/grosinger/nomads/InitializeGame.java +++ b/src/net/grosinger/nomads/InitializeGame.java @@ -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); + } + } } diff --git a/src/net/grosinger/nomads/MoneyPile.java b/src/net/grosinger/nomads/MoneyPile.java new file mode 100644 index 0000000..5867384 --- /dev/null +++ b/src/net/grosinger/nomads/MoneyPile.java @@ -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 int - 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)); + } + +} diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java index e0803b6..32ff7d9 100644 --- a/src/net/grosinger/nomads/Nomads.java +++ b/src/net/grosinger/nomads/Nomads.java @@ -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..."); diff --git a/src/net/grosinger/nomads/Objective.java b/src/net/grosinger/nomads/Objective.java new file mode 100644 index 0000000..f53592b --- /dev/null +++ b/src/net/grosinger/nomads/Objective.java @@ -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) { + + } + +} diff --git a/src/net/grosinger/nomads/Point.java b/src/net/grosinger/nomads/Point.java new file mode 100644 index 0000000..7151ff2 --- /dev/null +++ b/src/net/grosinger/nomads/Point.java @@ -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; + } +} diff --git a/src/net/grosinger/nomads/World.java b/src/net/grosinger/nomads/World.java index 96043dc..bc940ef 100644 --- a/src/net/grosinger/nomads/World.java +++ b/src/net/grosinger/nomads/World.java @@ -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 } } }