Archived
1
0

-Added to building class

-Buildings now generated and placed on map
-Maps only generated on interval
-Fixed grid lines (I think)

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-04-25 22:27:19 -07:00
parent db1b945815
commit b53eec8a61
11 changed files with 112 additions and 17 deletions

Binary file not shown.

View File

@ -17,13 +17,15 @@ public class Building implements GameObject {
Structure structure; Structure structure;
String name; String name;
// Can't decide if I want to add Drone Houses as another enum item or as a int x;
// separate class that extends Building int y;
// Houses will extend Buildings
public enum Structure { public enum Structure {
TOWNHALL, REPAIRSHOP, UPGRADESHOP, POLICESTATION TOWNHALL, REPAIRSHOP, UPGRADESHOP, POLICESTATION
} }
public Building(Structure thisBuilding) { public Building(Structure thisBuilding, int newX, int newY) {
structure = thisBuilding; structure = thisBuilding;
switch (structure) { switch (structure) {
case TOWNHALL: { case TOWNHALL: {
@ -43,6 +45,9 @@ public class Building implements GameObject {
break; break;
} }
} }
x = newX;
y = newY;
} }
@Override @Override
@ -50,11 +55,58 @@ public class Building implements GameObject {
return name; return name;
} }
/**
* Retrieve what type of building it is (I.E. TownHall, RepairShop, etc.)
*
* @return <code>Structure</code>
*/
public Structure getType() {
return structure;
}
/**
* Retrieve x index
*
* return <code>int</code>
*/
public int getX() {
return x;
}
/**
* Retrieve y index
*
* @return <code>int</code>
*/
public int getY() {
return y;
}
@Override @Override
public void setName(String newName) { public void setName(String newName) {
name = newName; name = newName;
} }
/**
* Sets a new x value for the building (As if buildings could move)
*
* @param newX
* - int, new x location
*/
public void setX(int newX) {
x = newX;
}
/**
* Sets a new y value for the building (As if buildings could move)
*
* @param newY
* - int, new y location
*/
public void setY(int newY) {
y = newY;
}
/* /*
* Information about how to use the switch command with enums * Information about how to use the switch command with enums
* http://download.oracle.com/javase/tutorial/java/javaOO/enum.html * http://download.oracle.com/javase/tutorial/java/javaOO/enum.html

View File

@ -38,7 +38,6 @@ public class DroneListItem {
private int reliability; private int reliability;
private int defenses; private int defenses;
private int speed; // Reflected in movements per turn private int speed; // Reflected in movements per turn
private int turning;
private int cargoSpace; private int cargoSpace;
private int theft; private int theft;
@ -149,15 +148,6 @@ public class DroneListItem {
return speed; return speed;
} }
/**
* Retrieve the turning factor of this drone
*
* @return <code>int</code>
*/
public int getTurning() {
return turning;
}
/** /**
* Retrieve the total space in the cargo hold of this drone. Does include * Retrieve the total space in the cargo hold of this drone. Does include
* *

View File

@ -10,6 +10,8 @@ import java.util.Enumeration;
import java.util.jar.JarEntry; import java.util.jar.JarEntry;
import java.util.jar.JarFile; import java.util.jar.JarFile;
import net.grosinger.nomads.Building.Structure;
/** /**
* Various methods used when first setting up the game and loading everything * Various methods used when first setting up the game and loading everything
* into the world. * into the world.
@ -145,9 +147,19 @@ public class InitializeGame {
if (Nomads.DEBUGSTATUS) if (Nomads.DEBUGSTATUS)
System.out.println("Generating and placing required buildings..."); System.out.println("Generating and placing required buildings...");
Building townHall = new Building(Structure.TOWNHALL, 30, 40);
Building upgradeShop = new Building(Structure.UPGRADESHOP, 30, 60);
Building policeStation = new Building(Structure.POLICESTATION, 50, 40);
Building RepairShop = new Building(Structure.REPAIRSHOP, 50, 60);
if (Nomads.DEBUGSTATUS) if (Nomads.DEBUGSTATUS)
System.out.println("Building generation complete"); System.out.println("Building generation complete");
awesomeWorld.placeNewBuilding(townHall);
awesomeWorld.placeNewBuilding(upgradeShop);
awesomeWorld.placeNewBuilding(policeStation);
awesomeWorld.placeNewBuilding(RepairShop);
if (Nomads.DEBUGSTATUS) if (Nomads.DEBUGSTATUS)
System.out.println("Building placement complete"); System.out.println("Building placement complete");
} }

View File

@ -17,6 +17,12 @@ public class Nomads {
public static final boolean DEBUGCREATIONS = true; public static final boolean DEBUGCREATIONS = true;
public static final boolean DEBUGBUILDINGS = true; public static final boolean DEBUGBUILDINGS = true;
/**
* How frequently should a new map be generated? (In turns, 1 means every
* turn)
*/
public static final int MAPGENRATE = 2;
public static void main(String[] args) { public static void main(String[] args) {
if (DEBUGSTATUS) if (DEBUGSTATUS)
System.out.println("Game initialization beginning..."); System.out.println("Game initialization beginning...");
@ -64,9 +70,10 @@ public class Nomads {
System.out.println("Game loop starting..."); System.out.println("Game loop starting...");
int turn = 0; int turn = 0;
int counter = 0;
while (running) { while (running) {
counter++;
turn++; turn++;
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
@ -80,7 +87,11 @@ public class Nomads {
if (DEBUGSTATUS) if (DEBUGSTATUS)
System.out.println("Moves took " + (endTime - startTime) + "milliseconds"); System.out.println("Moves took " + (endTime - startTime) + "milliseconds");
awesomeWorld.generateMap(turn); // Create a new map
if (counter == MAPGENRATE) {
awesomeWorld.generateMap(turn);
counter = 0;
}
try { try {
Thread.sleep(200); Thread.sleep(200);

View File

@ -143,6 +143,19 @@ public class World {
setObjectAt(lastUsedX, 20, newDrone.getCurrent()); setObjectAt(lastUsedX, 20, newDrone.getCurrent());
} }
/**
* Places a building in the world
*
* @param newBuilding
* The building to be placed
*/
public void placeNewBuilding(Building newBuilding) {
int x = newBuilding.getX();
int y = newBuilding.getY();
theWorld[x][y] = newBuilding;
}
/** /**
* Returns if the Drone at given coordinates is in a safe zone * Returns if the Drone at given coordinates is in a safe zone
* *
@ -181,6 +194,22 @@ public class World {
return false; return false;
} }
/**
* Searches for any buildings within range spaces of x,y
*
* @param x
* - X Index
* @param y
* - Y Index
* @param range
* - range to search
* @return <code>Arraylist(building)</code>
*/
public ArrayList<Building> buildingsInRange(int x, int y, int range) {
// TODO - implement buildingsInRange
return null;
}
/** /**
* Outputs an HTML file showing the world * Outputs an HTML file showing the world
*/ */
@ -209,7 +238,7 @@ public class World {
// draw grid lines // draw grid lines
g2d.setColor(Color.black); g2d.setColor(Color.black);
for (int i = 10; i <= 1000; i += 100) { for (int i = 0; i <= 1000; i += 100) {
g2d.drawLine(i, 0, i, 1000); g2d.drawLine(i, 0, i, 1000);
g2d.drawLine(0, i, 1000, i); g2d.drawLine(0, i, 1000, i);
} }
@ -224,7 +253,8 @@ public class World {
g2d.setColor(color); g2d.setColor(color);
g2d.fillOval(j * 10, i * 10, 10, 10); g2d.fillOval(j * 10, i * 10, 10, 10);
} else if (objectHere instanceof Building) { } else if (objectHere instanceof Building) {
// TODO - output for buildings g2d.setColor(Color.black);
g2d.fillRect(j * 10, i * 10, 10, 10);
} }
} }
} }