diff --git a/src/Main.java b/src/Main.java index 23bc90e..6c581e8 100644 --- a/src/Main.java +++ b/src/Main.java @@ -7,7 +7,7 @@ public class Main extends JFrame{ public static void main(String[] args) { JFrame frame = new JFrame("Tower Defense Refactor Mock GUI"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); - frame.setSize(640,640+23); + frame.setSize(650,720); int num = 6; int[][] nodes = new int[num][2]; nodes[0][0] = 1; diff --git a/src/MockGui.java b/src/MockGui.java index b056258..4efbea2 100644 --- a/src/MockGui.java +++ b/src/MockGui.java @@ -150,6 +150,15 @@ public class MockGui extends JPanel{ i++; } } + + public void drawPlayerHealth(Graphics g) { + int health = map.getTF().getTowerArray()[0].getHealth(); + g.setColor(new Color(0,255,0)); + colorBlocks(19, 0, 19, health, g); + g.setColor(new Color(255,0,0)); + colorBlocks(19, 20, 19, health, g); + } + public void drawAllMinions(MinionFactory MF, Graphics g) { int i = 0; while (i < MF.getNum()) { @@ -164,15 +173,6 @@ public class MockGui extends JPanel{ i++; } } - - public void drawPlayerHealth(Graphics g) { - int health = map.getTF().getTowerArray()[0].getHealth(); - g.setColor(new Color(0,255,0)); - colorBlocks(19, 0, 19, health, g); - g.setColor(new Color(255,0,0)); - colorBlocks(19, 20, 19, health, g); - } - public void drawMinion(int x, int y, int health, Graphics g) { g.drawImage(image, x,y, null); } @@ -193,14 +193,18 @@ public class MockGui extends JPanel{ int i = 0; while (i < TF.getNum()) { int[] local = hash(TF.getTowerArray()[i].getTowerXlocation(), TF.getTowerArray()[i].getTowerYlocation()); - drawBasicTower(local[0], local[1], g); + drawBasicTower(TF.getTowerArray()[i], local[0], local[1], g); i++; } } - public void drawBasicTower(int x, int y, Graphics g){ - g.setColor(new Color(24,24,24)); - g.fillRect(x, y, 32, 32); + public void drawBasicTower(TowerMock tm, int x, int y, Graphics g){ + //g.setColor(new Color(24,24,24)); + //g.fillRect(x, y, 32, 32); + g.drawImage(tm.getSprite(),x , y, null); + + //tm.getTowerXlocation() + //tm.getTowerYlocation() } @@ -213,7 +217,12 @@ public class MockGui extends JPanel{ System.out.println("x; " + x + " y: " + y); int[] local = unhash(x,y); - map.getTF().createBasicTower(local[0], local[1]); + if(map.getStatGui().gettowerPlacerVar() == 2){ + map.getTF().createBasicTower(local[0], local[1], TowerTypes.AOE); + } + else if(map.getStatGui().gettowerPlacerVar() == 1){ + map.getTF().createBasicTower(local[0], local[1], TowerTypes.BASIC); + } } } diff --git a/src/StatGui.java b/src/StatGui.java index 89c5344..bf93c75 100644 --- a/src/StatGui.java +++ b/src/StatGui.java @@ -18,6 +18,7 @@ public class StatGui extends JPanel implements ActionListener{ private int playermoney = 1000; JLabel hpLabel, moneyLabel, towersnumLabel; JButton AOETowerbutton, BasicTowerbutton; + public int towerPlacerVar = 1; //1: Basic, 2:AOE public StatGui (int x, int y) { X = x; @@ -88,16 +89,20 @@ public class StatGui extends JPanel implements ActionListener{ public void actionPerformed(ActionEvent e){ if("select aoe tower".equals(e.getActionCommand())){ AOETowerbutton.setEnabled(true); - //set tower placer variable to place aoe tower + towerPlacerVar = 2; System.out.println("AOE tower selected!"); } else if("select basic tower".equals(e.getActionCommand())){ BasicTowerbutton.setEnabled(true); - //set tower placer variable to place basic tower - System.out.println("Basic b**ch tower selected!"); + towerPlacerVar = 1; + System.out.println("Basic tower selected!"); } } + public int gettowerPlacerVar(){ + return towerPlacerVar; + } + public void updateHealth(){ hpLabel.setText("[Health]: " + map.getTF().getTowerArray()[0].getHealth() + "/" + maxHealth); } diff --git a/src/TowerFactory.java b/src/TowerFactory.java index 86118dd..30c0f1f 100644 --- a/src/TowerFactory.java +++ b/src/TowerFactory.java @@ -36,17 +36,14 @@ public class TowerFactory { - - - 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); + towerarray[0] = new TowerMock(0, x, y, false, TowerTypes.NEXUS); } - public void createBasicTower(int x, int y){ + 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)) { @@ -61,7 +58,7 @@ public class TowerFactory { } i++; } - towerarray[quantity] = new TowerMock(quantity, x, y, true); + towerarray[quantity] = new TowerMock(quantity, x, y, true, type); quantity++; } } diff --git a/src/TowerMock.java b/src/TowerMock.java index dfd2683..3698614 100644 --- a/src/TowerMock.java +++ b/src/TowerMock.java @@ -1,20 +1,21 @@ +import java.awt.image.BufferedImage; public class TowerMock{ - public int _xlocation, _ylocation, _value, _cost, _upgradecost, _towerid; + public int _xlocation, _ylocation, _sellCost, _buyCost, _upgradecost, _towerid; public int _level = 1; public int _range = 96; public int _power = 1; public double _firerate = 1.0; - + private BufferedImage _sprite; + public TowerTypes type; public int health; // (FOR NEXUS ONLY) public boolean _isTower; //false is Nexus - public String Description = "Basic Tower with generic stats, no special abilities or " - + "mods. Stats are initialized in the constructor. Targets 1 minion at a time."; + public String Description = "Tower lol."; public MinionMock currenttarget; - //baseline stats: range - radius of 10. firerate - 1 shot/s. power - 1 damage + /* public TowerMock(int id, int xloc, int yloc, boolean isTower){ _towerid = id; _xlocation = xloc; @@ -24,6 +25,27 @@ public class TowerMock{ health = 20; } } + */ + + public TowerMock(int id, int xloc, int yloc, boolean isTower, TowerTypes type){ + _towerid = id; + _xlocation = xloc; + _ylocation = yloc; + _isTower = isTower; + if (!isTower) { + health = 20; + } + + this.type=type; + this._buyCost=type.getBuycost(); + this._sellCost= type.getSellcost(); + this._sprite=type.getSprite(); + + } + + public BufferedImage getSprite(){ + return _sprite; + } public int dealDamage(int x, int y) { int deltax = (32*_xlocation - x); @@ -56,10 +78,6 @@ public class TowerMock{ public int getHealth() { return health; } - - - - public int getTowerXlocation() { return _xlocation; @@ -88,18 +106,18 @@ public class TowerMock{ //get cost this tower was purchased for public int getCost() { - _cost = (int) (_range + ( _power * 10) + (_firerate * 10)); - return _cost; + _buyCost = (int) (_range + ( _power * 10) + (_firerate * 10)); + return _buyCost; } //get upgrade cost to upgrade tower, double the price of last cost public int getupgradeCost() { - _upgradecost = _cost * 2; + _upgradecost = _buyCost * 2; return _upgradecost; } public void upgrade(){ - _cost = _upgradecost; + _buyCost = _upgradecost; _level = _level + 1; this._range = this._range + 1; this._firerate= this._firerate + 0.3; diff --git a/src/TowerTypes.java b/src/TowerTypes.java new file mode 100644 index 0000000..4b0a98f --- /dev/null +++ b/src/TowerTypes.java @@ -0,0 +1,44 @@ +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; + +public enum TowerTypes { + //NAME (Cost to buy, Cost to sell, "sprite dir") + NEXUS (1, 1, "Nexus Tower.png"), + BASIC (50, 25, "Basic Tower.png"), + AOE (100, 50, "AOE Tower.png"); + + private int _buycost, _sellcost; + private BufferedImage sprite; + private static final String SPRITE_FILE_DIR = "src/resources/images/"; + + TowerTypes(int buycost, int sellcost, String spriteFileName) { + this._buycost = buycost; + this._sellcost = sellcost; + + try { + this.sprite = ImageIO.read(new File(SPRITE_FILE_DIR.concat(spriteFileName))); + } catch (IOException ex) { + System.out.println("image not found"); + } + } + + public int getBuycost() { + return _buycost; + } + + public int getSellcost() { + return _sellcost; + } + + public String getName() { + return this.toString(); + } + + public BufferedImage getSprite() + { + return sprite; + } +} \ No newline at end of file