diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..26d3352
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,3 @@
+# Default ignored files
+/shelf/
+/workspace.xml
diff --git a/.idea/PIbd-11_Gorskov_E.M._Hard.iml b/.idea/PIbd-11_Gorskov_E.M._Hard.iml
new file mode 100644
index 0000000..b107a2d
--- /dev/null
+++ b/.idea/PIbd-11_Gorskov_E.M._Hard.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
new file mode 100644
index 0000000..6f29fee
--- /dev/null
+++ b/.idea/misc.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..65056ab
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/image/down.jpg b/src/image/down.jpg
new file mode 100644
index 0000000..fc21b6a
Binary files /dev/null and b/src/image/down.jpg differ
diff --git a/src/image/left.jpg b/src/image/left.jpg
new file mode 100644
index 0000000..453db80
Binary files /dev/null and b/src/image/left.jpg differ
diff --git a/src/image/right.jpg b/src/image/right.jpg
new file mode 100644
index 0000000..1f9989a
Binary files /dev/null and b/src/image/right.jpg differ
diff --git a/src/image/up.jpg b/src/image/up.jpg
new file mode 100644
index 0000000..bfdaef6
Binary files /dev/null and b/src/image/up.jpg differ
diff --git a/src/src.iml b/src/src.iml
new file mode 100644
index 0000000..c90834f
--- /dev/null
+++ b/src/src.iml
@@ -0,0 +1,11 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/src/CanvasAirbus.java b/src/src/CanvasAirbus.java
new file mode 100644
index 0000000..7768d8a
--- /dev/null
+++ b/src/src/CanvasAirbus.java
@@ -0,0 +1,16 @@
+import javax.swing.*;
+import java.awt.*;
+
+public class CanvasAirbus extends JComponent {
+ public DrawingAirbus _drawingAirbus;
+ public CanvasAirbus(){}
+ public void paintComponent(Graphics g) {
+ if (_drawingAirbus == null) {
+ return;
+ }
+ super.paintComponents(g);
+ Graphics2D g2d = (Graphics2D) g;
+ _drawingAirbus.DrawTransport(g2d);
+ super.repaint();
+ }
+}
\ No newline at end of file
diff --git a/src/src/CountPortholes.java b/src/src/CountPortholes.java
new file mode 100644
index 0000000..a07155b
--- /dev/null
+++ b/src/src/CountPortholes.java
@@ -0,0 +1,5 @@
+public enum CountPortholes {
+ Ten,
+ Twenty,
+ Thirty;
+}
\ No newline at end of file
diff --git a/src/src/DirectionType.java b/src/src/DirectionType.java
new file mode 100644
index 0000000..d3a2058
--- /dev/null
+++ b/src/src/DirectionType.java
@@ -0,0 +1,6 @@
+public enum DirectionType {
+ Up,
+ Down,
+ Left,
+ Right
+}
\ No newline at end of file
diff --git a/src/src/DrawingAirbus.java b/src/src/DrawingAirbus.java
new file mode 100644
index 0000000..ad0031f
--- /dev/null
+++ b/src/src/DrawingAirbus.java
@@ -0,0 +1,144 @@
+import javax.swing.*;
+import java.awt.*;
+import java.util.Random;
+
+public class DrawingAirbus extends JPanel {
+ public EntityAirbus EntityAirbus;
+ public DrawingPortholes _portholes = null;
+ private Integer picture_width;
+ private Integer picture_height;
+ private Integer _StartPosX;
+ private Integer _StartPosY;
+ private int drawingAirbusWidth = 185;
+ private int drawingAirbusHeight = 100;
+ public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean sheeppipes, boolean fueltank) {
+ EntityAirbus = new EntityAirbus();
+ EntityAirbus.Init(speed, weight, bodycolor, additionalcolor, sheeppipes, fueltank);
+ picture_width = null;
+ picture_height = null;
+ _StartPosX = null;
+ _StartPosY = null;
+ _portholes = new DrawingPortholes();
+ Random rand = new Random();
+ int randomNum = rand.nextInt(4);
+ _portholes.SetCount(randomNum);
+ }
+ public boolean SetPictureSize(int width, int height) {
+ if (width < drawingAirbusWidth || height < drawingAirbusHeight) return false;
+ picture_width = width;
+ picture_height = height;
+ if (_StartPosX != null || _StartPosY != null) {
+ if (_StartPosX + drawingAirbusWidth > picture_width)
+ {
+ _StartPosX = _StartPosX - (_StartPosX + drawingAirbusWidth - picture_width);
+ }
+ else if (_StartPosX < 0) _StartPosX = 0;
+ if (_StartPosY + drawingAirbusHeight > picture_height)
+ {
+ _StartPosY = _StartPosY - (_StartPosY + drawingAirbusHeight - picture_height);
+ }
+ else if (_StartPosY < 0) _StartPosY = 0;
+ }
+ return true;
+ }
+ public void SetPosition(int x, int y) {
+ if (!(picture_width != null && picture_height != null)) return;
+ if (x + drawingAirbusWidth > picture_width)
+ {
+ _StartPosX = x - (x + drawingAirbusWidth - picture_width);
+ }
+ else if (x < 0) _StartPosX = 0;
+ else _StartPosX = x;
+ if (y + drawingAirbusHeight > picture_height)
+ {
+ _StartPosY = y - (y + drawingAirbusHeight - picture_height);
+ }
+ else if (y < 0) _StartPosY = 0;
+ else _StartPosY = y;
+ }
+
+ public boolean MoveTransport(DirectionType direction) {
+ if (EntityAirbus == null || _StartPosX == null || _StartPosY == null) return false;
+ switch (direction) {
+ case Left:
+ if (_StartPosX - EntityAirbus.Step > 0) {
+ _StartPosX -= (int)EntityAirbus.Step;
+ }
+ return true;
+ case Up:
+ if (_StartPosY - EntityAirbus.Step > 0)
+ {
+ _StartPosY -= (int)EntityAirbus.Step;
+ }
+ return true;
+ case Right:
+ if (_StartPosX + drawingAirbusWidth + (int)EntityAirbus.Step < picture_width - EntityAirbus.Step)
+ {
+ _StartPosX += (int)EntityAirbus.Step;
+ }
+ return true;
+ case Down:
+ if (_StartPosY + drawingAirbusHeight + (int)EntityAirbus.Step < picture_height - EntityAirbus.Step)
+ {
+ _StartPosY += (int)EntityAirbus.Step;
+ }
+ return true;
+ default:
+ return false;
+ }
+ }
+
+ public void DrawTransport(Graphics2D g) {
+
+ if (EntityAirbus == null) {
+ return;
+ }
+ // иллюминаторы
+ _portholes.Draw(g, _StartPosX+30, _StartPosY+34);
+
+ g.setColor(Color.BLACK);
+//Тело
+ g.drawRect(_StartPosX + 5, _StartPosY + 50, 170, 30);
+ g.drawArc(_StartPosX - 5, _StartPosY + 50, 20, 30, 90, 180);
+//Заднее крыло
+ g.drawLine( _StartPosX, _StartPosY, _StartPosX + 50, _StartPosY + 50);
+ g.drawLine( _StartPosX, _StartPosY, _StartPosX, _StartPosY + 52);
+//Заднее боковые крылья
+ g.drawOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
+ g.fillOval(_StartPosX - 7, _StartPosY + 45, 30, 8);
+//Нос
+ g.drawLine( _StartPosX + 175, _StartPosY + 50, _StartPosX + 200, _StartPosY + 65);
+ g.drawLine( _StartPosX + 200, _StartPosY + 65, _StartPosX + 175, _StartPosY + 80);
+ g.drawLine( _StartPosX + 175, _StartPosY + 50, _StartPosX + 175, _StartPosY + 80);
+ g.drawLine( _StartPosX + 175, _StartPosY + 65, _StartPosX + 200, _StartPosY + 65);
+//Крылья
+ g.drawArc(_StartPosX + 49, _StartPosY + 62, 5, 5, 90, 180);
+ g.drawLine( _StartPosX + 51, _StartPosY + 62, _StartPosX + 140, _StartPosY + 62);
+ g.drawArc( _StartPosX + 137, _StartPosY + 62, 5, 5, 2790, 180);
+ g.drawLine( _StartPosX + 51, _StartPosY + 67, _StartPosX + 140, _StartPosY + 67);
+//Задние шасси
+ g.drawLine(_StartPosX + 55, _StartPosY + 80, _StartPosX + 55, _StartPosY + 90);
+ g.drawOval(_StartPosX + 47, _StartPosY + 90, 5, 5);
+ g.drawOval( _StartPosX + 57, _StartPosY + 90, 5, 5);
+//Передние шасси
+ g.drawLine( _StartPosX + 165, _StartPosY + 80, _StartPosX + 165, _StartPosY + 90);
+ g.drawOval( _StartPosX + 163, _StartPosY + 91, 5, 5);
+//Пассажирсакий доп. отсек
+ if (EntityAirbus.getIsCompartmen())
+ {
+ g.setColor(EntityAirbus.getAdditionalColor());
+ g.drawArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
+ g.fillArc(_StartPosX + 60, _StartPosY + 28, 115, 45, 0, 180);
+ }
+// Доп. двигатели
+ if (EntityAirbus.getIsAdditionalEngine())
+ {
+ g.drawLine(_StartPosX + 95, _StartPosY + 68, _StartPosX + 95, _StartPosY + 75);
+ g.setColor(EntityAirbus.getAdditionalColor());
+ int[] xPolygon = { _StartPosX + 83, _StartPosX + 103, _StartPosX + 103, _StartPosX + 83, _StartPosX + 83};
+ int[] yPolygon = {_StartPosY + 78, _StartPosY + 73, _StartPosY + 93, _StartPosY + 88, _StartPosY + 78};
+ g.drawPolygon(xPolygon, yPolygon, xPolygon.length);
+ g.fillPolygon(xPolygon, yPolygon, xPolygon.length);
+ }
+ }
+}
diff --git a/src/src/DrawingPortholes.java b/src/src/DrawingPortholes.java
new file mode 100644
index 0000000..81fd49d
--- /dev/null
+++ b/src/src/DrawingPortholes.java
@@ -0,0 +1,63 @@
+import java.awt.*;
+
+public class DrawingPortholes {
+ private CountPortholes _porthole;
+
+ public CountPortholes getCount() {
+ return _porthole;
+ }
+
+ public void SetCount(int count) {
+ switch (count) {
+ case 1: // 10
+ _porthole = CountPortholes.Ten;
+ break;
+ case 2: // 20
+ _porthole = CountPortholes.Twenty;
+ break;
+ case 3: // 30
+ _porthole = CountPortholes.Thirty;
+ break;
+ default:
+ _porthole = CountPortholes.Ten;
+ break;
+ }
+ }
+
+ public void Draw(Graphics2D g, int _startPosx, int _startPoxY) {
+ g.setColor(Color.BLACK);
+ if (_porthole == null) {
+ return;
+ }
+
+ for (int i = 0; i < 10; ++i) {
+ g.setColor(Color.cyan);
+ g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
+ g.setColor(Color.black);
+ g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 21, 3, 3);
+ }
+
+ if (_porthole != CountPortholes.Ten) {
+ for (int i = 0; i < 5; ++i) {
+ g.setColor(Color.cyan);
+ g.fillOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
+ g.setColor(Color.black);
+ g.drawOval(_startPosx - 15 + i * 5, _startPoxY + 28, 3, 3);
+ }
+ for (int i = 0; i < 5; ++i) {
+ g.setColor(Color.cyan);
+ g.fillOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
+ g.setColor(Color.black);
+ g.drawOval(_startPosx + 115 + i * 5, _startPoxY + 28, 3, 3);
+ }
+ }
+ if (_porthole == CountPortholes.Thirty) {
+ for (int i = 0; i < 10; ++i) {
+ g.setColor(Color.cyan);
+ g.fillOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
+ g.setColor(Color.black);
+ g.drawOval(_startPosx + 19 + i * 8, _startPoxY + 37, 3, 3);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/src/EntityAirbus.java b/src/src/EntityAirbus.java
new file mode 100644
index 0000000..de7f62a
--- /dev/null
+++ b/src/src/EntityAirbus.java
@@ -0,0 +1,24 @@
+import java.awt.*;
+public class EntityAirbus {
+ private int Speed;
+ private double Weight;
+ private Color BodyColor;
+ public Color getBodyColor() {return BodyColor;}
+ private Color AdditionalColor;
+ public Color getAdditionalColor() {return AdditionalColor;}
+ private boolean IsCompartment;
+ public boolean getIsCompartmen() {return IsCompartment;}
+ private boolean IsAdditionalEngine;
+ public boolean getIsAdditionalEngine() {return IsAdditionalEngine;}
+ public double Step;
+ public void Init(int speed, double weight, Color bodycolor, Color additionalcolor, boolean isCompartment, boolean isAdditionalEngine)
+ {
+ Speed = speed;
+ Weight = weight;
+ BodyColor = bodycolor;
+ AdditionalColor = additionalcolor;
+ IsCompartment = isCompartment;
+ IsAdditionalEngine = isAdditionalEngine;
+ Step = Speed * 100 / Weight;
+ }
+}
diff --git a/src/src/FormAirbus.java b/src/src/FormAirbus.java
new file mode 100644
index 0000000..e35cfe6
--- /dev/null
+++ b/src/src/FormAirbus.java
@@ -0,0 +1,123 @@
+import javax.swing.*;
+import java.awt.*;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ComponentAdapter;
+import java.awt.event.ComponentEvent;
+import java.util.Random;
+
+public class FormAirbus extends JFrame {
+ private String title;
+ private Dimension dimension;
+ private int Width, Height;
+ private CanvasAirbus canvasAirbus = new CanvasAirbus();
+ private JButton CreateButton = new JButton("Create");;
+ private JButton UpButton = new JButton();
+ private JButton DownButton = new JButton();;
+ private JButton LeftButton = new JButton();;
+ private JButton RightButton = new JButton();
+ public FormAirbus(String title, Dimension dimension) {
+ this.title = title;
+ this.dimension = dimension;
+ }
+ public void Init() {
+ setTitle(title);
+ setMinimumSize(dimension);
+ setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
+ Width = getWidth() - 15;
+ Height = getHeight() - 35;
+
+ CreateButton.setName("CREATE");
+ Icon iconUp = new ImageIcon("src\\image\\up.jpg");
+ UpButton.setIcon(iconUp);
+ UpButton.setName("UP");
+ DownButton.setName("DOWN");
+ Icon iconDown = new ImageIcon("src\\image\\down.jpg");
+ DownButton.setIcon(iconDown);
+ LeftButton.setName("LEFT");
+ Icon iconLeft = new ImageIcon("src\\image\\left.jpg");
+ LeftButton.setIcon(iconLeft);
+ RightButton.setName("RIGHT");
+ Icon iconRight = new ImageIcon("src\\image\\right.jpg");
+ RightButton.setIcon(iconRight);
+
+ CreateButton.addActionListener(new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent e) {
+ int StartPositionX = (int)(Math.random() * 90 + 10);
+ int StartPositionY = (int)(Math.random() * 90 + 10);
+ int speed = (int)(Math.random() * 300 + 100);
+ double weight = (double)(Math.random() * 3000 + 1000);
+ Color bodyColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));
+ Color additionalColor = new Color((int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0),(int)(Math.random() * 255 + 0));;
+ boolean sheepPipes = new Random().nextBoolean();
+ boolean fuelTank = new Random().nextBoolean();;
+ canvasAirbus._drawingAirbus = new DrawingAirbus();
+ canvasAirbus._drawingAirbus.Init(speed, weight, bodyColor, additionalColor, sheepPipes, fuelTank);
+ canvasAirbus._drawingAirbus.SetPictureSize(Width, Height);
+ canvasAirbus._drawingAirbus.SetPosition( StartPositionX, StartPositionY);
+ canvasAirbus.repaint();
+ }
+ });
+
+ ActionListener actionListener = new ActionListener() {
+ @Override
+ public void actionPerformed(ActionEvent event) {
+ if (canvasAirbus._drawingAirbus == null) return;
+ boolean result = false;
+ switch ((((JButton)(event.getSource())).getName())) {
+ case "UP":
+ result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Up);
+ break;
+ case "DOWN":
+ result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Down);
+ break;
+ case "LEFT":
+ result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Left);
+ break;
+ case "RIGHT":
+ result = canvasAirbus._drawingAirbus.MoveTransport(DirectionType.Right);
+ break;
+ }
+ if (result) {
+ canvasAirbus.repaint();
+ }
+ }
+ };
+ UpButton.addActionListener(actionListener);
+ DownButton.addActionListener(actionListener);
+ LeftButton.addActionListener(actionListener);
+ RightButton.addActionListener(actionListener);
+
+ setSize(dimension.width,dimension.height);
+ setLayout(null);
+ canvasAirbus.setBounds(0,0, getWidth(), getHeight());
+ CreateButton.setBounds(10, getHeight() - 90, 100, 40);
+ UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
+ DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
+ RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
+ LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
+ add(CreateButton);
+ add(UpButton);
+ add(DownButton);
+ add(RightButton);
+ add(LeftButton);
+ add(canvasAirbus);
+ setVisible(true);
+ //обработка события изменения размеров окна
+ addComponentListener(new ComponentAdapter() {
+ public void componentResized(ComponentEvent e) {
+ Width = getWidth() - 15;
+ Height = getHeight() - 35;
+ if (canvasAirbus._drawingAirbus != null)
+ canvasAirbus._drawingAirbus.SetPictureSize(Width, Height);
+ canvasAirbus.setBounds(0,0, getWidth(), getHeight());
+ CreateButton.setBounds(10, getHeight() - 90, 100, 40);
+ UpButton.setBounds(getWidth() - 140, getHeight() - 160, 50, 50);
+ DownButton.setBounds(getWidth() - 140, getHeight() - 100, 50, 50);
+ RightButton.setBounds(getWidth() - 80, getHeight() - 100, 50, 50);
+ LeftButton.setBounds(getWidth() - 200, getHeight() - 100, 50, 50);
+ }
+ });
+ }
+}
diff --git a/src/src/Main.java b/src/src/Main.java
new file mode 100644
index 0000000..2871a6b
--- /dev/null
+++ b/src/src/Main.java
@@ -0,0 +1,8 @@
+import java.awt.*;
+
+public class Main {
+ public static void main(String[] args) {
+ FormAirbus form = new FormAirbus("Самолёт", new Dimension(500, 500));
+ form.Init();
+ }
+}
\ No newline at end of file