Archived
1
0

-Created TownHall object

-Implemented Inventory
-Started Objectives

Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
Tony Grosinger 2011-05-19 17:22:54 -07:00
parent 20e7ec66fe
commit c7bf2268e8
16 changed files with 138 additions and 37 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,16 +1,15 @@
package net.grosinger.nomads; package net.grosinger.nomads;
/* 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 /**
* 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
* | Most of the inner workings of the program that we do not | * access to will take place here
* | want a drone to have access to will take place here |
* +----------------------------------------------------------+
* *
* Previous --> Towards the first item * Previous --> Towards the first item Next --> Towards the last item
* Next --> Towards the last item
*/ */
public class DroneListItem { public class DroneListItem {
private DroneListItem next; private DroneListItem next;
@ -31,7 +30,7 @@ public class DroneListItem {
N, S, E, W N, S, E, W
} }
// Stats about this robot // Statistics about this robot
private int visibleDistance; private int visibleDistance;
private int lumaLocatorDistance; private int lumaLocatorDistance;
@ -47,6 +46,8 @@ public class DroneListItem {
private int age; private int age;
private int x; private int x;
private int y; private int y;
private int waiting; // Is the drone building another drone or house?
private ArrayList<GameObject> inventory;
/* /*
* Default constructor, includes all references * Default constructor, includes all references
@ -58,6 +59,8 @@ public class DroneListItem {
visibleDistance = 15; visibleDistance = 15;
speed = 1; speed = 1;
team = theTeam; team = theTeam;
waiting = 0;
inventory = new ArrayList<GameObject>();
// Place itself in the world // Place itself in the world
Nomads.awesomeWorld.placeNewDrone(this); Nomads.awesomeWorld.placeNewDrone(this);
@ -256,6 +259,16 @@ public class DroneListItem {
y = newY; 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 * Increases the Visible Distance by specified amount
* *
@ -338,7 +351,12 @@ public class DroneListItem {
// Movement // Movement
public void moveDrone(Direction direction) { private void moveDrone(Direction direction) {
if (waiting != 0) {
waiting--;
return;
}
int amountN = 0; int amountN = 0;
int amountE = 0; int amountE = 0;
switch (direction) { switch (direction) {
@ -361,12 +379,13 @@ public class DroneListItem {
} }
// Check to see if there is a MoneyPile or Objective there // Check to see if there is a MoneyPile or Objective there
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN); GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
if (objectHere instanceof MoneyPile) {
int value = ((MoneyPile) objectHere).getValue(); if (inventory.size() < cargoSpace) {
team.increaseBalance(value); if (objectHere instanceof MoneyPile || objectHere instanceof Objective) {
Nomads.awesomeWorld.generateMoneyPile(); inventory.add(objectHere);
} else if (objectHere instanceof Objective) { }
// TODO - Implement moving onto Objective } else {
// TODO - Inventory is full, do not allow move
} }
// Make the move // Make the move

View File

@ -165,13 +165,10 @@ public class DroneTools {
House newHouse = new House(Structure.HOUSE, intendedPoint.getX(), intendedPoint.getY(), referredDrone.getName()); House newHouse = new House(Structure.HOUSE, intendedPoint.getX(), intendedPoint.getY(), referredDrone.getName());
worldReference.placeNewBuilding(newHouse); worldReference.placeNewBuilding(newHouse);
currentTeam.deductFromBalance(Nomads.HOUSEPRICE); currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
listItem.setWaiting(Nomads.CREATIONTIME);
return newHouse; return newHouse;
} else } else
return null; 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()); Point location = new Point(getX(), getY());
currentTeam.createNewDrone(listItem, location); currentTeam.createNewDrone(listItem, location);
currentTeam.deductFromBalance(Nomads.DRONEPRICE); currentTeam.deductFromBalance(Nomads.DRONEPRICE);
// TODO - Implement time to create new drone listItem.setWaiting(Nomads.CREATIONTIME);
// Creating a drone should take many turns. Their drone will remain
// immobile while drone is constructed.
} }
} }

View File

@ -62,14 +62,12 @@ public class InitializeGame {
while (entries.hasMoreElements()) { while (entries.hasMoreElements()) {
JarEntry element = entries.nextElement(); JarEntry element = entries.nextElement();
if (element.getName().endsWith(".class")) { if (element.getName().endsWith(className + ".class")) {
try { try {
@SuppressWarnings("rawtypes") @SuppressWarnings("rawtypes")
Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", ".")); Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", "."));
// Create new GameObject // 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(); GameObject newGameObject = (GameObject) c.newInstance();
newGameObject.setName(className); newGameObject.setName(className);
Drone newDrone = (Drone) newGameObject; Drone newDrone = (Drone) newGameObject;
@ -168,7 +166,7 @@ public class InitializeGame {
* Generate the money piles and place them on the map * Generate the money piles and place them on the map
*/ */
public static void initializeMoneyPiles() { public static void initializeMoneyPiles() {
for(int i = 0; i < Nomads.MONEYPILES; i++){ for (int i = 0; i < Nomads.MONEYPILES; i++) {
MoneyPile newPile = new MoneyPile(); MoneyPile newPile = new MoneyPile();
Nomads.awesomeWorld.setObjectRandom(newPile); Nomads.awesomeWorld.setObjectRandom(newPile);
} }

View File

@ -129,6 +129,12 @@ public class Nomads {
return getWinner(); return getWinner();
} }
/**
* Output the winning messages
*
* @param winner
* - The team that won
*/
public static void finishGame(DroneTeam winner) { public static void finishGame(DroneTeam winner) {
if (winner == null) if (winner == null)
System.out.println("There was no winner, please play again"); 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()); System.out.println("The winner was " + winner.getName());
} }
/**
* Find the last team alive, or the one with the most money
*
* @return <code>DroneTeam</code>
*/
public static DroneTeam getWinner() { public static DroneTeam getWinner() {
// TODO - Implement getWinner // When the last drone in the team is killed it will be removed from the
return null; // 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) { public static DroneListItem droneToListItem(Drone theDrone) {

View File

@ -1,15 +1,45 @@
package net.grosinger.nomads; 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 { 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 @Override
public String getName() { public String getName() {
return null; return name;
}
/**
* Return the bounty associated with this objective
*
* @return <code>int</code>
*/
public int getBounty() {
return bounty;
}
/**
* Return the UID of the Drone that can pick this Objective up
*
* @return <code>String</code>
*/
public String getUID() {
return UID;
} }
@Override @Override
public void setName(String newName) { public void setName(String newName) {
name = newName;
} }
} }

View File

@ -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<GameObject> 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
}
}
}
}

View File

@ -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 * @param startingX
* X index of starting location * X index of starting location
@ -218,11 +219,11 @@ public class World {
// TODO - Implement buildingsInRange // TODO - Implement buildingsInRange
return null; return null;
} }
/** /**
* Generates a new MoneyPile at random location * Generates a new MoneyPile at random location
*/ */
public void generateMoneyPile(){ public void generateMoneyPile() {
MoneyPile newPile = new MoneyPile(); MoneyPile newPile = new MoneyPile();
setObjectRandom(newPile); setObjectRandom(newPile);
} }
@ -274,11 +275,18 @@ public class World {
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 - Add color-coding to buildings on map // 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.setColor(Color.black);
g2d.fillRect(j * 10, i * 10, 10, 10); g2d.fillRect(j * 10, i * 10, 10, 10);
} else if (objectHere instanceof MoneyPile) { } else if (objectHere instanceof MoneyPile) {
// TODO - Implement mapping of MoneyPiles // 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
} }
} }
} }