Archived
1
0

-Changed most comments to work in JavaDoc

-Continued working on Move

Signed-off-by: unknown <github2@grosinger.net>
This commit is contained in:
unknown 2011-04-20 12:13:32 -07:00
parent 4201170b95
commit 8cc1c9a0dc
10 changed files with 237 additions and 44 deletions

Binary file not shown.

Binary file not shown.

View File

@ -6,6 +6,8 @@ package net.grosinger.nomads;
public class Building extends GameObject {
Structure structure;
// Can't decide if I want to add Drone Houses as another enum item or as a
// separate class that extends Building
public enum Structure {
TOWNHALL, REPAIRSHOP, UPGRADESHOP, POLICESTATION
}

View File

@ -1,15 +1,15 @@
package net.grosinger.nomads;
/*
* All drones will extend this class to give them the basic set of tools that they need.
* Don't forget to set a name
/**
* 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;
/*
* All custom drones should call the super constructor at the end of their
* constructor
/**
* Class constructor All custom drones should call their super constructor
* at the end of their own.
*/
public Drone() {
if (name == null) {
@ -22,14 +22,22 @@ public class Drone extends GameObject {
// Moving
// When moving, North is positive Y axis and East is positive X axis
// To be overridden by the drones
// This will be their turn
/**
* The main move method for all Drones. Custom Drones should override this
* with their own.
*/
public void move() {
}
// Checks to see if it can move north
// Moves and returns true if it can, returns false if it can not
/**
* 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);
@ -38,8 +46,14 @@ public class Drone extends GameObject {
return false;
}
// Checks to see if it can move south
// Moves and returns true if it can, returns false if it can not
/**
* 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);
@ -48,8 +62,14 @@ public class Drone extends GameObject {
return false;
}
// Checks to see if it can move east
// Moves and returns true if it can, returns false if it can not
/**
* 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);
@ -58,8 +78,14 @@ public class Drone extends GameObject {
return false;
}
// Checks to see if it can move west
// Moves and returns true if it can, returns false if it can not
/**
* 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);
@ -68,34 +94,69 @@ public class Drone extends GameObject {
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 it can move north
// Returns true if it can, false if it can not
/**
* 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(int amount) {
return canMoveHelper(amount, 0);
}
// Checks to see if it can move south
// Returns true if it can, false if it can not
/**
* 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(int amount) {
return canMoveHelper(amount * -1, 0);
}
// Checks to see if it can move east
// Returns true if it can, false if it can not
/**
* 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(int amount) {
return canMoveHelper(0, amount);
}
// Checks to see if it can move west
// Returns true if it can, false if it can not
/**
* 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(int amount) {
return canMoveHelper(0, amount * -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) {
@ -115,18 +176,29 @@ public class Drone extends GameObject {
// Getters and Setters
// Returns how many turns this drone has been alive
/**
* Returns how many turns this drone has been alive
*
* @return How many turns this drone has been alive
*/
public final int getAge() {
return age;
}
// Probably will not be needed.
// 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 by 1 turn
/**
* Increases the age of the drone by 1 turn
*/
public final void incrementAge() {
age++;
}

View File

@ -1,59 +1,113 @@
package net.grosinger.nomads;
/*
* Contains a pointer to the first and the last DroneListItem in a particular team.
* When adding drones to Team A they should be added to the end of the DroneTeam
* So similar drones are grouped together
/**
* Contains a pointer to the first and the last DroneListItem in a particular
* team. When adding drones to Team A they should be added to the end of the
* DroneTeam So similar drones are grouped together
*/
public class DroneTeam {
/**
* The first DroneListItem in the team
*/
private DroneListItem first;
/**
* The last DroneListItem in the team
*/
private DroneListItem last;
// Taken from the first drone added to the team
/**
* Taken from the first drone added to the team
*/
private String teamName;
/**
* Class Constructor
*
* @param firstDrone
* <code>DroneListItem</code> that will be the first Drone
*/
public DroneTeam(DroneListItem firstDrone) {
first = firstDrone;
last = firstDrone;
}
/*
* Getters and Setters
// Getters and Setters
/**
* Retrieves the first DroneListItem
*
* @return First <code>DroneListItem</code>
*/
public DroneListItem getFirst() {
return first;
}
/**
* Retrieves the last DroneListItem
*
* @return Last <code>DroneListItem</code>
*/
public DroneListItem getLast() {
return last;
}
/**
* Retrieves the Team Name
*
* @return Team Name in a <code>String</code>
*/
public String getName() {
return teamName;
}
/**
* Sets the first DroneListItem to that provided
*
* @param theFirst
* <code>DroneListItem</code> to be made first
*/
public void setFirst(DroneListItem theFirst) {
first = theFirst;
}
/**
* Sets the last DroneListItem to that provided
*
* @param theFirst
* <code>DroneListItem</code> to be made last
*/
public void setLast(DroneListItem theLast) {
last = theLast;
}
/**
* Sets the Team Name
*
* @param newName
* <String> to set the name to
*/
public void setName(String newName) {
teamName = newName;
}
/*
/**
* Adds a DroneListItem to the end of a DroneTeam
*
* @param newItem
* <code>DroneListItem</code> to add to end
*/
public void addToEnd(DroneListItem newItem) {
// TODO - Implement addToEnd
}
/*
/**
* Always remove a DroneListItem through the DroneTeam so that it can tell
* if it needs to update the first or last pointers
*
* @param toRemove
* <code>DroneListItem</code> that needs to be removed
*/
public void removeDrone(DroneListItem toRemove) {
// TODO - Implement removeDrone

View File

@ -5,7 +5,7 @@ package net.grosinger.nomads;
*/
public class InitializeGame {
/*
/**
* Search through ___ directory for any drone classes Load them, find the
* name, and return a linkedlist with all the drones
*

View File

@ -1,6 +1,6 @@
package net.grosinger.nomads;
/*
/**
* Main class where information about the world is stored
*
* Consists of a 2D array, representing each possible space in the game grid
@ -8,14 +8,19 @@ package net.grosinger.nomads;
*/
public class World {
// The dimensions of x and y in the game world
/**
* The dimensions of x and y in the game world
*/
private final static int WORLDSIZE = 100;
// The 2D array of the entire world
// TODO - This will never actually hold a GameObject, will always be a type
// of drone or building. Make that work
/**
* The 2D array of the entire world
*/
private static GameObject theWorld[][] = new GameObject[WORLDSIZE][WORLDSIZE];
/**
* Class constructor
*/
public World() {
if (Nomads.DEBUGSTATUS)
System.out.println("Intializing the world...");
@ -25,28 +30,88 @@ public class World {
System.out.println("World initialization complete");
}
// Moves the object at x,y to a new x,y
/**
* Moves the object at x, y by the specified amount
*
* @param startingX
* X index of starting location
* @param startingY
* Y index of starting location
* @param amountN
* Amount to move the object North (negative will move South)
* @param amountE
* Amount to move the object East (negative will move West)
*/
public void moveObjectAt(int startingX, int startingY, int amountN, int amountE) {
// TODO - Implement moveObjectAt
GameObject tempStorage = theWorld[startingX][startingY];
theWorld[startingX][startingY] = null;
int newX = startingX + amountE;
int newY = startingY + amountN;
theWorld[newX][newY] = tempStorage;
}
// Getters and Setters
/**
* Returns the main world that all the GameObjects are on
*
* @return theWorld
*/
public GameObject[][] getWorldGrid() {
return theWorld;
}
/**
* Returns a GameObject located at given position
*
* @param x
* The X index to retrieve
* @param y
* The Y index to retrieve
* @return GameObject at given location
*/
public GameObject getObjectAt(int x, int y) {
return theWorld[x][y];
}
/**
* Retrieves the length of X and Y axis of the world (square)
*
* @return A single int, representing the length of X and Y
*/
public int getWorldSize() {
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
*
* @param x
* X index to place GameObject at
* @param y
* Y index to place GameObject at
* @param newItem
* GameObject to be placed
*/
public void setObjectAt(int x, int y, GameObject newItem) {
theWorld[x][y] = newItem;
}
/**
* Places a GameObject at a random location in the World
*
* @param newItem
* GameObject to be placed
*/
public void setObjectRandom(GameObject newItem) {
// Min + (int)(Math.random() * ((Max - Min) + 1))
int randX = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
int randY = 0 + (int) (Math.random() * ((getWorldSize() - 0) + 1));
setObjectAt(randX, randY, newItem);
}
}