diff --git a/bin/net/grosinger/nomads/DroneListItem$Direction.class b/bin/net/grosinger/nomads/DroneListItem$Direction.class index eb5ce2e..810fd9e 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem$Direction.class and b/bin/net/grosinger/nomads/DroneListItem$Direction.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem$EnumMove.class b/bin/net/grosinger/nomads/DroneListItem$EnumMove.class index 7285ecf..25ad3e6 100644 Binary files a/bin/net/grosinger/nomads/DroneListItem$EnumMove.class and b/bin/net/grosinger/nomads/DroneListItem$EnumMove.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem.class b/bin/net/grosinger/nomads/DroneListItem.class index 5590327..6e1b8dd 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/DroneTools.class b/bin/net/grosinger/nomads/DroneTools.class index c73747e..0df9340 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 86a1557..fe91f23 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/Nomads.class b/bin/net/grosinger/nomads/Nomads.class index 886b26d..b788f22 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 index 01b9dd2..fa37cb9 100644 Binary files a/bin/net/grosinger/nomads/Objective.class and b/bin/net/grosinger/nomads/Objective.class differ diff --git a/bin/net/grosinger/nomads/TownHall.class b/bin/net/grosinger/nomads/TownHall.class new file mode 100644 index 0000000..d52809e Binary files /dev/null and b/bin/net/grosinger/nomads/TownHall.class differ diff --git a/bin/net/grosinger/nomads/World.class b/bin/net/grosinger/nomads/World.class index 82177ec..ce036e1 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 a23b2ee..bb09600 100644 --- a/src/net/grosinger/nomads/DroneListItem.java +++ b/src/net/grosinger/nomads/DroneListItem.java @@ -1,16 +1,15 @@ package net.grosinger.nomads; -/* - * A class that allows a drone to be part of a linked list - * Provides reference to the next drone, the previous drone, and the drone object +import java.util.ArrayList; + +/** + * A class that allows a drone to be part of a linked list Provides reference to + * the next drone, the previous drone, and the drone object * - * +----------------------------------------------------------+ - * | Most of the inner workings of the program that we do not | - * | want a drone to have access to will take place here | - * +----------------------------------------------------------+ + * Most of the inner workings of the program that we do not want a drone to have + * access to will take place here * - * Previous --> Towards the first item - * Next --> Towards the last item + * Previous --> Towards the first item Next --> Towards the last item */ public class DroneListItem { private DroneListItem next; @@ -31,7 +30,7 @@ public class DroneListItem { N, S, E, W } - // Stats about this robot + // Statistics about this robot private int visibleDistance; private int lumaLocatorDistance; @@ -47,6 +46,8 @@ public class DroneListItem { private int age; private int x; private int y; + private int waiting; // Is the drone building another drone or house? + private ArrayList inventory; /* * Default constructor, includes all references @@ -58,6 +59,8 @@ public class DroneListItem { visibleDistance = 15; speed = 1; team = theTeam; + waiting = 0; + inventory = new ArrayList(); // Place itself in the world Nomads.awesomeWorld.placeNewDrone(this); @@ -256,6 +259,16 @@ public class DroneListItem { y = newY; } + /** + * Adds the existing waiting time (which should be 0) to the provided time + * + * @param newWaiting + * - Amount of time to add to waiting timer + */ + public void setWaiting(int newWaiting) { + waiting += newWaiting; + } + /** * Increases the Visible Distance by specified amount * @@ -338,7 +351,12 @@ public class DroneListItem { // Movement - public void moveDrone(Direction direction) { + private void moveDrone(Direction direction) { + if (waiting != 0) { + waiting--; + return; + } + int amountN = 0; int amountE = 0; switch (direction) { @@ -361,12 +379,13 @@ public class DroneListItem { } // 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 + + if (inventory.size() < cargoSpace) { + if (objectHere instanceof MoneyPile || objectHere instanceof Objective) { + inventory.add(objectHere); + } + } else { + // TODO - Inventory is full, do not allow move } // Make the move diff --git a/src/net/grosinger/nomads/DroneTools.java b/src/net/grosinger/nomads/DroneTools.java index 6d3ecb2..dc23b7e 100644 --- a/src/net/grosinger/nomads/DroneTools.java +++ b/src/net/grosinger/nomads/DroneTools.java @@ -165,13 +165,10 @@ public class DroneTools { House newHouse = new House(Structure.HOUSE, intendedPoint.getX(), intendedPoint.getY(), referredDrone.getName()); worldReference.placeNewBuilding(newHouse); currentTeam.deductFromBalance(Nomads.HOUSEPRICE); + listItem.setWaiting(Nomads.CREATIONTIME); 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. } /** @@ -182,9 +179,7 @@ public class DroneTools { 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 - // immobile while drone is constructed. + listItem.setWaiting(Nomads.CREATIONTIME); } } diff --git a/src/net/grosinger/nomads/InitializeGame.java b/src/net/grosinger/nomads/InitializeGame.java index 2ae8980..7f59baf 100644 --- a/src/net/grosinger/nomads/InitializeGame.java +++ b/src/net/grosinger/nomads/InitializeGame.java @@ -62,14 +62,12 @@ public class InitializeGame { while (entries.hasMoreElements()) { JarEntry element = entries.nextElement(); - if (element.getName().endsWith(".class")) { + if (element.getName().endsWith(className + ".class")) { try { @SuppressWarnings("rawtypes") Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", ".")); // Create new GameObject - // TODO - This will break if it loads a class from a jar - // that does not extend Drone GameObject newGameObject = (GameObject) c.newInstance(); newGameObject.setName(className); Drone newDrone = (Drone) newGameObject; @@ -168,7 +166,7 @@ public class InitializeGame { * Generate the money piles and place them on the map */ public static void initializeMoneyPiles() { - for(int i = 0; i < Nomads.MONEYPILES; i++){ + for (int i = 0; i < Nomads.MONEYPILES; i++) { MoneyPile newPile = new MoneyPile(); Nomads.awesomeWorld.setObjectRandom(newPile); } diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java index 32ff7d9..d51a453 100644 --- a/src/net/grosinger/nomads/Nomads.java +++ b/src/net/grosinger/nomads/Nomads.java @@ -129,6 +129,12 @@ public class Nomads { return getWinner(); } + /** + * Output the winning messages + * + * @param winner + * - The team that won + */ public static void finishGame(DroneTeam winner) { if (winner == null) System.out.println("There was no winner, please play again"); @@ -136,9 +142,31 @@ public class Nomads { System.out.println("The winner was " + winner.getName()); } + /** + * Find the last team alive, or the one with the most money + * + * @return DroneTeam + */ public static DroneTeam getWinner() { - // TODO - Implement getWinner - return null; + // When the last drone in the team is killed it will be removed from the + // list + + // If there is only 1 drone left, it is the winner + if (allTeams.size() == 1) + return allTeams.get(0); + else if (allTeams.isEmpty()) { + // No winner, this probably won't happen + return null; + } else { + // There were multiple teams left, check their balances + DroneTeam winner = null; + int highestBalance = 0; + for (DroneTeam team : allTeams) { + if (team.getBalance() > highestBalance) + winner = team; + } + return winner; + } } public static DroneListItem droneToListItem(Drone theDrone) { diff --git a/src/net/grosinger/nomads/Objective.java b/src/net/grosinger/nomads/Objective.java index f53592b..790afa4 100644 --- a/src/net/grosinger/nomads/Objective.java +++ b/src/net/grosinger/nomads/Objective.java @@ -1,15 +1,45 @@ package net.grosinger.nomads; +/** + * A goal for a drone to collect. Holds a monetary reward if returned to a + * TownCenter by the Drone that issued it. + */ public class Objective implements GameObject { - // TODO - Implement Objective + private int bounty; + private String UID; + private String name; + + public Objective(int newBounty, String newUID) { + bounty = newBounty; + UID = newUID; + } + @Override public String getName() { - return null; + return name; + } + + /** + * Return the bounty associated with this objective + * + * @return int + */ + public int getBounty() { + return bounty; + } + + /** + * Return the UID of the Drone that can pick this Objective up + * + * @return String + */ + public String getUID() { + return UID; } @Override public void setName(String newName) { - + name = newName; } } diff --git a/src/net/grosinger/nomads/TownHall.java b/src/net/grosinger/nomads/TownHall.java new file mode 100644 index 0000000..23647d3 --- /dev/null +++ b/src/net/grosinger/nomads/TownHall.java @@ -0,0 +1,23 @@ +package net.grosinger.nomads; + +import java.util.ArrayList; + +public class TownHall extends Building { + + public TownHall(int newX, int newY) { + super(Structure.TOWNHALL, newX, newY); + } + + public void cashInventory(ArrayList inventory, DroneTeam team) { + while (!inventory.isEmpty()) { + GameObject currentObject = inventory.get(0); + if (currentObject instanceof MoneyPile) { + int value = ((MoneyPile) currentObject).getValue(); + team.increaseBalance(value); + Nomads.awesomeWorld.generateMoneyPile(); + } else if (currentObject instanceof Objective) { + // TODO - Implement turning in objective + } + } + } +} diff --git a/src/net/grosinger/nomads/World.java b/src/net/grosinger/nomads/World.java index bc940ef..2ad9020 100644 --- a/src/net/grosinger/nomads/World.java +++ b/src/net/grosinger/nomads/World.java @@ -46,7 +46,8 @@ public class World { } /** - * Moves the object at x, y by the specified amount + * Moves the object at x, y by the specified amount. If there is already an + * object there it will overwrite that object. * * @param startingX * X index of starting location @@ -218,11 +219,11 @@ public class World { // TODO - Implement buildingsInRange return null; } - + /** * Generates a new MoneyPile at random location */ - public void generateMoneyPile(){ + public void generateMoneyPile() { MoneyPile newPile = new MoneyPile(); setObjectRandom(newPile); } @@ -274,11 +275,18 @@ public class World { g2d.fillOval(j * 10, i * 10, 10, 10); } else if (objectHere instanceof Building) { // TODO - Add color-coding to buildings on map - // World owned buildings should be black + // World owned buildings should be black - use colorMap to + // get color for each team g2d.setColor(Color.black); g2d.fillRect(j * 10, i * 10, 10, 10); } else if (objectHere instanceof MoneyPile) { // TODO - Implement mapping of MoneyPiles + // Should be black since they are world owned but a + // different shape than anything else + } else if (objectHere instanceof Objective) { + // TODO - Implement mapping of Objective + // Should be black since they are world owned but a + // different shape than anything else } } }