Skip to content
Permalink
cf2ff3d1cc
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
108 lines (95 sloc) 2.49 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){
System.out.println("x is: "+ x + " , y is: "+ y);
//Checks if there's already a tower here
//TODO make this better
if (!_map.getStatGui().canAfford(type.getBuycost())) { //check to see if player can afford
return;
}
if (quantity < _max) {
int i = 0;
//prevents tower from being placed on existing towers or on path
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++;
}
//first segment
if (((x >= 1) &&(x <= 16)) &&(y == 3)) {
System.out.println("NO TOWER ON PATH");
return;
}
//second segment
if (((y >= 3) &&(y <= 9)) &&(x == 16)) {
System.out.println("NO TOWER ON PATH");
return;
}
//third segment
if (((x >= 4) &&(x <= 16)) &&(y == 9)) {
System.out.println("NO TOWER ON PATH");
return;
}
//fourth segment
if (((y >= 9) &&(y <= 15)) &&(x == 4)) {
System.out.println("NO TOWER ON PATH");
return;
}
//fifth segment
if (((x >= 4) &&(x <= 18)) &&(y == 15)) {
System.out.println("NO TOWER ON PATH");
return;
}
_map.getStatGui().spendMoney(type.getBuycost()); //actually spend money, prevent double spending
towerarray[quantity] = new TowerMock(quantity, x, y, true, type, _map);
quantity++;
}
}
}