Skip to content
Permalink
931edba1de
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
119 lines (95 sloc) 2.88 KB
import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.imageio.ImageIO;
import javax.swing.*;
public class StatGui extends JPanel implements ActionListener{
private int X, Y;
private MapTowerDefense map;
private int maxHealth = 20;
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;
Y = y;
}
public int getMoney() {
return playermoney;
}
public boolean canAfford(int cost) {
if (playermoney >= cost) {
return true;
} else {
return false;
}
}
public boolean spendMoney(int cost) {
if (canAfford(cost)) {
playermoney -= cost;
return true;
} else {
return false;
}
}
public boolean payDay(int value) {
playermoney += value;
return true;
}
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);
ImageIcon AOEicon = new ImageIcon("src/resources/images/AOE Tower.png", "AOE tower sprite");
AOETowerbutton = new JButton("AOE Tower", AOEicon);
AOETowerbutton.setActionCommand("select aoe tower");
AOETowerbutton.setEnabled(true);
AOETowerbutton.addActionListener(this);
this.add(AOETowerbutton);
ImageIcon BasicTowericon = new ImageIcon("src/resources/images/Basic Tower.png", "Basic tower sprite");
BasicTowerbutton = new JButton("Basic Tower", BasicTowericon);
BasicTowerbutton.setActionCommand("select basic tower");
BasicTowerbutton.setEnabled(true);
BasicTowerbutton.addActionListener(this);
this.add(BasicTowerbutton);
}
public void actionPerformed(ActionEvent e){
if("select aoe tower".equals(e.getActionCommand())){
AOETowerbutton.setEnabled(true);
towerPlacerVar = 2;
System.out.println("AOE tower selected!");
}
else if("select basic tower".equals(e.getActionCommand())){
BasicTowerbutton.setEnabled(true);
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);
}
public void updateMoney(){
moneyLabel.setText("[Money]: $ " + playermoney);
}
public void updateNumTowers(){
towersnumLabel.setText("[# of Towers]: " + map.TF.quantity);
}
}