diff --git a/bin/net/grosinger/nomads/Building$Structure.class b/bin/net/grosinger/nomads/Building$Structure.class index 7065ade..2179df0 100644 Binary files a/bin/net/grosinger/nomads/Building$Structure.class and b/bin/net/grosinger/nomads/Building$Structure.class differ diff --git a/bin/net/grosinger/nomads/Building.class b/bin/net/grosinger/nomads/Building.class index 5c3d0fb..fd2ad2c 100644 Binary files a/bin/net/grosinger/nomads/Building.class and b/bin/net/grosinger/nomads/Building.class differ diff --git a/bin/net/grosinger/nomads/DroneListItem$Direction.class b/bin/net/grosinger/nomads/DroneListItem$Direction.class index 810fd9e..eb5ce2e 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 25ad3e6..7285ecf 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 89e9cfd..73453b3 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 7a9effc..b28ebb9 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 18740a2..fb203e4 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/House.class b/bin/net/grosinger/nomads/House.class new file mode 100644 index 0000000..0c10342 Binary files /dev/null and b/bin/net/grosinger/nomads/House.class differ diff --git a/bin/net/grosinger/nomads/Nomads.class b/bin/net/grosinger/nomads/Nomads.class index a1b3a25..ab6289c 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/World.class b/bin/net/grosinger/nomads/World.class index 7bcc59e..5a0d70c 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/Building.java b/src/net/grosinger/nomads/Building.java index 524b2d2..d95ef96 100644 --- a/src/net/grosinger/nomads/Building.java +++ b/src/net/grosinger/nomads/Building.java @@ -22,7 +22,7 @@ public class Building implements GameObject { // Houses will extend Buildings public enum Structure { - TOWNHALL, REPAIRSHOP, UPGRADESHOP, POLICESTATION + TOWNHALL, REPAIRSHOP, UPGRADESHOP, POLICESTATION, HOUSE } public Building(Structure thisBuilding, int newX, int newY) { @@ -44,6 +44,10 @@ public class Building implements GameObject { name = "PoliceStation"; break; } + case HOUSE: { + name = "House"; + break; + } } x = newX; diff --git a/src/net/grosinger/nomads/DroneListItem.java b/src/net/grosinger/nomads/DroneListItem.java index 11090e7..ad9ad27 100644 --- a/src/net/grosinger/nomads/DroneListItem.java +++ b/src/net/grosinger/nomads/DroneListItem.java @@ -16,6 +16,7 @@ public class DroneListItem { private DroneListItem next; private DroneListItem previous; private Drone current; + private DroneTeam team; /** * The DroneTools for this Drone @@ -50,12 +51,13 @@ public class DroneListItem { /* * Default constructor, includes all references */ - public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, Drone theCurrent) { + public DroneListItem(DroneListItem theNext, DroneListItem thePrevious, Drone theCurrent, DroneTeam theTeam) { next = theNext; previous = thePrevious; current = theCurrent; visibleDistance = 15; speed = 1; + team = theTeam; // Place itself in the world Nomads.awesomeWorld.placeNewDrone(this); @@ -195,6 +197,15 @@ public class DroneListItem { return y; } + /** + * Retrieve reference to the team this drone belongs to + * + * @return DroneTeam + */ + public DroneTeam getTeam() { + return team; + } + /** * Sets the next DroneListItem in the Linked List * @@ -351,7 +362,7 @@ public class DroneListItem { // Make the move Nomads.awesomeWorld.moveObjectAt(getX(), getY(), amountN, amountE); - + // Update the saved coordinates if (amountN != 0) setY(getY() + amountN); diff --git a/src/net/grosinger/nomads/DroneTeam.java b/src/net/grosinger/nomads/DroneTeam.java index a816847..26cf58f 100644 --- a/src/net/grosinger/nomads/DroneTeam.java +++ b/src/net/grosinger/nomads/DroneTeam.java @@ -1,5 +1,7 @@ package net.grosinger.nomads; +import java.util.ArrayList; + /** * Contains a pointer to the first and the last DroneListItem in a particular * team. When adding drones to Team A they should be added to the end of the @@ -27,6 +29,11 @@ public class DroneTeam { */ private int currentBalance; + /** + * ArrayList of all the houses owned by this team; + */ + private ArrayList teamHouses; + /** * Class Constructor * @@ -36,8 +43,7 @@ public class DroneTeam { public DroneTeam(DroneListItem firstList) { first = firstList; last = firstList; - teamName = firstList.getCurrent().getName(); - currentBalance = 0; + finishConstructing(); } /** @@ -47,11 +53,19 @@ public class DroneTeam { * GameObject that will be the first Drone */ public DroneTeam(GameObject firstDrone) { - DroneListItem firstList = new DroneListItem(null, null, (Drone) firstDrone); + DroneListItem firstList = new DroneListItem(null, null, (Drone) firstDrone, this); first = firstList; last = firstList; - teamName = firstDrone.getName(); + finishConstructing(); + } + + /** + * A few things that both constructors need, put into a different method. + */ + private void finishConstructing() { + teamName = first.getCurrent().getName(); currentBalance = 0; + teamHouses = new ArrayList(); } // Getters and Setters @@ -92,6 +106,15 @@ public class DroneTeam { return currentBalance; } + /** + * Retrieve the ArrayList of all the houses this team owns + * + * @return ArrayList (House) + */ + public ArrayList getTeamHouses() { + return teamHouses; + } + /** * Sets the first DroneListItem to that provided * diff --git a/src/net/grosinger/nomads/DroneTools.java b/src/net/grosinger/nomads/DroneTools.java index 51a8028..248232d 100644 --- a/src/net/grosinger/nomads/DroneTools.java +++ b/src/net/grosinger/nomads/DroneTools.java @@ -2,6 +2,8 @@ package net.grosinger.nomads; import java.util.ArrayList; +import net.grosinger.nomads.Building.Structure; + /** * Tools for the Drone to use. Only place methods in here that you want the * drone to have access to. @@ -55,7 +57,7 @@ public class DroneTools { * @return Boolean - can move */ public boolean canMoveNorth() { - if (getY() < worldSize-1) + if (getY() < worldSize - 1) return worldReference.getWorldGrid()[getX()][getY() + 1] == null; else return false; @@ -79,7 +81,7 @@ public class DroneTools { * @return Boolean - can move */ public boolean canMoveEast() { - if (getX() < worldSize-1) + if (getX() < worldSize - 1) return worldReference.getWorldGrid()[getX() + 1][getY()] == null; else return false; @@ -104,24 +106,25 @@ public class DroneTools { * @return Boolean - is Safe */ public boolean inSafeZone() { - return worldReference.inSafeZone(getX(), getY()); + return worldReference.inSafeZone(getX(), getY(), listItem); } - + /** - * Retrieve a list of all Drones that are visible within your sight range. (Sight range can be upgraded) + * Retrieve a list of all Drones that are visible within your sight range. + * (Sight range can be upgraded) * * @return ArrayList of Neighbors */ - public ArrayList checkRadar(){ + public ArrayList checkRadar() { ArrayList neighbors = new ArrayList(); int maxDistance = listItem.getVisibleDistance(); - for(int i = maxDistance * -1; i <= maxDistance; i++){ - for(int j = maxDistance * -1; j <= maxDistance; j++){ - if (getX() + i >= worldSize-1 || getX() + i < 0 || getY() + j >= worldSize-1 || getY() + j < 0) { + for (int i = maxDistance * -1; i <= maxDistance; i++) { + for (int j = maxDistance * -1; j <= maxDistance; j++) { + if (getX() + i >= worldSize - 1 || getX() + i < 0 || getY() + j >= worldSize - 1 || getY() + j < 0) { - } else if(i != 0 && j != 0) { - GameObject objectHere = worldReference.getObjectAt(getX()+i, getY()+j); - if(objectHere instanceof Drone){ //TODO - Not sure if this will work + } else if (i != 0 && j != 0) { + GameObject objectHere = worldReference.getObjectAt(getX() + i, getY() + j); + if (objectHere instanceof Drone) { Drone droneHere = (Drone) objectHere; DroneListItem listItemHere = Nomads.droneToListItem(droneHere); Neighbor aWildNeighbor = new Neighbor(listItemHere.getX(), listItemHere.getY(), droneHere.getName()); @@ -132,4 +135,29 @@ public class DroneTools { } return neighbors; } + + /** + * If your team has enough money, will create a house 1 space east of + * current location. + * + * @return Reference to the house so you can find it later. Will return null + * 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 { + House newHouse = new House(Structure.HOUSE, getX() + 1, getY(), referredDrone.getName()); + worldReference.placeNewBuilding(newHouse); + return newHouse; + } + + // TODO - Implement time to create house + // Building a house should take many turns. Their drone will remain + // immobile while house is constructed. + } } diff --git a/src/net/grosinger/nomads/House.java b/src/net/grosinger/nomads/House.java new file mode 100644 index 0000000..2001dbb --- /dev/null +++ b/src/net/grosinger/nomads/House.java @@ -0,0 +1,50 @@ +package net.grosinger.nomads; + +/** + * It is a house, just like it says. Basically a building that can be owned by a + * team + */ +public class House extends Building { + + private String team; + private int turnCreated; + + public House(Structure thisBuilding, int newX, int newY) { + super(thisBuilding, newX, newY); + turnCreated = Nomads.turn; + } + + public House(Structure thisBuilding, int newX, int newY, String teamName) { + super(thisBuilding, newX, newY); + team = teamName; + turnCreated = Nomads.turn; + } + + /** + * Retrieve the name of team that owns this house + * + * @return String + */ + public String getTeam() { + return team; + } + + /** + * Calculates the age of the house + * + * @return currentTurn - turnCreated + */ + public int getAge() { + return Nomads.turn - turnCreated; + } + + /** + * Sets the name of the team that owns this house + * + * @param newTeam + * String House owner + */ + public void setTeam(String newTeam) { + team = newTeam; + } +} diff --git a/src/net/grosinger/nomads/Nomads.java b/src/net/grosinger/nomads/Nomads.java index 6b63c56..96c3fdd 100644 --- a/src/net/grosinger/nomads/Nomads.java +++ b/src/net/grosinger/nomads/Nomads.java @@ -8,6 +8,7 @@ public class Nomads { public static World awesomeWorld; public static ArrayList allTeams = new ArrayList(); public static boolean running = true; + public static int turn; // Debugging Modes public static final boolean DEBUGSTATUS = true; @@ -23,6 +24,11 @@ public class Nomads { */ public static final int MAPGENRATE = 2; + /** + * How much should a house cost? + */ + public static final int HOUSEPRICE = 200; + public static void main(String[] args) { if (DEBUGSTATUS) System.out.println("Game initialization beginning..."); @@ -69,7 +75,7 @@ public class Nomads { if (DEBUGSTATUS) System.out.println("Game loop starting..."); - int turn = 0; + turn = 0; int counter = 0; while (running) { diff --git a/src/net/grosinger/nomads/World.java b/src/net/grosinger/nomads/World.java index db26d70..96043dc 100644 --- a/src/net/grosinger/nomads/World.java +++ b/src/net/grosinger/nomads/World.java @@ -165,7 +165,7 @@ public class World { * - Specified Y value * @return boolean */ - public boolean inSafeZone(int x, int y) { + public boolean inSafeZone(int x, int y, DroneListItem listItem) { /* * Safe Zones - Measured in radius of a square TownHall - 3 : RepairShop * - 2 : UpgradeShop - 2 : PoliceStation - 3 : Home - 1 @@ -186,11 +186,20 @@ public class World { } else if ((name.equalsIgnoreCase("RepairShop") || name.equalsIgnoreCase("UpgradeShop")) && i <= 2 && j <= 2) { return true; } - // TODO - Include Team Houses in the safe zone test } } } } + // Check to see if they are within the safe-zone of any of the team + // houses. Houses provide 1 radius around the building (total 3x3) + ArrayList teamHouses = listItem.getTeam().getTeamHouses(); + for (House currentHouse : teamHouses) { + int houseX = currentHouse.getX(); + int houseY = currentHouse.getY(); + if (houseX + 1 > x && houseX - 1 < x && houseY + 1 > y && houseY - 1 < y) { + return true; + } + } return false; } @@ -203,10 +212,10 @@ public class World { * - Y Index * @param range * - range to search - * @return Arraylist(building) + * @return ArrayList(building) */ public ArrayList buildingsInRange(int x, int y, int range) { - // TODO - implement buildingsInRange + // TODO - Implement buildingsInRange return null; } @@ -253,6 +262,8 @@ public class World { g2d.setColor(color); 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 g2d.setColor(Color.black); g2d.fillRect(j * 10, i * 10, 10, 10); }