Archived
1
0

-Added houses

-Almost finished with adding ability to build a house
-Houses included in safezone if they are on the same team

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-04-26 12:59:04 -07:00
parent b53eec8a61
commit 4f7140b45a
17 changed files with 157 additions and 24 deletions

Binary file not shown.

Binary file not shown.

View File

@ -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;

View File

@ -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 <code>DroneTeam</code>
*/
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);

View File

@ -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<House> 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 {
* <code>GameObject</code> 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<House>();
}
// Getters and Setters
@ -92,6 +106,15 @@ public class DroneTeam {
return currentBalance;
}
/**
* Retrieve the ArrayList of all the houses this team owns
*
* @return <code>ArrayList (House)</code>
*/
public ArrayList<House> getTeamHouses() {
return teamHouses;
}
/**
* Sets the first DroneListItem to that provided
*

View File

@ -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 <code>Boolean</code> - 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 <code>Boolean</code> - 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 <code>Boolean</code> - 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<Neighbor> checkRadar(){
public ArrayList<Neighbor> checkRadar() {
ArrayList<Neighbor> neighbors = new ArrayList<Neighbor>();
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.
}
}

View File

@ -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 <code>String</code>
*/
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
* <code>String</code> House owner
*/
public void setTeam(String newTeam) {
team = newTeam;
}
}

View File

@ -8,6 +8,7 @@ public class Nomads {
public static World awesomeWorld;
public static ArrayList<DroneTeam> allTeams = new ArrayList<DroneTeam>();
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) {

View File

@ -165,7 +165,7 @@ public class World {
* - Specified Y value
* @return <code>boolean</code>
*/
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<House> 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 <code>Arraylist(building)</code>
* @return <code>ArrayList(building)</code>
*/
public ArrayList<Building> 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);
}