Skip to content
Permalink
3b17dc257d
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
145 lines (117 sloc) 4.01 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 buttonAOETower, buttonBasicTower, buttonSellTower, buttonUpgradeTower;
public int towerPlacerVar = 1; //1:Basic, 2:AOE, 3:Sell, 4:Upgrade
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, 20));
hpLabel.setForeground(Color.BLUE);
this.add(hpLabel);
moneyLabel = new JLabel();
moneyLabel.setFont(new Font("Serif", Font.BOLD, 20));
moneyLabel.setForeground(Color.BLUE);
this.add(moneyLabel);
towersnumLabel = new JLabel();
towersnumLabel.setFont(new Font("Serif", Font.BOLD, 20));
towersnumLabel.setForeground(Color.BLUE);
this.add(towersnumLabel);
ImageIcon iconAOE = new ImageIcon("src/resources/images/AOE Tower.png", "AOE tower sprite");
buttonAOETower = new JButton("AOE Tower ($" + TowerTypes.AOE.getBuycost() + ")", iconAOE);
buttonAOETower.setActionCommand("select aoe tower");
buttonAOETower.setEnabled(true);
buttonAOETower.addActionListener(this);
this.add(buttonAOETower);
ImageIcon iconBasicTower = new ImageIcon("src/resources/images/Basic Tower.png", "Basic tower sprite");
buttonBasicTower = new JButton("Basic Tower ($" + TowerTypes.BASIC.getBuycost() + ")", iconBasicTower);
buttonBasicTower.setActionCommand("select basic tower");
buttonBasicTower.setEnabled(true);
buttonBasicTower.addActionListener(this);
this.add(buttonBasicTower);
ImageIcon iconSellTower = new ImageIcon("src/resources/images/Sell Button.png", "Sell tower sprite");
buttonSellTower = new JButton("Sell Tower" , iconSellTower);
buttonSellTower.setActionCommand("select sell");
buttonSellTower.setEnabled(true);
buttonSellTower.addActionListener(this);
this.add(buttonSellTower);
ImageIcon iconUpgradeTower = new ImageIcon("src/resources/images/Upgrade Button.png", "Sell tower sprite");
buttonUpgradeTower = new JButton("Upgrade Tower" , iconUpgradeTower);
buttonUpgradeTower.setActionCommand("select upgrade");
buttonUpgradeTower.setEnabled(true);
buttonUpgradeTower.addActionListener(this);
this.add(buttonUpgradeTower);
}
public void actionPerformed(ActionEvent e){
if("select aoe tower".equals(e.getActionCommand())){
buttonAOETower.setEnabled(true);
towerPlacerVar = 2;
System.out.println("AOE tower selected!");
}
else if("select basic tower".equals(e.getActionCommand())){
buttonBasicTower.setEnabled(true);
towerPlacerVar = 1;
System.out.println("Basic tower selected!");
}
else if("select sell".equals(e.getActionCommand())){
buttonSellTower.setEnabled(true);
towerPlacerVar = 3;
System.out.println("Sell selected!");
}
else if("select upgrade".equals(e.getActionCommand())){
buttonUpgradeTower.setEnabled(true);
towerPlacerVar = 4;
System.out.println("Upgrade 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);
}
}