diff --git a/src/Main.java b/src/Main.java index e24d452..9e104b2 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(1340,640+23); int num = 6; int[][] nodes = new int[num][2]; nodes[0][0] = 1; @@ -28,11 +28,35 @@ public static void main(String[] args) { nodes[7][1] = 13; nodes[8][0] = 11; nodes[8][1] = 1;*/ + + + JPanel container = new JPanel(); + container.setLayout(new BoxLayout(container, BoxLayout.X_AXIS)); MockGui mg = new MockGui(640,640,32, num, nodes); - MapTowerDefense map = new MapTowerDefense(100, num, nodes, mg); + StatGui sg= new StatGui(0,0); + sg.setPreferredSize(new Dimension(1, 0)); //this keeps statgui from overlapping mockgui + + /** + JLabel health = new JLabel("Health"); + health.setSize(100,100); + jp2.add(health);*/ + + container.add(mg); + container.add(sg); + + + MapTowerDefense map = new MapTowerDefense(100, num, nodes, mg, sg); mg.setMap(map); - frame.add(mg); + sg.setMap(map); + sg.setup(); + + frame.add(container); + //frame.add(mg); frame.setVisible(true); + + + + //StatGui sg = new StatGui(100, 640); //sg.setLocation(640, 0); diff --git a/src/MapTowerDefense.java b/src/MapTowerDefense.java index 309f929..108c273 100644 --- a/src/MapTowerDefense.java +++ b/src/MapTowerDefense.java @@ -7,18 +7,20 @@ public class MapTowerDefense { private int numNodes; private int[][] nodes; private MinionFactory MF; - private TowerFactory TF; + public TowerFactory TF; private MockGui MG; + private StatGui SG; - - public MapTowerDefense(int _maxTowers, int _numNodes, int[][] _nodes, MockGui _mg) { + public MapTowerDefense(int _maxTowers, int _numNodes, int[][] _nodes, MockGui _mg, StatGui _sg) { maxTowers = _maxTowers; numNodes = _numNodes; nodes = _nodes; MF = new MinionFactory(nodes[0][0], nodes[0][1], this); TF = new TowerFactory(this, maxTowers); MG = _mg; + SG = _sg; } + public MinionFactory getMF() { return MF; } @@ -34,6 +36,9 @@ public int[][] getNodes() { public MockGui getGui() { return MG; } + public StatGui getStatGui(){ + return SG; + } public void createMinion(MinionTypes type) { MF.createMinion(type); } diff --git a/src/MockGui.java b/src/MockGui.java index 79e4fce..a2e067e 100644 --- a/src/MockGui.java +++ b/src/MockGui.java @@ -1,3 +1,4 @@ +import javax.imageio.ImageIO; import javax.swing.*; import java.awt.*; @@ -6,13 +7,24 @@ import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.*; +import java.io.File; +import java.io.IOException; +import java.awt.Graphics; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.logging.Level; +import java.util.logging.Logger; +import javax.imageio.ImageIO; + + public class MockGui extends JPanel{ boolean gameOver; private int x, y, gridsize, numnodes; private int[][] nodes; private MapTowerDefense map;// - + private BufferedImage image; public MockGui(int x, int y, int gridSize, int numNodes, int[][] nodes) { this.x = x; @@ -29,7 +41,7 @@ public MockGui(int x, int y, int gridSize, int numNodes, int[][] nodes) { } public void setMap(MapTowerDefense map) { - this.map = map;// + this.map = map; } public void step() { @@ -42,6 +54,9 @@ public void step() { // map.getMF().getMinions()[0].minionTakeDamage(); + map.getStatGui().updateHealth(); + map.getStatGui().updateMoney(); + map.getStatGui().updateNumTowers(); map.getMF().assignAllDamage(); if (i > 63) { @@ -60,6 +75,7 @@ public void paint(Graphics g) { drawGrid(x, y, gridsize, g); //drawMinion(96,96,0,g); colorPath(g); + drawAllMinions(map.getMF(), g); drawAllTowers(map.getTF(), g); drawPlayerHealth(g); @@ -156,8 +172,14 @@ public void drawPlayerHealth(Graphics g) { } public void drawMinion(int x, int y, int health, Graphics g) { - g.setColor(new Color(255-health, 100, 100)); - g.fillOval(x, y, 32, 32); + //g.setColor(new Color(255-health, 100, 100)); + //g.fillOval(x, y, 32, 32); + try { + image = ImageIO.read(new File("src/Minion.png")); + } catch (IOException ex) { + System.out.println("image not found"); + } + g.drawImage(image, x,y, null); } public void drawAllTowers(TowerFactory TF, Graphics g) { diff --git a/src/StatGui.java b/src/StatGui.java index 4835b53..0daf4fe 100644 --- a/src/StatGui.java +++ b/src/StatGui.java @@ -1,12 +1,55 @@ +import javax.swing.JLabel; import javax.swing.JPanel; +import java.awt.*; + public class StatGui extends JPanel { private int X, Y; + private MapTowerDefense map; + private int maxHealth = 20; + private int playermoney = 1000; + JLabel hpLabel, moneyLabel, towersnumLabel; public StatGui (int x, int y) { X = x; Y = y; + + } + + public void setMap(MapTowerDefense map){ + this.map=map; + } + + public void setup(){ + hpLabel = new JLabel(); + hpLabel.setFont(new Font("Serif", Font.BOLD, 15)); + hpLabel.setForeground(Color.BLUE); + this.add(hpLabel); + + moneyLabel = new JLabel(); + moneyLabel.setFont(new Font("Serif", Font.BOLD, 15)); + moneyLabel.setForeground(Color.BLUE); + this.add(moneyLabel); + + towersnumLabel = new JLabel(); + towersnumLabel.setFont(new Font("Serif", Font.BOLD, 15)); + towersnumLabel.setForeground(Color.BLUE); + this.add(towersnumLabel); + + } + + public void updateHealth(){ + hpLabel.setText("[Health]: " + map.getTF().getTowerArray()[0].getHealth() + "/" + maxHealth); + } + + public void updateMoney(){ + moneyLabel.setText("[Money]: $ " + playermoney); } + public void updateNumTowers(){ + towersnumLabel.setText("[# of Towers]: " + map.TF.quantity); + } + + }