Archived
1
0

-Created classes for additional building types

-Restructred how buildings are represented

Signed-off-by: Tony Grosinger <tony@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-09-13 15:12:14 -07:00
parent 73cd872900
commit a5e5999b4d
20 changed files with 88 additions and 61 deletions

View File

@ -5,7 +5,7 @@ A small Java based game where creating the A.I. is the fun part.
About
-----
Using the API (coming soon) and the [SampleDrone](https://github.com/tgrosinger/Nomads-Sample-Drone) create a drone of your own that can destroy all the other drones.
Using the [API](https://github.com/tgrosinger/Nomads/downloads) and the [SampleDrone](https://github.com/tgrosinger/Nomads-Sample-Drone) create a drone of your own that can destroy all the other drones.
A sucessful drone will be able to gather resources, avoid the law and other malicious drones, and even reproduce to increase it's forces.
Wiki

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -9,9 +9,6 @@ package net.grosinger.nomads;
* UpgradeShop - 2
* PoliceStation - 3
* Home - 1
*
*
*
*/
public class Building implements GameObject {
Structure structure;

View File

@ -155,9 +155,30 @@ public class DroneTools {
+ i, getY() + j);
if (objectHere instanceof Building) {
Building buildingHere = (Building) objectHere;
NeighborBuilding aWildNeighbor = new NeighborBuilding(
buildingHere.getX(), buildingHere.getY(),
buildingHere.getName(), buildingHere);
NeighborBuilding aWildNeighbor;
if (buildingHere.getType() == Structure.TOWNHALL) {
aWildNeighbor = new TownHall(buildingHere.getX(),
buildingHere.getY(),
buildingHere.getName(), buildingHere);
} else if (buildingHere.getType() == Structure.REPAIRSHOP) {
aWildNeighbor = new RepairShop(buildingHere.getX(),
buildingHere.getY(),
buildingHere.getName(), buildingHere);
} else if (buildingHere.getType() == Structure.UPGRADESHOP) {
aWildNeighbor = new UpgradeShop(
buildingHere.getX(), buildingHere.getY(),
buildingHere.getName(), buildingHere);
} else if (buildingHere.getType() == Structure.POLICESTATION) {
aWildNeighbor = new PoliceStation(
buildingHere.getX(), buildingHere.getY(),
buildingHere.getName(), buildingHere);
} else {
aWildNeighbor = new NeighborBuilding(
buildingHere.getX(), buildingHere.getY(),
buildingHere.getName(), buildingHere);
}
neighbors.add(aWildNeighbor);
}
}
@ -212,7 +233,7 @@ public class DroneTools {
findEmptyPoint(intendedPoint);
House newHouse = new House(Structure.HOUSE, intendedPoint.getX(),
intendedPoint.getY(), referredDrone.getName());
intendedPoint.getY(), currentTeam);
worldReference.placeNewBuilding(newHouse);
currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
listItem.setWaiting(Nomads.CREATIONTIME);

View File

@ -5,30 +5,13 @@ package net.grosinger.nomads;
* team
*/
public class House extends Building {
private String team;
private int turnCreated;
public House(Structure thisBuilding, int newX, int newY) {
super(thisBuilding, newX, newY);
public House(Structure thisBuilding, int newX, int newY, DroneTeam team) {
super(thisBuilding, newX, newY, team);
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
*
@ -37,14 +20,4 @@ public class House extends Building {
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

@ -29,7 +29,8 @@ public class InitializeGame {
* @throws IOException
* @throws ClassNotFoundException
*/
public static void initializeDrones() throws ClassNotFoundException, IOException {
public static void initializeDrones() throws ClassNotFoundException,
IOException {
if (Nomads.DEBUGSTATUS)
System.out.println("Loading the drones into world...");
/*
@ -52,9 +53,11 @@ public class InitializeGame {
if (Nomads.DEBUGSTATUS)
System.out.println("Loading " + filename);
File file = new File(System.getProperty("user.dir") + "/drones/" + filename);
File file = new File(System.getProperty("user.dir") + "/drones/"
+ filename);
URLClassLoader clazzLoader = URLClassLoader.newInstance(new URL[] { file.toURI().toURL() });
URLClassLoader clazzLoader = URLClassLoader
.newInstance(new URL[] { file.toURI().toURL() });
// System.class.getClassLoader()
JarFile jarFile = new JarFile(file);
@ -65,7 +68,8 @@ public class InitializeGame {
if (element.getName().endsWith(className + ".class")) {
try {
@SuppressWarnings("rawtypes")
Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", "."));
Class c = clazzLoader.loadClass(element.getName()
.replaceAll(".class", "").replaceAll("/", "."));
// Create new GameObject
GameObject newGameObject = (GameObject) c.newInstance();
@ -145,10 +149,11 @@ public class InitializeGame {
if (Nomads.DEBUGSTATUS)
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);
Building townHall = new Building(Structure.TOWNHALL, 30, 40, null);
Building upgradeShop = new Building(Structure.UPGRADESHOP, 30, 60, null);
Building policeStation = new Building(Structure.POLICESTATION, 50, 40,
null);
Building RepairShop = new Building(Structure.REPAIRSHOP, 50, 60, null);
if (Nomads.DEBUGSTATUS)
System.out.println("Building generation complete");

View File

@ -1,7 +1,5 @@
package net.grosinger.nomads;
import net.grosinger.nomads.Building.Structure;
/**
* An array of NeigborBuildings will be given to a drone that is searching for
* the buildings it is near. This is typically done from the town center.
@ -53,15 +51,6 @@ public class NeighborBuilding implements GameObject {
return y;
}
/**
* Retrieve type of building that this is
*
* @return <code>Structure</code>
*/
public Structure getType() {
return building.getType();
}
/**
* Retrieve the name of the team that owns the current building. If the
* building is a public building, the string will be "Public".

View File

@ -0,0 +1,13 @@
package net.grosinger.nomads;
/**
* A representation of a PoliceStation. Allows Drones to interact with this
* building.
*/
public class PoliceStation extends NeighborBuilding {
public PoliceStation(int x, int y, String name, Building building) {
super(x, y, name, building);
}
}

View File

@ -0,0 +1,13 @@
package net.grosinger.nomads;
/**
* A representation of a RepairShop. Allows Drones to interact with this
* building.
*/
public class RepairShop extends NeighborBuilding {
public RepairShop(int x, int y, String name, Building building) {
super(x, y, name, building);
}
}

View File

@ -2,10 +2,13 @@ package net.grosinger.nomads;
import java.util.ArrayList;
public class TownHall extends Building {
/**
* A representation of a TownHall. Allows Drones to interact with this building.
*/
public class TownHall extends NeighborBuilding {
public TownHall(int newX, int newY) {
super(Structure.TOWNHALL, newX, newY);
public TownHall(int x, int y, String name, Building building) {
super(x, y, name, building);
}
public void cashInventory(ArrayList<GameObject> inventory, DroneTeam team) {
@ -21,8 +24,8 @@ public class TownHall extends Building {
inventory.remove(currentObject);
}
}
public Point requestNewObjective(String UID){
public Point requestNewObjective(String UID) {
return Nomads.awesomeWorld.generateObjective(UID);
}
}

View File

@ -0,0 +1,13 @@
package net.grosinger.nomads;
/**
* A representation of an UpgradeShop. Allows Drones to interact with this
* building.
*/
public class UpgradeShop extends NeighborBuilding {
public UpgradeShop(int x, int y, String name, Building building) {
super(x, y, name, building);
}
}