diff --git a/src/TowerFactory.java b/src/TowerFactory.java index 84baa8c..4c296db 100644 --- a/src/TowerFactory.java +++ b/src/TowerFactory.java @@ -58,13 +58,15 @@ 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 @@ -72,6 +74,33 @@ public class TowerFactory { } 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++; }