sellTurretLocations = new HashSet<Point>();
}
public void update()
{
Treasure treasure = (Treasure)world.getEntity(world.getEntitiesByType(EntityType.Treasure).iterator().next());
int gold = treasure.getGold();
// sell wall
for(Point sellWallLocation : sellWallLocations)
{
int x = sellWallLocation.getX();
int y = sellWallLocation.getY();
Set<Long> results = world.getEntitiesByLocation(x,y);
results.retainAll(world.getEntitiesByType(EntityType.Wall));
if(!results.isEmpty())
{
treasure.setGold(treasure.getGold() + (int)(wallCost * refundPercentage));
Long id = results.iterator().next();
world.deleteEntity(id);
}
}
sellWallLocations.clear();
// sell turrets
for(Point sellTurretLocation : sellTurretLocations)
{
int x = sellTurretLocation.getX();
int y = sellTurretLocation.getY();
Set<Long> results = world.getEntitiesByLocation(x,y);
results.retainAll(world.getEntitiesByType(EntityType.Turret));
if(!results.isEmpty())
{
treasure.setGold(treasure.getGold() + (int)(turretCost * refundPercentage));
Long id = results.iterator().next();
world.deleteEntity(id);
}
}
sellTurretLocations.clear();
// build wall
for(Point createWallLocation : createWallLocations)
{
int x = createWallLocation.getX();
int y = createWallLocation.getY();
if((gold >= wallCost) && world.getEntitiesByLocation(x,y).isEmpty())
{
treasure.setGold(gold - wallCost);
world.createEntity(EntityType.Wall, x, y, Direction.North);
}
}
createWallLocations.clear();
// build turret
for(Point createTurretLocation : createTurretLocations)
{
int x = createTurretLocation.getX();
int y = createTurretLocation.getY();
if((gold >= turretCost) && world.getEntitiesByLocation(x,y).isEmpty())
{
treasure.setGold(gold - turretCost);
world.createEntity(EntityType.Turret, x, y, Direction.North);
}
}
createTurretLocations.clear();
}