-Created TownHall object
-Implemented Inventory -Started Objectives Signed-off-by: Tony Grosinger <github2@grosinger.net>
This commit is contained in:
parent
20e7ec66fe
commit
c7bf2268e8
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/net/grosinger/nomads/TownHall.class
Normal file
BIN
bin/net/grosinger/nomads/TownHall.class
Normal file
Binary file not shown.
Binary file not shown.
@ -1,16 +1,15 @@
|
||||
package net.grosinger.nomads;
|
||||
|
||||
/*
|
||||
* 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
|
||||
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
|
||||
*
|
||||
* +----------------------------------------------------------+
|
||||
* | Most of the inner workings of the program that we do not |
|
||||
* | want a drone to have access to will take place here |
|
||||
* +----------------------------------------------------------+
|
||||
* Most of the inner workings of the program that we do not want a drone to have
|
||||
* access to will take place here
|
||||
*
|
||||
* Previous --> Towards the first item
|
||||
* Next --> Towards the last item
|
||||
* Previous --> Towards the first item Next --> Towards the last item
|
||||
*/
|
||||
public class DroneListItem {
|
||||
private DroneListItem next;
|
||||
@ -31,7 +30,7 @@ public class DroneListItem {
|
||||
N, S, E, W
|
||||
}
|
||||
|
||||
// Stats about this robot
|
||||
// Statistics about this robot
|
||||
|
||||
private int visibleDistance;
|
||||
private int lumaLocatorDistance;
|
||||
@ -47,6 +46,8 @@ public class DroneListItem {
|
||||
private int age;
|
||||
private int x;
|
||||
private int y;
|
||||
private int waiting; // Is the drone building another drone or house?
|
||||
private ArrayList<GameObject> inventory;
|
||||
|
||||
/*
|
||||
* Default constructor, includes all references
|
||||
@ -58,6 +59,8 @@ public class DroneListItem {
|
||||
visibleDistance = 15;
|
||||
speed = 1;
|
||||
team = theTeam;
|
||||
waiting = 0;
|
||||
inventory = new ArrayList<GameObject>();
|
||||
|
||||
// Place itself in the world
|
||||
Nomads.awesomeWorld.placeNewDrone(this);
|
||||
@ -256,6 +259,16 @@ public class DroneListItem {
|
||||
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
|
||||
*
|
||||
@ -338,7 +351,12 @@ public class DroneListItem {
|
||||
|
||||
// Movement
|
||||
|
||||
public void moveDrone(Direction direction) {
|
||||
private void moveDrone(Direction direction) {
|
||||
if (waiting != 0) {
|
||||
waiting--;
|
||||
return;
|
||||
}
|
||||
|
||||
int amountN = 0;
|
||||
int amountE = 0;
|
||||
switch (direction) {
|
||||
@ -361,12 +379,13 @@ public class DroneListItem {
|
||||
}
|
||||
// Check to see if there is a MoneyPile or Objective there
|
||||
GameObject objectHere = Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN);
|
||||
if (objectHere instanceof MoneyPile) {
|
||||
int value = ((MoneyPile) objectHere).getValue();
|
||||
team.increaseBalance(value);
|
||||
Nomads.awesomeWorld.generateMoneyPile();
|
||||
} else if (objectHere instanceof Objective) {
|
||||
// TODO - Implement moving onto Objective
|
||||
|
||||
if (inventory.size() < cargoSpace) {
|
||||
if (objectHere instanceof MoneyPile || objectHere instanceof Objective) {
|
||||
inventory.add(objectHere);
|
||||
}
|
||||
} else {
|
||||
// TODO - Inventory is full, do not allow move
|
||||
}
|
||||
|
||||
// Make the move
|
||||
|
@ -165,13 +165,10 @@ public class DroneTools {
|
||||
House newHouse = new House(Structure.HOUSE, intendedPoint.getX(), intendedPoint.getY(), referredDrone.getName());
|
||||
worldReference.placeNewBuilding(newHouse);
|
||||
currentTeam.deductFromBalance(Nomads.HOUSEPRICE);
|
||||
listItem.setWaiting(Nomads.CREATIONTIME);
|
||||
return newHouse;
|
||||
} else
|
||||
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());
|
||||
currentTeam.createNewDrone(listItem, location);
|
||||
currentTeam.deductFromBalance(Nomads.DRONEPRICE);
|
||||
// TODO - Implement time to create new drone
|
||||
// Creating a drone should take many turns. Their drone will remain
|
||||
// immobile while drone is constructed.
|
||||
listItem.setWaiting(Nomads.CREATIONTIME);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,14 +62,12 @@ public class InitializeGame {
|
||||
|
||||
while (entries.hasMoreElements()) {
|
||||
JarEntry element = entries.nextElement();
|
||||
if (element.getName().endsWith(".class")) {
|
||||
if (element.getName().endsWith(className + ".class")) {
|
||||
try {
|
||||
@SuppressWarnings("rawtypes")
|
||||
Class c = clazzLoader.loadClass(element.getName().replaceAll(".class", "").replaceAll("/", "."));
|
||||
|
||||
// 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();
|
||||
newGameObject.setName(className);
|
||||
Drone newDrone = (Drone) newGameObject;
|
||||
@ -168,7 +166,7 @@ public class InitializeGame {
|
||||
* Generate the money piles and place them on the map
|
||||
*/
|
||||
public static void initializeMoneyPiles() {
|
||||
for(int i = 0; i < Nomads.MONEYPILES; i++){
|
||||
for (int i = 0; i < Nomads.MONEYPILES; i++) {
|
||||
MoneyPile newPile = new MoneyPile();
|
||||
Nomads.awesomeWorld.setObjectRandom(newPile);
|
||||
}
|
||||
|
@ -129,6 +129,12 @@ public class Nomads {
|
||||
return getWinner();
|
||||
}
|
||||
|
||||
/**
|
||||
* Output the winning messages
|
||||
*
|
||||
* @param winner
|
||||
* - The team that won
|
||||
*/
|
||||
public static void finishGame(DroneTeam winner) {
|
||||
if (winner == null)
|
||||
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());
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the last team alive, or the one with the most money
|
||||
*
|
||||
* @return <code>DroneTeam</code>
|
||||
*/
|
||||
public static DroneTeam getWinner() {
|
||||
// TODO - Implement getWinner
|
||||
return null;
|
||||
// When the last drone in the team is killed it will be removed from the
|
||||
// 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) {
|
||||
|
@ -1,15 +1,45 @@
|
||||
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 {
|
||||
// TODO - Implement Objective
|
||||
private int bounty;
|
||||
private String UID;
|
||||
private String name;
|
||||
|
||||
public Objective(int newBounty, String newUID) {
|
||||
bounty = newBounty;
|
||||
UID = newUID;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
public void setName(String newName) {
|
||||
|
||||
name = newName;
|
||||
}
|
||||
|
||||
}
|
||||
|
23
src/net/grosinger/nomads/TownHall.java
Normal file
23
src/net/grosinger/nomads/TownHall.java
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -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
|
||||
* X index of starting location
|
||||
@ -218,11 +219,11 @@ public class World {
|
||||
// TODO - Implement buildingsInRange
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Generates a new MoneyPile at random location
|
||||
*/
|
||||
public void generateMoneyPile(){
|
||||
public void generateMoneyPile() {
|
||||
MoneyPile newPile = new MoneyPile();
|
||||
setObjectRandom(newPile);
|
||||
}
|
||||
@ -274,11 +275,18 @@ public class World {
|
||||
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
|
||||
// World owned buildings should be black - use colorMap to
|
||||
// get color for each team
|
||||
g2d.setColor(Color.black);
|
||||
g2d.fillRect(j * 10, i * 10, 10, 10);
|
||||
} else if (objectHere instanceof MoneyPile) {
|
||||
// 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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user