From fcb259c7e7f4639d7f64ef89c874764ffe87288f Mon Sep 17 00:00:00 2001 From: jrb10014 Date: Mon, 20 Apr 2015 19:12:08 -0400 Subject: [PATCH 1/2] only way to update Stat Gui head --- src/MinionMock.java | 6 +++++ src/MinionTypes.java | 1 + src/MockGui.java | 2 +- src/TowerFactory.java | 20 +++++++++++++--- src/TowerMock.java | 53 +++++++++++++++++++++++++++++++++++++++---- 5 files changed, 74 insertions(+), 8 deletions(-) diff --git a/src/MinionMock.java b/src/MinionMock.java index 8c0fe01..c02fa5a 100644 --- a/src/MinionMock.java +++ b/src/MinionMock.java @@ -112,6 +112,12 @@ public class MinionMock { return attackDamage; } + + + public void minionTakeHit(int damage) { + health-=damage; + } + public void minionTakeDamage() { int dam = map.getTF().assignTotalDamage(x, y); health-=dam; diff --git a/src/MinionTypes.java b/src/MinionTypes.java index 6c9d2e0..83fe1cb 100644 --- a/src/MinionTypes.java +++ b/src/MinionTypes.java @@ -14,6 +14,7 @@ public enum MinionTypes { // UNKILLABLE (10000, 1, 1, 100, "Unkillable Minion.png"), DOUBLEBASIC (255, 2, 1, 12, "Double Basic Minion.png"), // SUPERKILLER (10, 20, 8, 100, "Superkiller Minion.png"), + HEALTH (2000, -1, 1, -50, "Basic Minion.png"), MONEYBAGS (350, 1, 2, 50, "Moneybags Minion.png"); diff --git a/src/MockGui.java b/src/MockGui.java index 4efbea2..5844a3c 100644 --- a/src/MockGui.java +++ b/src/MockGui.java @@ -53,8 +53,8 @@ public class MockGui extends JPanel{ repaint(); i++; // + map.getTF().basicTotalDamage(); map.getMF().getMinions()[0].minionTakeDamage(); - map.getStatGui().updateHealth(); map.getStatGui().updateMoney(); map.getStatGui().updateNumTowers(); diff --git a/src/TowerFactory.java b/src/TowerFactory.java index 30c0f1f..84baa8c 100644 --- a/src/TowerFactory.java +++ b/src/TowerFactory.java @@ -16,11 +16,25 @@ public class TowerFactory { 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) { - total += towerarray[i].dealDamage(x, y); + if (0 == (towerarray[i].type.compareTo(TowerTypes.AOE))) { + total += towerarray[i].dealDamage(x, y); + } i++; } return total; @@ -40,7 +54,7 @@ public class TowerFactory { 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); + towerarray[0] = new TowerMock(0, x, y, false, TowerTypes.NEXUS, _map); } public void createBasicTower(int x, int y, TowerTypes type){ @@ -58,7 +72,7 @@ public class TowerFactory { } i++; } - towerarray[quantity] = new TowerMock(quantity, x, y, true, type); + towerarray[quantity] = new TowerMock(quantity, x, y, true, type, _map); quantity++; } } diff --git a/src/TowerMock.java b/src/TowerMock.java index 3698614..d51238c 100644 --- a/src/TowerMock.java +++ b/src/TowerMock.java @@ -9,11 +9,11 @@ public class TowerMock{ private BufferedImage _sprite; public TowerTypes type; public int health; // (FOR NEXUS ONLY) - + private MapTowerDefense _map; public boolean _isTower; //false is Nexus public String Description = "Tower lol."; - public MinionMock currenttarget; + public MinionMock currentTarget; /* public TowerMock(int id, int xloc, int yloc, boolean isTower){ @@ -27,8 +27,9 @@ public class TowerMock{ } */ - public TowerMock(int id, int xloc, int yloc, boolean isTower, TowerTypes type){ + public TowerMock(int id, int xloc, int yloc, boolean isTower, TowerTypes type, MapTowerDefense map){ _towerid = id; + _map = map; _xlocation = xloc; _ylocation = yloc; _isTower = isTower; @@ -47,6 +48,48 @@ public class TowerMock{ return _sprite; } + public int basicAttack() { + if (findMinion()) { + + } + return 0; + } + + + + public boolean basicDealDamage() { + if (findMinion()) { + currentTarget.minionTakeHit(1); + return true; + } else { + return false; + } + + + } + + + + public boolean findMinion() { + int i = 0; + while (i < 100) { + MinionMock m = _map.getMF().getMinions()[i]; + if (m == null) { + return false; + } + if (m.isAlive()) { + if (1 == dealDamage(m.getX(), m.getY())) { + currentTarget = m; + return true; + } + } + i++; + } + return false; + } + + + public int dealDamage(int x, int y) { int deltax = (32*_xlocation - x); int deltay = (32*_ylocation - y); @@ -58,6 +101,8 @@ public class TowerMock{ } } + + public boolean takeDamage(int damage) { if (this.health <= damage) { @@ -137,7 +182,7 @@ public class TowerMock{ } public void setTarget(MinionMock aminion){ - currenttarget = aminion; + currentTarget = aminion; } public int getID() { From cf2ff3d1cc6e82cba2f59c1a6b2b1f40d60eae3b Mon Sep 17 00:00:00 2001 From: ssl10003 Date: Tue, 21 Apr 2015 18:23:44 -0400 Subject: [PATCH 2/2] Fixed double tower and existing tower placement and player money spending --- src/TowerFactory.java | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) 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++; }