Skip to content

Commit

Permalink
Added StatGui with health, money, towers. Added Minion Mickey instead of
Browse files Browse the repository at this point in the history
circles for minions.
  • Loading branch information
ssl10003 committed Apr 10, 2015
1 parent 56778fa commit fd72ee9
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 10 deletions.
30 changes: 27 additions & 3 deletions src/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);

Expand Down
11 changes: 8 additions & 3 deletions src/MapTowerDefense.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
Expand Down
30 changes: 26 additions & 4 deletions src/MockGui.java
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import javax.imageio.ImageIO;
import javax.swing.*;

import java.awt.*;
Expand All @@ -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;
Expand All @@ -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() {
Expand All @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
43 changes: 43 additions & 0 deletions src/StatGui.java
Original file line number Diff line number Diff line change
@@ -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);
}


}

0 comments on commit fd72ee9

Please sign in to comment.