-Major overhaul of design. Now using interfaces rather than extending
-Added DroneTools to allow a Drone to find out necessary information -Prevented drone from accessing information it shouldn't get -Changed moving again -More stuff that I have forgotten by now
This commit is contained in:
parent
a2bb46503c
commit
70a933ac09
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/net/grosinger/nomads/DroneListItem$Direction.class
Normal file
BIN
bin/net/grosinger/nomads/DroneListItem$Direction.class
Normal file
Binary file not shown.
BIN
bin/net/grosinger/nomads/DroneListItem$EnumMove.class
Normal file
BIN
bin/net/grosinger/nomads/DroneListItem$EnumMove.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
bin/net/grosinger/nomads/DroneTools.class
Normal file
BIN
bin/net/grosinger/nomads/DroneTools.class
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4
sql_info.txt
Normal file
4
sql_info.txt
Normal file
@ -0,0 +1,4 @@
|
||||
redundan_nomadswiki
|
||||
|
||||
redundan_nomads
|
||||
QQ[1_)gT5ST_!RZC^.
|
@ -3,8 +3,9 @@ package net.grosinger.nomads;
|
||||
/*
|
||||
* Anything that is on the theWorld that is not a drone of some sort is a building
|
||||
*/
|
||||
public class Building extends GameObject {
|
||||
public class Building implements GameObject {
|
||||
Structure structure;
|
||||
String name;
|
||||
|
||||
// Can't decide if I want to add Drone Houses as another enum item or as a
|
||||
// separate class that extends Building
|
||||
@ -16,6 +17,16 @@ public class Building extends GameObject {
|
||||
structure = thisBuilding;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setName(String newName) {
|
||||
name = newName;
|
||||
}
|
||||
|
||||
/*
|
||||
* Information about how to use the switch command with enums
|
||||
* http://download.oracle.com/javase/tutorial/java/javaOO/enum.html
|
||||
|
@ -6,134 +6,21 @@ import net.grosinger.nomads.DroneListItem.EnumMove;
|
||||
* All drones will extend this class. Gives them access to basic set of tools
|
||||
* they need such as movement, discovery, and world interaction.
|
||||
*/
|
||||
public class Drone extends GameObject {
|
||||
private int age;
|
||||
public interface Drone extends GameObject {
|
||||
|
||||
/**
|
||||
* Class constructor All custom drones should call their super constructor
|
||||
* at the end of their own.
|
||||
* This will give you a set of tools that will provide you will all the
|
||||
* basic info your drone needs.
|
||||
*/
|
||||
public Drone() {
|
||||
if (Nomads.DEBUGSTATUS)
|
||||
System.out.println("Drone initialized");
|
||||
}
|
||||
public void setDroneTools(DroneTools yourTools);
|
||||
|
||||
// Moving
|
||||
// When moving, North is positive Y axis and East is positive X axis
|
||||
|
||||
/**
|
||||
* Starts the move, can be used to perform maintenance operations before the actual move
|
||||
*/
|
||||
public final EnumMove getMove() {
|
||||
if (Nomads.DEBUGMOVES)
|
||||
System.out.println("Drone " + name + " moving");
|
||||
return move();
|
||||
}
|
||||
|
||||
/**
|
||||
* The main move method for all Drones. Custom Drones should override this
|
||||
* with their own.
|
||||
*/
|
||||
public EnumMove move() {
|
||||
return EnumMove.NoMove;
|
||||
}
|
||||
public EnumMove move();
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Checks to see if the drone can move North
|
||||
*
|
||||
* @param amount
|
||||
* of Distance to travel
|
||||
* @return True if the move is possible, false if is invalid
|
||||
*/
|
||||
public final boolean canMoveNorth() {
|
||||
return canMoveHelper(1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the drone can move South
|
||||
*
|
||||
* @param amount
|
||||
* of Distance to travel
|
||||
* @return True if the move is possible, false if is invalid
|
||||
*/
|
||||
public final boolean canMoveSouth() {
|
||||
return canMoveHelper(-1, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the drone can move East
|
||||
*
|
||||
* @param amount
|
||||
* of Distance to travel
|
||||
* @return True if the move is possible, false if is invalid
|
||||
*/
|
||||
public final boolean canMoveEast() {
|
||||
return canMoveHelper(0, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the drone can move West
|
||||
*
|
||||
* @param amount
|
||||
* of Distance to travel
|
||||
* @return True if the move is possible, false if is invalid
|
||||
*/
|
||||
public final boolean canMoveWest() {
|
||||
return canMoveHelper(0, -1);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param amountN
|
||||
* The amount of desired travel North (negative will go South)
|
||||
* @param amountE
|
||||
* The amount of desired travel East (negative will go West)
|
||||
* @return True if the move is possible, false if is invalid
|
||||
*/
|
||||
private final boolean canMoveHelper(int amountN, int amountE) {
|
||||
int size = Nomads.awesomeWorld.getWorldSize();
|
||||
if (getY() + amountN >= size || getY() + amountN < 0 || getX() + amountE >= size || getX() + amountE < 0) {
|
||||
if (Nomads.DEBUGMOVES)
|
||||
System.out.println("Cannot move, out of range");
|
||||
return false;
|
||||
} else if (Nomads.awesomeWorld.getObjectAt(getX() + amountE, getY() + amountN) != null) {
|
||||
if (Nomads.DEBUGMOVES)
|
||||
System.out.println("Cannot move, space occupied");
|
||||
return false;
|
||||
} else {
|
||||
if (Nomads.DEBUGMOVES)
|
||||
System.out.println("Can move");
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
|
||||
/**
|
||||
* Returns how many turns this drone has been alive
|
||||
*
|
||||
* @return How many turns this drone has been alive
|
||||
*/
|
||||
public final int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
// TODO - find a way to prevent the drone from accessing this
|
||||
/**
|
||||
* Do not use under normal circumstances
|
||||
*
|
||||
* @param newAge
|
||||
* Age to set as the Drone's current age
|
||||
*/
|
||||
public final void setAge(int newAge) {
|
||||
age = newAge;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the age of the drone by 1 turn
|
||||
*/
|
||||
public final void incrementAge() {
|
||||
age++;
|
||||
}
|
||||
}
|
||||
|
@ -17,8 +17,17 @@ public class DroneListItem {
|
||||
private DroneListItem previous;
|
||||
private Drone current;
|
||||
|
||||
/**
|
||||
* The DroneTools for this Drone
|
||||
*/
|
||||
private DroneTools yourTools;
|
||||
|
||||
public enum EnumMove {
|
||||
NoMove, North, South, East, West, Upgrade, Attack
|
||||
NoMove, North, South, East, West, Upgrade, Attack, Steal
|
||||
}
|
||||
|
||||
public enum Direction {
|
||||
N, S, E, W
|
||||
}
|
||||
|
||||
// Stats about this robot
|
||||
@ -31,6 +40,13 @@ public class DroneListItem {
|
||||
private int speed; // Reflected in movements per turn
|
||||
private int turning;
|
||||
private int cargoSpace;
|
||||
private int theft;
|
||||
|
||||
// Info about this robot
|
||||
|
||||
private int age;
|
||||
private int x;
|
||||
private int y;
|
||||
|
||||
/*
|
||||
* Default constructor, includes all references
|
||||
@ -40,6 +56,10 @@ public class DroneListItem {
|
||||
previous = thePrevious;
|
||||
current = theCurrent;
|
||||
visibleDistance = 15;
|
||||
|
||||
// Give the Drone it's tools
|
||||
yourTools = new DroneTools(current, this);
|
||||
current.setDroneTools(yourTools);
|
||||
}
|
||||
|
||||
// Getters and Setters
|
||||
@ -136,6 +156,7 @@ public class DroneListItem {
|
||||
|
||||
/**
|
||||
* Retrieve the total space in the cargo hold of this drone. Does include
|
||||
*
|
||||
* space that is currently occupied.
|
||||
*
|
||||
* @return <code>int</code>
|
||||
@ -144,6 +165,42 @@ public class DroneListItem {
|
||||
return cargoSpace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the level of this drone in theiving
|
||||
*
|
||||
* @return <code>int</code>
|
||||
*/
|
||||
public int getTheft() {
|
||||
return theft;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns how many turns this drone has been alive
|
||||
*
|
||||
* @return How many turns this drone has been alive
|
||||
*/
|
||||
public int getAge() {
|
||||
return age;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the x index of this drone
|
||||
*
|
||||
* @return <code>int</code>
|
||||
*/
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the y index of this drone
|
||||
*
|
||||
* @return <code>int</code>
|
||||
*/
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the next DroneListItem in the Linked List
|
||||
*
|
||||
@ -170,7 +227,7 @@ public class DroneListItem {
|
||||
* @param newDistance
|
||||
* <code>int</code> New Distance
|
||||
*/
|
||||
private void setVisibleDistance(int newDistance) {
|
||||
public void setVisibleDistance(int newDistance) {
|
||||
visibleDistance = newDistance;
|
||||
}
|
||||
|
||||
@ -180,20 +237,27 @@ public class DroneListItem {
|
||||
* @param amount
|
||||
* <code>int</code> How much to increase the distance
|
||||
*/
|
||||
private void increaseVisibleDistance(int amount) {
|
||||
public void increaseVisibleDistance(int amount) {
|
||||
visibleDistance += amount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases the age of the drone by 1 turn
|
||||
*/
|
||||
public final void incrementAge() {
|
||||
age++;
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/**
|
||||
* Will ask the Drone what direction it would like to move
|
||||
*
|
||||
* @return
|
||||
* @return <code>boolean</code> if a move was made
|
||||
*/
|
||||
public boolean makeMove() {
|
||||
// Call the Drone's Move method
|
||||
EnumMove move = current.getMove();
|
||||
EnumMove move = current.move();
|
||||
|
||||
switch (move) {
|
||||
case NoMove: {
|
||||
@ -201,27 +265,31 @@ public class DroneListItem {
|
||||
return true;
|
||||
}
|
||||
case North: {
|
||||
moveNorth();
|
||||
moveDrone(Direction.N);
|
||||
return true;
|
||||
}
|
||||
case South: {
|
||||
moveSouth();
|
||||
moveDrone(Direction.S);
|
||||
return true;
|
||||
}
|
||||
case East: {
|
||||
moveEast();
|
||||
moveDrone(Direction.E);
|
||||
return true;
|
||||
}
|
||||
case West: {
|
||||
moveWest();
|
||||
moveDrone(Direction.W);
|
||||
return true;
|
||||
}
|
||||
case Upgrade: {
|
||||
//TODO - Implement upgrade
|
||||
// TODO - Implement upgrade
|
||||
return true;
|
||||
}
|
||||
case Attack: {
|
||||
//TODO - Implement attack
|
||||
// TODO - Implement attack
|
||||
return true;
|
||||
}
|
||||
case Steal: {
|
||||
// TODO - Implement steal
|
||||
return true;
|
||||
}
|
||||
default: {
|
||||
@ -233,79 +301,27 @@ public class DroneListItem {
|
||||
|
||||
// Movement
|
||||
|
||||
/**
|
||||
* Tests if a move North is possible. Will make the requested move if
|
||||
* possible.
|
||||
*
|
||||
* @param amount
|
||||
* of distance to move North
|
||||
* @return True if the move was made, false if is invalid
|
||||
*/
|
||||
public final boolean moveNorth() {
|
||||
if (current.canMoveNorth()) {
|
||||
moveHelper(1, 0);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
public void moveDrone(Direction direction) {
|
||||
int amountN = 0;
|
||||
int amountE = 0;
|
||||
switch (direction) {
|
||||
case N: {
|
||||
amountN = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a move South is possible. Will make the requested move if
|
||||
* possible.
|
||||
*
|
||||
* @param amount
|
||||
* of distance to move South
|
||||
* @return True if the move was made, false if is invalid
|
||||
*/
|
||||
public final boolean moveSouth() {
|
||||
if (current.canMoveSouth()) {
|
||||
moveHelper(-1, 0);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
case S: {
|
||||
amountN = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a move East is possible. Will make the requested move if
|
||||
* possible.
|
||||
*
|
||||
* @param amount
|
||||
* of distance to move East
|
||||
* @return True if the move was made, false if is invalid
|
||||
*/
|
||||
public final boolean moveEast() {
|
||||
if (current.canMoveEast()) {
|
||||
moveHelper(0, 1);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
case E: {
|
||||
amountE = 1;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests if a move West is possible. Will make the requested move if
|
||||
* possible.
|
||||
*
|
||||
* @param amount
|
||||
* of distance to move West
|
||||
* @return True if the move was made, false if is invalid
|
||||
*/
|
||||
public final boolean moveWest() {
|
||||
if (current.canMoveWest()) {
|
||||
moveHelper(0,-1);
|
||||
return true;
|
||||
} else
|
||||
return false;
|
||||
case W: {
|
||||
amountE = -1;
|
||||
break;
|
||||
}
|
||||
|
||||
/**
|
||||
* Performs a move in the specified amounts
|
||||
*
|
||||
* @param amountN
|
||||
* Amount of distance to move North (negative will go South)
|
||||
* @param amountE
|
||||
* Amount of distance to move East (negative will go West)
|
||||
*/
|
||||
public final void moveHelper(int amountN, int amountE) {
|
||||
Nomads.awesomeWorld.moveObjectAt(current.getX(), current.getY(), amountN, amountE);
|
||||
}
|
||||
Nomads.awesomeWorld.moveObjectAt(getX(), getY(), amountN, amountE);
|
||||
}
|
||||
}
|
||||
|
@ -36,7 +36,7 @@ public class DroneTeam {
|
||||
public DroneTeam(DroneListItem firstList) {
|
||||
first = firstList;
|
||||
last = firstList;
|
||||
teamName = firstList.getCurrent().name;
|
||||
teamName = firstList.getCurrent().getName();
|
||||
currentBalance = 0;
|
||||
}
|
||||
|
||||
@ -50,7 +50,7 @@ public class DroneTeam {
|
||||
DroneListItem firstList = new DroneListItem(null, null, (Drone) firstDrone);
|
||||
first = firstList;
|
||||
last = firstList;
|
||||
teamName = firstDrone.name;
|
||||
teamName = firstDrone.getName();
|
||||
currentBalance = 0;
|
||||
}
|
||||
|
||||
@ -172,7 +172,24 @@ public class DroneTeam {
|
||||
public void getMoves() {
|
||||
DroneListItem current = first;
|
||||
while (current != null) {
|
||||
current.getCurrent().getMove();
|
||||
// Increment the drone's age
|
||||
current.incrementAge();
|
||||
// Have it perform it's moves
|
||||
int turns = current.getSpeed();
|
||||
int currentTurn = 1;
|
||||
int currentTry = 1;
|
||||
while (currentTurn <= turns) {
|
||||
boolean moved = current.makeMove();
|
||||
if (moved)
|
||||
currentTurn++;
|
||||
else
|
||||
currentTry++;
|
||||
|
||||
// Give the drone 3 tries to make a valid move before skipping
|
||||
// them
|
||||
if (currentTry > 3)
|
||||
break;
|
||||
}
|
||||
current = current.getNext();
|
||||
}
|
||||
}
|
||||
|
61
src/net/grosinger/nomads/DroneTools.java
Normal file
61
src/net/grosinger/nomads/DroneTools.java
Normal file
@ -0,0 +1,61 @@
|
||||
package net.grosinger.nomads;
|
||||
|
||||
/**
|
||||
* Tools for the Drone to use. Only place methods in here that you want the
|
||||
* drone to have access to.
|
||||
*/
|
||||
public class DroneTools {
|
||||
|
||||
private Drone referredDrone;
|
||||
private DroneListItem listItem;
|
||||
|
||||
public DroneTools(Drone aDrone, DroneListItem droneParent) {
|
||||
referredDrone = aDrone;
|
||||
listItem = droneParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the X value of your Drone
|
||||
*
|
||||
* @return <code>int</code> - X value
|
||||
*/
|
||||
public int getX() {
|
||||
return listItem.getX();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Y value of your Drone
|
||||
*
|
||||
* @return <code>int</code> - Y value
|
||||
*/
|
||||
public int getY() {
|
||||
return listItem.getY();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the age of this Drone
|
||||
*
|
||||
* @return <code>int</code> - Age
|
||||
*/
|
||||
public int getAge() {
|
||||
return listItem.getAge();
|
||||
}
|
||||
|
||||
// Movement
|
||||
|
||||
public boolean canMoveNorth() {
|
||||
return Nomads.awesomeWorld.getWorldGrid()[getY() + 1][getX()] == null;
|
||||
}
|
||||
|
||||
public boolean canMoveSouth() {
|
||||
return Nomads.awesomeWorld.getWorldGrid()[getY() - 1][getX()] == null;
|
||||
}
|
||||
|
||||
public boolean canMoveEast() {
|
||||
return Nomads.awesomeWorld.getWorldGrid()[getY()][getX() + 1] == null;
|
||||
}
|
||||
|
||||
public boolean canMoveWest() {
|
||||
return Nomads.awesomeWorld.getWorldGrid()[getY()][getX() - 1] == null;
|
||||
}
|
||||
}
|
@ -3,29 +3,8 @@ package net.grosinger.nomads;
|
||||
/*
|
||||
* Everything that is found on the world will be a type of game object
|
||||
*/
|
||||
public class GameObject {
|
||||
private int x;
|
||||
private int y;
|
||||
protected String name;
|
||||
public interface GameObject {
|
||||
|
||||
// Getters and Setters
|
||||
public int getX() {
|
||||
return x;
|
||||
}
|
||||
|
||||
public int getY() {
|
||||
return y;
|
||||
}
|
||||
|
||||
public void setX(int newX) {
|
||||
x = newX;
|
||||
}
|
||||
|
||||
public void setY(int newY) {
|
||||
y = newY;
|
||||
}
|
||||
|
||||
public void setName(String newName) {
|
||||
name = newName;
|
||||
}
|
||||
public String getName();
|
||||
public void setName(String newName);
|
||||
}
|
||||
|
@ -85,8 +85,6 @@ public class World {
|
||||
return WORLDSIZE;
|
||||
}
|
||||
|
||||
// Why would we need a setter for theWorld?
|
||||
|
||||
/**
|
||||
* Used to set a new GameObject at a given location Not used for moving a
|
||||
* GameObject
|
||||
|
Reference in New Issue
Block a user