Skip to content
This repository has been archived by the owner on Jan 31, 2018. It is now read-only.

Commit

Permalink
Minor Changes
Browse files Browse the repository at this point in the history
* Organized code around the entire project's source.
* Made Objects `Serializable`
  • Loading branch information
Zeale committed Mar 11, 2017
1 parent c75c204 commit e343501
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 76 deletions.
32 changes: 16 additions & 16 deletions src/zeale/evolution/Evolution.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,29 @@ public final class Evolution {
*/
public final EvolutionPane pane = new EvolutionPane();

/**
* This List is used to prevent {@link ConcurrentModificationException}s
* from occurring. While iterating over {@link #structures},
* {@link #addStruct(Structure)} adds its objects here to prevent
* {@link ConcurrentModificationException}s caused by {@link #structures}.
*/
private LinkedList<Structure> modificationStructsList = new LinkedList<>();
/**
* This List is used to prevent {@link ConcurrentModificationException}s
* from occurring. While iterating over {@link #bots}, {@link #addBot(Bot)}
* adds its objects here to prevent {@link ConcurrentModificationException}s
* caused by {@link #bots}.
*/
private LinkedList<Bot> modificationBotsList = new LinkedList<>();

/**
* <p>
* The current instance of {@link Evolution} that is running in the program.
* This is commonly used to retrieve the current instance statically, as
* that was what it was made for. See {@link #getCurrentInstance()}.
*/
private static Evolution CURRENT_INSTANCE;

/**
* A {@link Random} for use around the class, where necessary.
*/
Expand Down Expand Up @@ -146,22 +162,6 @@ public boolean addStruct(final Structure struct) {
return modificationStructsList.add(struct);
}

/**
* This List is used to prevent {@link ConcurrentModificationException}s
* from occurring. While iterating over {@link #structures},
* {@link #addStruct(Structure)} adds its objects here to prevent
* {@link ConcurrentModificationException}s caused by {@link #structures}.
*/
private LinkedList<Structure> modificationStructsList = new LinkedList<>();

/**
* This List is used to prevent {@link ConcurrentModificationException}s
* from occurring. While iterating over {@link #bots}, {@link #addBot(Bot)}
* adds its objects here to prevent {@link ConcurrentModificationException}s
* caused by {@link #bots}.
*/
private LinkedList<Bot> modificationBotsList = new LinkedList<>();

/**
* <p>
* <strong>A getter for the {@link Bot}s in game.</strong>
Expand Down
7 changes: 6 additions & 1 deletion src/zeale/evolution/Object.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package zeale.evolution;

import java.awt.Graphics;
import java.io.Serializable;

public abstract class Object {
public abstract class Object implements Serializable {
/**
* <p>
* Whether or not this {@link Object} is alive. This defines whether or not
Expand All @@ -14,6 +15,10 @@ public abstract class Object {
* The position of this {@link Object} in game.
*/
protected double posx, posy;
/**
* Serial Version UID
*/
private static final long serialVersionUID = 1L;

/**
* <strong>Constructs an {@link Object}.</strong>
Expand Down
92 changes: 48 additions & 44 deletions src/zeale/evolution/bots/Bot.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,53 +26,12 @@ public class Bot extends Object {
* The life that this {@link Bot} has remaining before it dies (in seconds).
*/
private double life = 100.0;

/**
* Adds life to this {@link Bot}. See {@link #life} for more details.
*
* @param life
* The amount of life to add to this {@link Bot}.
* @return The total amount of life that this {@link Bot} has left.
*/
public double addLife(double life) {
return this.life += life;
}

/**
* A getter for {@link Bot#life}.
*
* @return The life remaining for this {@link Bot}.
*/
public double getLife() {
return life;
}

/**
* Sets the amount of life that this {@link Bot} has left.
*
* @param life
* The amount of life that will be set to this {@link Bot}.
*/
public void setLife(double life) {
this.life = life;
}

/**
* Decrements the life of this {@link Bot} by the specified amount.
*
* @param life
* The amount of life to take from this {@link Bot}.
* @return The amount of life that this {@link Bot} has left over.
*/
public double decrementLife(double life) {
return this.life -= life;
}

/**
* The maximum amount of {@link Resource}s that this {@link Bot} can carry.
* (AKA its inventory size.)
*/
private short maxResources = 5;

/**
* The {@link LinkedList} of {@link Resource}s that this {@link Bot}
* carries. This is sometimes referred to as its <i>inventory</i> in
Expand All @@ -89,7 +48,7 @@ public double decrementLife(double life) {
/**
* The {@link Object} that this {@link Bot} is attempting to head towards.
*/
private Object target;
private transient Object target;

/**
* The current amount of wait time that this {@link Bot} has. See
Expand All @@ -101,12 +60,16 @@ public double decrementLife(double life) {
* The {@link Color} of this {@link Bot}. Defaults to {@link Color#PINK}.
*/
protected Color botColor = Color.PINK;

/**
* The size of this {@link Bot}. Defaulted to 25.
*/
protected int width = 25, height = 25;

/**
* Serial Version UID
*/
private static final long serialVersionUID = 1L;

/**
* Makes a new {@link Bot} with the specified attributes and position.
*
Expand Down Expand Up @@ -175,6 +138,17 @@ public Bot(final double posx, final short maxResources, final double posy) {
this.maxResources = maxResources;
}

/**
* Adds life to this {@link Bot}. See {@link #life} for more details.
*
* @param life
* The amount of life to add to this {@link Bot}.
* @return The total amount of life that this {@link Bot} has left.
*/
public double addLife(double life) {
return this.life += life;
}

/**
* Adds time to this {@link Bot} where it will sit and do nothing. If this
* {@link Bot} has 50,000 milliseconds of wait time, it will wait 50 seconds
Expand All @@ -187,6 +161,26 @@ public void addWaitTime(final double miliseconds) {
waitTime += miliseconds;
}

/**
* Decrements the life of this {@link Bot} by the specified amount.
*
* @param life
* The amount of life to take from this {@link Bot}.
* @return The amount of life that this {@link Bot} has left over.
*/
public double decrementLife(double life) {
return this.life -= life;
}

/**
* A getter for {@link Bot#life}.
*
* @return The life remaining for this {@link Bot}.
*/
public double getLife() {
return life;
}

/**
* Adds a {@link Resource} to this {@link Bot}'s inventory/storage. <br>
* <br>
Expand Down Expand Up @@ -216,6 +210,16 @@ public void render(final Graphics g) {
Evolution.calculateSize(getY() + height - 7, false));
}

/**
* Sets the amount of life that this {@link Bot} has left.
*
* @param life
* The amount of life that will be set to this {@link Bot}.
*/
public void setLife(double life) {
this.life = life;
}

/**
* Removes and returns all of this {@link Bot}'s {@link Resource}s.
*
Expand Down
10 changes: 5 additions & 5 deletions src/zeale/evolution/resources/Resource.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
import java.util.Random;

public class Resource {
/**
* A private static {@link Random} for use around the class.
*/
private static Random rand = new Random();

/**
* Attributes of this {@link Resource} that define how it works in game. The
* {@link #weight} will define how hard this {@link Resource} is to carry,
* and the {@link #value} defines how rewarding this {@link Resource} is.
*/
private int value = 1, weight = 25;

/**
* A private static {@link Random} for use around the class.
*/
private static Random rand = new Random();

/**
* Constructs a new {@link Resource}. (<b>Will be changed by the next
* version...</b>)
Expand Down
20 changes: 10 additions & 10 deletions src/zeale/evolution/structures/Spawnpoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,6 @@

public final class Spawnpoint extends Structure {

/**
* A private static random for wherever/whenever it's needed in this class.
*/
private static Random rand = new Random();

/**
* A {@link LinkedList} of the {@link Resource}s that this
* {@link Spawnpoint} currently holds.
Expand All @@ -30,6 +25,11 @@ public final class Spawnpoint extends Structure {
*/
private final int width = 36, height = 36;

/**
* A private static random for wherever/whenever it's needed in this class.
*/
private static Random rand = new Random();

/**
* Constructs a new {@link Spawnpoint} using an x and y position.
*
Expand All @@ -50,6 +50,11 @@ public void activate(final Bot bot) {
resources.addAll(list);
}

@Override
public void activate(final Object activatingObj) {

}

public LinkedList<Resource> removeResources(int count) {
LinkedList<Resource> list = new LinkedList<>();
for (int i = 0; i < count; i++)
Expand All @@ -60,11 +65,6 @@ public LinkedList<Resource> removeResources(int count) {
return list;
}

@Override
public void activate(final Object activatingObj) {

}

@Override
public void render(final Graphics g) {
g.setColor(Color.BLUE);
Expand Down

0 comments on commit e343501

Please sign in to comment.