Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixed double tower and existing tower placement and player money
spending
  • Loading branch information
ssl10003 committed Apr 21, 2015
1 parent 6ec4add commit cf2ff3d
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/TowerFactory.java
Expand Up @@ -58,20 +58,49 @@ public class TowerFactory {
}

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().spendMoney(cost)) {
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++;
}
Expand Down

0 comments on commit cf2ff3d

Please sign in to comment.