Skip to content
Permalink
fcb259c7e7
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
79 lines (67 sloc) 1.59 KB
public class TowerFactory {
int xloc, yloc;
MapTowerDefense _map;
TowerMock[] towerarray;
int quantity;
int _max;
int cost;
public TowerFactory(MapTowerDefense amap, int max){
_map = amap;
_max = max;
towerarray = new TowerMock[_max];
createNexus();
quantity = 1;
cost = 100;
}
public void basicTotalDamage() {
int i = 1;
while (i < quantity) {
if (0 == (towerarray[i].type.compareTo(TowerTypes.BASIC))) {
towerarray[i].basicDealDamage();
}
i++;
}
}
public int assignTotalDamage(int x, int y) {
int i = 1;
int total = 0;
while (i < quantity) {
if (0 == (towerarray[i].type.compareTo(TowerTypes.AOE))) {
total += towerarray[i].dealDamage(x, y);
}
i++;
}
return total;
}
public TowerMock[] getTowerArray() {
return towerarray;
}
public int getNum() {
return quantity;
}
public void createNexus(){
int[] local = _map.getNodes()[_map.getNum()-1];
int x = local[0];
int y = local[1];
towerarray[0] = new TowerMock(0, x, y, false, TowerTypes.NEXUS, _map);
}
public void createBasicTower(int x, int y, TowerTypes type){
//Checks if there's already a tower here
//TODO make this better
if (!_map.getStatGui().spendMoney(cost)) {
return;
}
if (quantity < _max) {
int i = 0;
while (i < quantity) {
if ((towerarray[i].getTowerXlocation() == x) && (towerarray[i].getTowerYlocation() == y)) {
System.out.println("CONSEQUENCES WILL NEVER BE THE SAME"); //informal logging
return;
}
i++;
}
towerarray[quantity] = new TowerMock(quantity, x, y, true, type, _map);
quantity++;
}
}
}