PIbd-21_Potapov_N.S._Stormt.../ProjectStormtrooper/FormDoubleParametrized.java

79 lines
2.7 KiB
Java
Raw Normal View History

package ProjectStormtrooper;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.util.Random;
public class FormDoubleParametrized {
private JPanel PictureBox;
private JButton buttonGeneratePlane;
Random _random;
DrawingPlane _drawingPlane;
DoubleParametrized<EntityPlane, IDrawingEngines> _doubleParametrized;
public JPanel getPictureBox() {
return PictureBox;
}
public FormDoubleParametrized() {
_random = new Random();
_doubleParametrized = new DoubleParametrized<>();
PictureBox.setPreferredSize(new Dimension(400, 400));
buttonGeneratePlane.addActionListener(this::buttonGeneratePlaneClicked);
}
private void addRandomEntityPlane() {
EntityPlane entityPlane;
if (_random.nextBoolean()) {
entityPlane = new EntityPlane(
_random.nextInt(100, 300),
_random.nextInt(1000, 3000),
new Color(_random.nextInt(256), _random.nextInt(256), _random.nextInt(256))
);
} else {
entityPlane = new EntityStormtrooper(
_random.nextInt(100, 300),
_random.nextInt(1000, 3000),
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()
);
}
_doubleParametrized.Add(entityPlane);
}
private void addRandomDrawingEngine() {
int choice = _random.nextInt(3);
IDrawingEngines drawingEngines;
if (choice == 0) {
drawingEngines = new DrawingEnginesSimple();
} else if (choice == 1) {
drawingEngines = new DrawingEnginesEllipse();
} else {
drawingEngines = new DrawingEnginesPyramid();
}
drawingEngines.SetEnumEnginesCount(_random.nextInt(2, 7));
_doubleParametrized.Add(drawingEngines);
}
public void buttonGeneratePlaneClicked(ActionEvent e) {
addRandomEntityPlane();
addRandomDrawingEngine();
_drawingPlane = _doubleParametrized.GeneratePlane(PictureBox.getWidth(), PictureBox.getHeight());
_drawingPlane.SetPosition((PictureBox.getWidth() - _drawingPlane._planeWidth) / 2, (PictureBox.getHeight() - _drawingPlane._planeHeight) / 2);
Draw();
}
public void Draw() {
if (_drawingPlane == null) {
return;
}
Graphics g = PictureBox.getGraphics();
PictureBox.paint(g);
_drawingPlane.DrawTransport(g);
}
}