2022-12-02 00:06:03 +04:00
|
|
|
|
import javax.imageio.ImageIO;
|
|
|
|
|
import javax.swing.*;
|
|
|
|
|
import java.awt.*;
|
|
|
|
|
import java.awt.event.ActionEvent;
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
|
|
import java.awt.image.BufferedImage;
|
|
|
|
|
import java.util.Random;
|
|
|
|
|
|
|
|
|
|
public class FormMap extends JFrame{
|
|
|
|
|
private JButton ButtonCreateModif;
|
|
|
|
|
private JButton ButtonLeft;
|
|
|
|
|
private JButton ButtonDown;
|
|
|
|
|
private JButton ButtonRight;
|
|
|
|
|
private JButton ButtonUp;
|
|
|
|
|
private JButton ButtonCreate;
|
|
|
|
|
private JComboBox ComboBoxSelectorMap;
|
|
|
|
|
private AbstractMap _abstractMap;
|
|
|
|
|
private JPanel pictureBoxShip;
|
|
|
|
|
private JToolBar StatusStrip;
|
|
|
|
|
public JPanel MainPanel;
|
|
|
|
|
private Random random = new Random();
|
|
|
|
|
protected DrawingShip _ship;
|
|
|
|
|
|
|
|
|
|
private BufferedImage bufferImg = null;
|
|
|
|
|
private JLabel JLabelSpeed = new JLabel();
|
|
|
|
|
private JLabel JLabelWeight = new JLabel();
|
|
|
|
|
private JLabel JLabelColor = new JLabel();
|
|
|
|
|
|
|
|
|
|
public void Draw() {
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
BufferedImage bmp = new BufferedImage(pictureBoxShip.getWidth(), pictureBoxShip.getHeight(),BufferedImage.TYPE_INT_RGB);
|
|
|
|
|
Graphics gr = bmp.getGraphics();
|
|
|
|
|
gr.setColor(new Color(238, 238, 238));
|
|
|
|
|
gr.fillRect(0, 0, pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
|
|
|
|
if (_ship != null) {
|
|
|
|
|
_ship.DrawTransport(gr);
|
2022-12-08 18:53:50 +04:00
|
|
|
|
JLabel imageOfShip = new JLabel();
|
|
|
|
|
imageOfShip.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageOfShip.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageOfShip.setIcon(new ImageIcon(bmp));
|
|
|
|
|
pictureBoxShip.add(imageOfShip,BorderLayout.CENTER);
|
2022-12-02 00:06:03 +04:00
|
|
|
|
}
|
|
|
|
|
validate();
|
|
|
|
|
}
|
|
|
|
|
public void SetData(DrawingShip _ship)
|
|
|
|
|
{
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
JLabelSpeed.setText("Cкорость: " + _ship.GetShip().GetSpeed() + " ");
|
|
|
|
|
JLabelWeight.setText("Вес: " + _ship.GetShip().GetWeight() + " ");
|
|
|
|
|
JLabelColor.setText(("Цвет: " + _ship.GetShip().GetBodyColor() + " "));
|
|
|
|
|
JLabel imageWithMapAndObject = new JLabel();
|
|
|
|
|
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.CreateMap(pictureBoxShip.getWidth(),pictureBoxShip.getHeight(), new DrawingObjectShip(_ship))));
|
|
|
|
|
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
|
|
|
|
pictureBoxShip.revalidate();
|
|
|
|
|
}
|
|
|
|
|
@Override
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
super.paint(g);
|
|
|
|
|
Draw();
|
|
|
|
|
}
|
|
|
|
|
public FormMap() {
|
|
|
|
|
_abstractMap = new SimpleMap();
|
|
|
|
|
Box LabelBox = Box.createHorizontalBox();
|
|
|
|
|
LabelBox.setMinimumSize(new Dimension(1, 20));
|
|
|
|
|
LabelBox.add(JLabelSpeed);
|
|
|
|
|
LabelBox.add(JLabelWeight);
|
|
|
|
|
LabelBox.add(JLabelColor);
|
|
|
|
|
StatusStrip.add(LabelBox);
|
|
|
|
|
try {
|
|
|
|
|
Image img = ImageIO.read(FormShip.class.getResource("Images/4.png"));
|
|
|
|
|
ButtonUp.setIcon(new ImageIcon(img));
|
|
|
|
|
img = ImageIO.read(FormShip.class.getResource("Images/2.png"));
|
|
|
|
|
ButtonDown.setIcon(new ImageIcon(img));
|
|
|
|
|
img = ImageIO.read(FormShip.class.getResource("Images/1.png"));
|
|
|
|
|
ButtonLeft.setIcon(new ImageIcon(img));
|
|
|
|
|
img = ImageIO.read(FormShip.class.getResource("Images/3.png"));
|
|
|
|
|
ButtonRight.setIcon(new ImageIcon(img));
|
|
|
|
|
} catch (Exception ex) {
|
|
|
|
|
System.out.println(ex);
|
|
|
|
|
}
|
|
|
|
|
_ship=new DrawingShip (random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
|
|
|
|
ButtonCreate.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
var _ship=new DrawingShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)));
|
|
|
|
|
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
|
|
|
|
SetData(_ship);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ButtonUp.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
JLabel imageWithMapAndObject = new JLabel();
|
|
|
|
|
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Up)));
|
|
|
|
|
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
|
|
|
|
pictureBoxShip.revalidate();
|
|
|
|
|
pictureBoxShip.repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ButtonDown.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
JLabel imageWithMapAndObject = new JLabel();
|
|
|
|
|
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Down)));
|
|
|
|
|
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
|
|
|
|
pictureBoxShip.revalidate();
|
|
|
|
|
pictureBoxShip.repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ButtonRight.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
JLabel imageWithMapAndObject = new JLabel();
|
|
|
|
|
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Right)));
|
|
|
|
|
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
|
|
|
|
pictureBoxShip.revalidate();
|
|
|
|
|
pictureBoxShip.repaint();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ButtonLeft.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
pictureBoxShip.removeAll();
|
|
|
|
|
JLabel imageWithMapAndObject = new JLabel();
|
|
|
|
|
imageWithMapAndObject.setPreferredSize(pictureBoxShip.getSize());
|
|
|
|
|
imageWithMapAndObject.setMinimumSize(new Dimension(1, 1));
|
|
|
|
|
imageWithMapAndObject.setIcon(new ImageIcon(_abstractMap.MoveObject(Direction.Left)));
|
|
|
|
|
pictureBoxShip.add(imageWithMapAndObject, BorderLayout.CENTER);
|
|
|
|
|
pictureBoxShip.revalidate();
|
|
|
|
|
pictureBoxShip.repaint();
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ButtonCreateModif.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
_ship=new DrawingContainerShip(random.nextInt(100, 300), random.nextInt(1000, 2000), new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),random.nextBoolean(),random.nextBoolean());
|
|
|
|
|
_ship.SetPosition(random.nextInt(100, 500), random.nextInt(10, 100), pictureBoxShip.getWidth(), pictureBoxShip.getHeight());
|
|
|
|
|
SetData(_ship);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
ComboBoxSelectorMap.addActionListener(new ActionListener() {
|
|
|
|
|
@Override
|
|
|
|
|
public void actionPerformed(ActionEvent e) {
|
|
|
|
|
ComboBoxSelectorMap = (JComboBox)e.getSource();
|
|
|
|
|
String item = (String)ComboBoxSelectorMap.getSelectedItem();
|
|
|
|
|
switch (item) {
|
|
|
|
|
case "Простая карта":
|
|
|
|
|
_abstractMap = new SimpleMap();
|
|
|
|
|
break;
|
|
|
|
|
case "Острова":
|
|
|
|
|
_abstractMap = new IslandsMap();
|
|
|
|
|
break;
|
|
|
|
|
case "Скалы":
|
|
|
|
|
_abstractMap = new RocksMap();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|