Skip to content

Commit

Permalink
Changed visibility of energy values as part of #4
Browse files Browse the repository at this point in the history
It should be noted that World factories are visible and accessible by
Ants. This need to change in such a way that other classes can access
the factories without the Ants being able to.
  • Loading branch information
hiniko committed May 3, 2012
1 parent a08bc15 commit fdbcef0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 10 deletions.
21 changes: 13 additions & 8 deletions src/me/paulrose/lptc/simulator/Ant.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,14 @@ public abstract class Ant extends MoveableEntity

private int processOnTick;

protected Colony colony, enemyColony;
private Colony colony, enemyColony;

protected int energy, maxCarryWeight;
private int energy, maxCarryWeight;

protected boolean foundFood, atFood, atColony, atEnemyAnt, atFriendlyAnt,
attacked, fullEnergy, halfEnergy, eating, friendlyAntAttacked,
friendlyAntFoundFood, nearEnemyColony, nearHomeColony, drawViewRadius,
drawCollisions, drawEnergyBar, atEnemyColony;
drawCollisions, atEnemyColony , drawEnergyBar;

protected Ant nearestAnt, nearestFriendlyAnt, nearestEnemyAnt, attackerAnt,
friendlyAttacked, friendlyWithFood;
Expand All @@ -55,7 +55,6 @@ public Ant(String n, float x, float y, Colony c, World wo)

// Starting values for the ant
colony = c;
//energy = 1000;
energy = MAX_ENERGY;
maxCarryWeight = 100;
sizeRadius = BODY_SIZE / 2;
Expand All @@ -64,18 +63,20 @@ public Ant(String n, float x, float y, Colony c, World wo)
drawCollisions = false;
drawEnergyBar = true;


processOnTick = world.random.nextInt(4);

setRotation(world.random.nextInt(360 + 1));
}

public int getColonyID()
{
return colony.ID;
}

public void runLogic()
{
// User code will go here in the end
}


public void update(int delta)
{
super.update(delta);
Expand Down Expand Up @@ -108,7 +109,6 @@ public void update(int delta)

enemyColony = null;


// Check if we have full energy before this loops deductions
fullEnergy = (energy == MAX_ENERGY);
halfEnergy = (energy >= MAX_ENERGY / 2);
Expand Down Expand Up @@ -610,4 +610,9 @@ public void resetColonyAttackFlag()
colony.resetAttack(this);
}

public int getEnergy()
{
return energy;
}

}
5 changes: 3 additions & 2 deletions src/me/paulrose/lptc/simulator/Colony.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ public class Colony extends Entity
private Image antSpriteFull, antSpriteMin;
private float centerX, centerY;
protected boolean drawEnergyCount, drawAntCount, drawOwnerName,
drawHealthBar, autoCreateAnts, firstRun, attacked,
drawHealthBar, autoCreateAnts, attacked,
createAntProtection;
private boolean firstRun;

Colony(String n, float x, float y, String c, int f, World wo)
{
Expand Down Expand Up @@ -350,7 +351,7 @@ public void createAnt()
//TODO checking of energy bounds and disable users from being to edit the values of sensitive variables.
public void resetAttack(Entity e)
{
if (e instanceof Ant && ((Ant) e).colony == this)
if (e instanceof Ant && ((Ant) e).getColonyID() == this.ID)
{
attacked = false;
}
Expand Down
2 changes: 2 additions & 0 deletions src/me/paulrose/lptc/simulator/PaulsAnt.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

public class PaulsAnt extends Ant
{
private Colony colony;

PaulsAnt(String name, float x, float y, Colony c, World w)
{
super(name, x, y, c, w);
colony = c;
}

public void update(int delta)
Expand Down
2 changes: 2 additions & 0 deletions src/resources/AntTemplate.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@ import me.paulrose.lptc.simulator.World;

public class --NAME--Ant extends Ant
{
private Colony colony;

public --NAME--Ant(String name, float x, float y, Colony c, World w)
{
super(name, x, y, c, w);
colony = c;
}

public void update(int delta)
Expand Down

0 comments on commit fdbcef0

Please sign in to comment.