Selling towers

This commit is contained in:
Yohann D'ANELLO 2020-02-25 11:17:23 +01:00
parent b97f662d70
commit 1c7762c40c
1 changed files with 27 additions and 4 deletions

View File

@ -8,8 +8,6 @@ import fr.ynerant.leveleditor.editor.CollidPanel;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.awt.event.MouseListener; import java.awt.event.MouseListener;
import java.util.List; import java.util.List;
@ -26,6 +24,7 @@ public class GameFrame extends JFrame {
private List<Mob> mobs = new ArrayList<>(); private List<Mob> mobs = new ArrayList<>();
private List<Tower> towers = new ArrayList<>(); private List<Tower> towers = new ArrayList<>();
private JRadioButton basicTower, nullTower, autoTower;
private JLabel waveLabel; private JLabel waveLabel;
private JLabel nbMobsLabel; private JLabel nbMobsLabel;
private JLabel hpLabel; private JLabel hpLabel;
@ -47,7 +46,7 @@ public class GameFrame extends JFrame {
this.setContentPane(root); this.setContentPane(root);
JPanel pane = new JPanel(); JPanel pane = new JPanel();
pane.setLayout(new GridLayout(5, 1)); pane.setLayout(new GridLayout(8, 1));
root.add(pane, BorderLayout.SOUTH); root.add(pane, BorderLayout.SOUTH);
Grid grid = new Grid(); Grid grid = new Grid();
@ -57,6 +56,21 @@ public class GameFrame extends JFrame {
grid.setMaximumSize(grid.getSize()); grid.setMaximumSize(grid.getSize());
root.add(grid, BorderLayout.CENTER); root.add(grid, BorderLayout.CENTER);
ButtonGroup towerSelect = new ButtonGroup();
basicTower = new JRadioButton("Tour basique (" + new BasicTower(0, 0).getPrice() + " pièces)");
basicTower.setSelected(true);
towerSelect.add(basicTower);
pane.add(basicTower);
nullTower = new JRadioButton("Tour nulle (" + new NullTower(0, 0).getPrice() + " pièces)");
towerSelect.add(nullTower);
pane.add(nullTower);
autoTower = new JRadioButton("Tour automatique (" + new AutoTower(0, 0).getPrice() + " pièces)");
towerSelect.add(autoTower);
pane.add(autoTower);
waveLabel = new JLabel(); waveLabel = new JLabel();
pane.add(waveLabel); pane.add(waveLabel);
@ -183,7 +197,16 @@ public class GameFrame extends JFrame {
@Override @Override
public void mouseReleased(MouseEvent event) { public void mouseReleased(MouseEvent event) {
towers.add(new BasicTower(event.getX() / 32, event.getY() / 32)); int x = event.getX() / 32, y = event.getY() / 32;
Tower tower = basicTower.isSelected() ? new BasicTower(x, y) :
nullTower.isSelected() ? new NullTower(x, y) :
autoTower.isSelected() ? new AutoTower(x, y) :
null;
if (tower == null || tower.getPrice() > reward)
return;
reward -= tower.getPrice();
towers.add(tower);
} }
@Override @Override