Archived
1
0

-Revampped move method, might actually work now

-Moved move methods to DroneListItem
-Designed turn system
-Created two drawings that will help express how things should be structured
This commit is contained in:
Tony Grosinger 2011-04-22 10:46:29 -07:00
parent ab8838fd31
commit a2bb46503c
12 changed files with 341 additions and 109 deletions

Binary file not shown.

BIN
drawing/Hierarchy.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

BIN
drawing/Hierarchy.vsd Normal file

Binary file not shown.

BIN
drawing/TurnProgression.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
drawing/TurnProgression.vsd Normal file

Binary file not shown.

View File

@ -1,5 +1,7 @@
package net.grosinger.nomads;
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.
@ -22,138 +24,64 @@ public class Drone extends GameObject {
/**
* Starts the move, can be used to perform maintenance operations before the actual move
*/
public final void getMove() {
public final EnumMove getMove() {
if (Nomads.DEBUGMOVES)
System.out.println("Drone " + name + " moving");
move();
return move();
}
/**
* The main move method for all Drones. Custom Drones should override this
* with their own.
*/
public void move() {
public EnumMove move() {
return EnumMove.NoMove;
}
/**
* 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(int amount) {
if (canMoveNorth(amount)) {
moveHelper(amount, 0);
return true;
} else
return false;
}
/**
* 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(int amount) {
if (canMoveSouth(amount)) {
moveHelper(amount * -1, 0);
return true;
} else
return false;
}
/**
* 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(int amount) {
if (canMoveEast(amount)) {
moveHelper(0, amount);
return true;
} else
return false;
}
/**
* 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(int amount) {
if (canMoveWest(amount)) {
moveHelper(0, amount * -1);
return true;
} else
return false;
}
/**
* 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(getX(), getY(), amountN, amountE);
}
/**
* Checks to see if the drone can move North
*
* @param Amount
* @param amount
* of Distance to travel
* @return True if the move is possible, false if is invalid
*/
public final boolean canMoveNorth(int amount) {
return canMoveHelper(amount, 0);
public final boolean canMoveNorth() {
return canMoveHelper(1, 0);
}
/**
* Checks to see if the drone can move South
*
* @param Amount
* @param amount
* of Distance to travel
* @return True if the move is possible, false if is invalid
*/
public final boolean canMoveSouth(int amount) {
return canMoveHelper(amount * -1, 0);
public final boolean canMoveSouth() {
return canMoveHelper(-1, 0);
}
/**
* Checks to see if the drone can move East
*
* @param Amount
* @param amount
* of Distance to travel
* @return True if the move is possible, false if is invalid
*/
public final boolean canMoveEast(int amount) {
return canMoveHelper(0, amount);
public final boolean canMoveEast() {
return canMoveHelper(0, 1);
}
/**
* Checks to see if the drone can move West
*
* @param Amount
* @param amount
* of Distance to travel
* @return True if the move is possible, false if is invalid
*/
public final boolean canMoveWest(int amount) {
return canMoveHelper(0, amount * -1);
public final boolean canMoveWest() {
return canMoveHelper(0, -1);
}
/**

View File

@ -4,6 +4,11 @@ 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
*
* +----------------------------------------------------------+
* | 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
*/
@ -12,6 +17,21 @@ public class DroneListItem {
private DroneListItem previous;
private Drone current;
public enum EnumMove {
NoMove, North, South, East, West, Upgrade, Attack
}
// Stats about this robot
private int visibleDistance;
private int lumaLocatorDistance;
private int objectLocatorDistance;
private int reliability;
private int defenses;
private int speed; // Reflected in movements per turn
private int turning;
private int cargoSpace;
/*
* Default constructor, includes all references
*/
@ -19,40 +39,273 @@ public class DroneListItem {
next = theNext;
previous = thePrevious;
current = theCurrent;
visibleDistance = 15;
}
/*
* Constructor for the first or last Drone
*/
public DroneListItem(DroneListItem otherDrone, Drone theCurrent, Boolean isFirst) {
if (isFirst)
new DroneListItem(otherDrone, null, theCurrent);
else
new DroneListItem(null, otherDrone, theCurrent);
}
// Getters and Setters
/*
* Getters and Setters
/**
* Retrieve the next DroneListItem in the Linked List
*
* @return <code>DroneListItem</code>
*/
public DroneListItem getNext() {
return next;
}
/**
* Retrieve the previous DroneListItem in the Linked List
*
* @return <code>DroneListItem</code>
*/
public DroneListItem getPrevious() {
return previous;
}
/**
* Retrieve the Drone associated with the current DroneListItem
*
* @return <code>Drone</code>
*/
public Drone getCurrent() {
return current;
}
/**
* Retrieve the distance this drone can see other drones
*
* @return <code>int</code> Visible Distance
*/
public int getVisibleDistance() {
return visibleDistance;
}
/**
* Retrieve the distance from which this drone can spot a LumaPile
*
* @return <code>int</code> Visible Distance
*/
public int getLumaLocatorDistance() {
return lumaLocatorDistance;
}
/**
* Retrieve the distance from which this drone can spot an object
*
* @return <code>int</code> Visible Distance
*/
public int getObjectLocatorDistance() {
return objectLocatorDistance;
}
/**
* Retrieve the reliability factor of this drone
*
* @return <code>int</code>
*/
public int getReliability() {
return reliability;
}
/**
* Retrieve the defenses factor of this drone
*
* @return <code>int</code>
*/
public int getDefenses() {
return defenses;
}
/**
* Retrieve the speed factor of this drone
*
* @return <code>int</code>
*/
public int getSpeed() {
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
* space that is currently occupied.
*
* @return <code>int</code>
*/
public int getCargoSpace() {
return cargoSpace;
}
/**
* Sets the next DroneListItem in the Linked List
*
* @param theNext
* <code>DroneListItem</code>
*/
public void setNext(DroneListItem theNext) {
next = theNext;
}
/**
* Sets the previous DroneListItem in the Linked List
*
* @param thePrevious
* <code>DroneListItem</code>
*/
public void setPrevious(DroneListItem thePrevious) {
previous = thePrevious;
}
// Should be no need to set the current
/**
* Sets the visible distance for this drone
*
* @param newDistance
* <code>int</code> New Distance
*/
private void setVisibleDistance(int newDistance) {
visibleDistance = newDistance;
}
/**
* Increases the Visible Distance by specified amount
*
* @param amount
* <code>int</code> How much to increase the distance
*/
private void increaseVisibleDistance(int amount) {
visibleDistance += amount;
}
// Actions
/**
* Will ask the Drone what direction it would like to move
*
* @return
*/
public boolean makeMove() {
// Call the Drone's Move method
EnumMove move = current.getMove();
switch (move) {
case NoMove: {
// Default move has not been overridden
return true;
}
case North: {
moveNorth();
return true;
}
case South: {
moveSouth();
return true;
}
case East: {
moveEast();
return true;
}
case West: {
moveWest();
return true;
}
case Upgrade: {
//TODO - Implement upgrade
return true;
}
case Attack: {
//TODO - Implement attack
return true;
}
default: {
// No move was made
return false;
}
}
}
// 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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;
}
/**
* 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);
}
}

View File

@ -22,6 +22,11 @@ public class DroneTeam {
*/
private String teamName;
/**
* Amount of Lumas this team has accrued
*/
private int currentBalance;
/**
* Class Constructor
*
@ -32,6 +37,7 @@ public class DroneTeam {
first = firstList;
last = firstList;
teamName = firstList.getCurrent().name;
currentBalance = 0;
}
/**
@ -45,6 +51,7 @@ public class DroneTeam {
first = firstList;
last = firstList;
teamName = firstDrone.name;
currentBalance = 0;
}
// Getters and Setters
@ -76,6 +83,15 @@ public class DroneTeam {
return teamName;
}
/**
* Retrieves the balance for the team
*
* @return Number of Lumas this team possesses
*/
public int getBalance() {
return currentBalance;
}
/**
* Sets the first DroneListItem to that provided
*
@ -106,6 +122,26 @@ public class DroneTeam {
teamName = newName;
}
/**
* Replaces old balance with the new balance
*
* @param newBalance
* Amount to set the balance to
*/
public void setBalance(int newBalance) {
currentBalance = newBalance;
}
/**
* Increases the balance by specified amount
*
* @param additionalBalance
* How much to add to the team's balance
*/
public void increaseBalance(int additionalBalance) {
currentBalance += additionalBalance;
}
/**
* Adds a DroneListItem to the end of a DroneTeam
*
@ -129,10 +165,13 @@ public class DroneTeam {
public void removeDrone(DroneListItem toRemove) {
// TODO - Implement removeDrone
}
public void getMoves(){
/**
* Asks each Drone in the team to take it's turn
*/
public void getMoves() {
DroneListItem current = first;
while(current != null){
while (current != null) {
current.getCurrent().getMove();
current = current.getNext();
}

View File

@ -71,13 +71,20 @@ public class Nomads {
for (DroneTeam currentTeam : allTeams) {
currentTeam.getMoves();
}
//For testing purposes...
running = false;
try {
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
// For testing purposes...
//running = false;
}
if (DEBUGSTATUS)
System.out.println("Game loop finished");
return null;
return getWinner();
}
public static void finishGame(DroneTeam winner) {
@ -86,4 +93,9 @@ public class Nomads {
else
System.out.println("The winner was " + winner.getName());
}
public static DroneTeam getWinner() {
// TODO - Implement getWinner
return null;
}
}