From 88f057c2fa04f0c04e04318db1bb73de7a1da730 Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Mon, 16 Oct 2023 20:23:52 +0300 Subject: [PATCH 1/2] =?UTF-8?q?1=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/DirectionType.java | 6 + src/DrawningAirplaneWithRadar.java | 171 +++++++++++++++++++++++++++++ src/DrawningIlluminators.java | 57 ++++++++++ src/EntityAirplaneWithRadar.java | 43 ++++++++ src/Main.java | 87 +++++++++++++++ src/NumberType.java | 5 + 6 files changed, 369 insertions(+) create mode 100644 src/DirectionType.java create mode 100644 src/DrawningAirplaneWithRadar.java create mode 100644 src/DrawningIlluminators.java create mode 100644 src/EntityAirplaneWithRadar.java create mode 100644 src/Main.java create mode 100644 src/NumberType.java diff --git a/src/DirectionType.java b/src/DirectionType.java new file mode 100644 index 0000000..35657f0 --- /dev/null +++ b/src/DirectionType.java @@ -0,0 +1,6 @@ +public enum DirectionType { + Up, + Down, + Left, + Right +} diff --git a/src/DrawningAirplaneWithRadar.java b/src/DrawningAirplaneWithRadar.java new file mode 100644 index 0000000..3b58871 --- /dev/null +++ b/src/DrawningAirplaneWithRadar.java @@ -0,0 +1,171 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; +public class DrawningAirplaneWithRadar { + JPanel AirplaneWithRadarPanel; + private EntityAirplaneWithRadar EntityAirplaneWithRadar; + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX = 0; + private int _startPosY = 0; + private int _airplaneWidth = 200; + private int _airplaneHeight = 78; + private DrawningIlluminators DrawningIlluminators; + public EntityAirplaneWithRadar EntityAirplaneWithRadar(){ + return EntityAirplaneWithRadar; + } + public boolean Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb, + int width, int height, boolean radar, boolean dopBak, JPanel airplaneWithRadarPanel){ + if(width <= _airplaneWidth || height <= _airplaneHeight) + return false; + _startPosY=0; + _startPosX = 0; + airplaneWithRadarPanel.setSize(width, height); + AirplaneWithRadarPanel = airplaneWithRadarPanel; + airplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics()); + _pictureWidth = width; + _pictureHeight = height; + EntityAirplaneWithRadar = new EntityAirplaneWithRadar(); + EntityAirplaneWithRadar.Init(speed, weight, bodyColor, illuminatorColor, additionalColor, illuminatorNumb, radar, dopBak); + DrawningIlluminators = new DrawningIlluminators(); + DrawningIlluminators.Init(_airplaneWidth, _airplaneHeight,_startPosX,_startPosY,illuminatorColor,airplaneWithRadarPanel); + Random rand = new Random(); + DrawningIlluminators.ChangeIlluminatorNumb(rand.nextInt(1, 5)); + return true; + } + public void SetPosition(int x, int y){ + if (x < 0 || y < 0 || x + _airplaneWidth >= _pictureWidth || y + _airplaneHeight >= _pictureHeight) + { + x = y = 10; + _startPosX = x; + _startPosY = y; + } + _startPosX = x; + _startPosY = y; + DrawningIlluminators.CurX = _startPosX; + DrawningIlluminators.CurY = _startPosY; + } + public void MoveTransport(DirectionType direction){ + if (EntityAirplaneWithRadar == null) + return; + AirplaneWithRadarPanel.paint(AirplaneWithRadarPanel.getGraphics()); + switch (direction) + { + case Left: + if (_startPosX - EntityAirplaneWithRadar.Step() >= 0) + _startPosX -= (int)EntityAirplaneWithRadar.Step(); + else + _startPosX = 0; + break; + case Up: + if (_startPosY - EntityAirplaneWithRadar.Step() >= 0) + _startPosY -= (int)EntityAirplaneWithRadar.Step(); + else + _startPosY = 0; + break; + case Right: + if (_startPosX + EntityAirplaneWithRadar.Step() + _airplaneWidth < _pictureWidth) + _startPosX += (int)EntityAirplaneWithRadar.Step(); + else + _startPosX = _pictureWidth - _airplaneWidth; + break; + case Down: + if (_startPosY + EntityAirplaneWithRadar.Step() + _airplaneHeight < _pictureHeight) + _startPosY += (int)EntityAirplaneWithRadar.Step(); + else + _startPosY = _pictureHeight - _airplaneHeight; + break; + } + DrawningIlluminators.CurX = _startPosX; + DrawningIlluminators.CurY = _startPosY; + } + public void DrawAirplaneWithRadar(){ + Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics(); + if (EntityAirplaneWithRadar == null) + return; + g2d.setColor(Color.BLACK); + g2d.setStroke(new BasicStroke(3)); +// корпус + g2d.setColor(EntityAirplaneWithRadar.BodyColor()); + g2d.fillOval(_startPosX, _startPosY + 25, 180, 30); + g2d.setColor(Color.BLACK); + g2d.drawOval(_startPosX, _startPosY + 25, 180, 30); +// крыло + g2d.setColor(Color.BLACK); + g2d.fillOval(_startPosX + 70, _startPosY + 35, 80, 10); +// стекла + g2d.setColor(Color.BLUE); + int[] curvePointsX = + { + _startPosX + 170, + _startPosX + 200, + _startPosX + 170, + }; + int[] curvePointsY = + { + _startPosY + 30, + _startPosY + 40, + _startPosY + 50, + }; + g2d.fillPolygon(curvePointsX,curvePointsY,curvePointsY.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(curvePointsX,curvePointsY,curvePointsY.length); + g2d.drawLine(_startPosX + 170, _startPosY + 40, _startPosX + 200, _startPosY + 40); +// хвост + g2d.setColor(Color.BLUE); + int[] curvePoints2x = + { + _startPosX, + _startPosX, + _startPosX + 30, + }; + int[] curvePoints2y = + { + _startPosY + 35, + _startPosY + 5, + _startPosY + 35, + }; + g2d.fillPolygon(curvePoints2x,curvePoints2y, curvePoints2x.length); + g2d.setColor(Color.BLACK); + g2d.drawPolygon(curvePoints2x,curvePoints2y, curvePoints2x.length); +// шасси + g2d.setColor(Color.BLACK); + g2d.drawLine(_startPosX + 50, _startPosY + 55, _startPosX + 50, _startPosY + 70); + g2d.drawLine(_startPosX + 150, _startPosY + 51, _startPosX + 150, _startPosY + 70); + g2d.fillOval(_startPosX + 40, _startPosY + 65, 10, 10); + g2d.fillOval(_startPosX + 50, _startPosY + 65, 10, 10); + g2d.fillOval(_startPosX + 145, _startPosY + 65, 10, 10); +//дополнительный бак + if (EntityAirplaneWithRadar().DopBak()) { + g2d.setColor(EntityAirplaneWithRadar.AdditionalColor()); + g2d.fillOval( _startPosX, _startPosY + 45, 40, 20); + g2d.setColor(Color.BLACK); + g2d.drawOval(_startPosX, _startPosY + 45, 40, 20); + } +//радар + if (EntityAirplaneWithRadar.Radar()) + { + g2d.setColor(Color.BLACK); + g2d.drawLine(_startPosX + 60, _startPosY + 25, _startPosX + 60, _startPosY + 15); + g2d.drawLine( _startPosX + 60, _startPosY + 15, _startPosX + 67, _startPosY + 11); + g2d.setColor(EntityAirplaneWithRadar.AdditionalColor()); + Point point7 = new Point(_startPosX + 60, _startPosY + 15); + Point point8 = new Point(_startPosX + 60, _startPosY + 5); + Point point9 = new Point(_startPosX + 70, _startPosY + 25); + int[] curvePoints3x = + { + _startPosX + 60, + _startPosX + 60, + _startPosX + 70, + }; + int[] curvePoints3y = + { + _startPosY + 15, + _startPosY + 5, + _startPosY + 25, + }; + g2d.fillPolygon(curvePoints3x, curvePoints3y,curvePoints3x.length); + } + DrawningIlluminators.DrawIlluminators(); + } +} diff --git a/src/DrawningIlluminators.java b/src/DrawningIlluminators.java new file mode 100644 index 0000000..ae9cce1 --- /dev/null +++ b/src/DrawningIlluminators.java @@ -0,0 +1,57 @@ +import javax.swing.*; +import java.awt.*; +public class DrawningIlluminators { + JPanel AirplaneWithRadarPanel; + private NumberType IlluminatorNumb; + private Color IlluminatorColor; + private int Width, Height; + public int CurX, CurY; + boolean Init(int width, int height, int curX, int curY, Color illuminatorColor, JPanel airplaneWithRadarPanel){ + Width = width; + Height = height; + CurX = curX; + CurY = curY; + IlluminatorColor = illuminatorColor; + AirplaneWithRadarPanel = airplaneWithRadarPanel; + return true; + } + public void ChangeIlluminatorNumb(int x){ + if(x <= 2) + IlluminatorNumb = NumberType.Ten; + if(x == 3) + IlluminatorNumb = NumberType.Twenty; + if(x >= 4) + IlluminatorNumb = NumberType.Thirty; + } + public NumberType IlluminatorNumb(){ + return IlluminatorNumb; + } + public void DrawIlluminators(){ + Graphics2D g2d = (Graphics2D)AirplaneWithRadarPanel.getGraphics(); + g2d.setColor(IlluminatorColor); + int x = CurX; + int y = CurY; + for( int i =0; i<10;i++){ + g2d.fillOval( x+34 , y+29 , 5, 5); + x+=7; + } +//20 иллюминаторов + if (IlluminatorNumb == NumberType.Twenty || IlluminatorNumb == NumberType.Thirty) + { + x = CurX; + for( int i =0; i<10;i++){ + g2d.fillOval( x+34 , y+37 , 5, 5); + x+=7; + } + } +//30 иллюминаторов + if (IlluminatorNumb == NumberType.Thirty) + { + x = CurX; + for( int i =0; i<10;i++){ + g2d.fillOval( x+34 , y+45 , 5, 5); + x+=7; + } + } + } +} diff --git a/src/EntityAirplaneWithRadar.java b/src/EntityAirplaneWithRadar.java new file mode 100644 index 0000000..2a472d2 --- /dev/null +++ b/src/EntityAirplaneWithRadar.java @@ -0,0 +1,43 @@ +import java.awt.*; +public class EntityAirplaneWithRadar { + private int Speed, IlluminatorNumb; + private double Weight, Step; + private Color BodyColor, AdditionalColor, IlluminatorColor; + private boolean Radar; + private boolean DopBak; + public int Speed(){ + return Speed; + } + public int IlluminatorNumb(){ + return IlluminatorNumb; + } + public double Weight(){ + return Weight; + } + public double Step(){ + return Step; + } + public Color BodyColor(){ + return BodyColor; + } + public Color AdditionalColor(){ + return AdditionalColor; + } + public Color IlluminatorColor(){ + return IlluminatorColor; + } + public boolean Radar(){return Radar;} + public boolean DopBak(){return DopBak;} + public void Init(int speed, double weight, Color bodyColor, Color illuminatorColor, Color additionalColor, int illuminatorNumb, + boolean radar, boolean dopBak ){ + Speed = speed; + Weight = weight; + Step = (double)Speed * 100 / Weight; + BodyColor = bodyColor; + IlluminatorColor=illuminatorColor; + AdditionalColor = additionalColor; + IlluminatorNumb = illuminatorNumb; + Radar = radar; + DopBak = dopBak; + } +} diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..96feeb9 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,87 @@ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; +import javax.swing.*; +public class Main { + public static void main(String[] args) { + JFrame AirplaneWithRadarFrame = new JFrame(); + JPanel AirplaneWithRadarPanel = new JPanel(); + AirplaneWithRadarFrame.setLayout(new BorderLayout()); + AirplaneWithRadarFrame.setSize(900, 500); + AirplaneWithRadarFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + AirplaneWithRadarFrame.setLayout(new BorderLayout(1,1)); + AirplaneWithRadarFrame.setResizable(false); + DrawningAirplaneWithRadar DrawningEntityAirplaneWithRadar = new DrawningAirplaneWithRadar(); + AirplaneWithRadarPanel.setLayout(null); + JButton RightButton = new JButton("→"); + JButton LeftButton = new JButton("←"); + JButton UpButton = new JButton("↑"); + JButton DownButton = new JButton("↓"); + JButton CreateButton = new JButton(); + CreateButton.setText("Создать"); + CreateButton.setBounds(12, 401, 90, 40); + RightButton.setBounds(840,411,30,30); + LeftButton.setBounds(768,411,30,30); + UpButton.setBounds(804,375,30,30); + DownButton.setBounds(804,411,30,30); + AirplaneWithRadarPanel.add(CreateButton); + AirplaneWithRadarPanel.add(RightButton); + AirplaneWithRadarPanel.add(LeftButton); + AirplaneWithRadarPanel.add(UpButton); + AirplaneWithRadarPanel.add(DownButton); + AirplaneWithRadarFrame.add(AirplaneWithRadarPanel, BorderLayout.CENTER); + Random random = new Random(); + CreateButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DrawningEntityAirplaneWithRadar.Init(random.nextInt(100, 300), random.nextDouble(1000, 3000), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + Color.getHSBColor(random.nextInt(0, 301), random.nextInt(0, 301), random.nextInt(0, 301)), + random.nextInt(1, 4)*10, + AirplaneWithRadarPanel.getWidth(), AirplaneWithRadarPanel.getHeight(), random.nextBoolean(), random.nextBoolean(), AirplaneWithRadarPanel); + + DrawningEntityAirplaneWithRadar.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10); + DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar(); + } + }); + RightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null) + return; + DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Right); + DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar(); + } + }); + LeftButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null) + return; + DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Left); + DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar(); + } + }); + UpButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null) + return; + DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Up); + DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar(); + } + }); + DownButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningEntityAirplaneWithRadar.EntityAirplaneWithRadar() == null) + return; + DrawningEntityAirplaneWithRadar.MoveTransport(DirectionType.Down); + DrawningEntityAirplaneWithRadar.DrawAirplaneWithRadar(); + } + }); + AirplaneWithRadarFrame.setVisible(true); + } +} \ No newline at end of file diff --git a/src/NumberType.java b/src/NumberType.java new file mode 100644 index 0000000..21a034e --- /dev/null +++ b/src/NumberType.java @@ -0,0 +1,5 @@ +public enum NumberType { + Ten, + Twenty, + Thirty +} -- 2.25.1 From 435ed2cad93a8149034f3421f85c898d9b5d3fbe Mon Sep 17 00:00:00 2001 From: antoc0der <1@DESKTOP-K1L8ND3> Date: Mon, 16 Oct 2023 20:36:19 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= =?UTF-8?q?=20=D0=BA=D0=B0=D1=80=D1=82=D0=B8=D0=BD=D0=BA=D0=B8=20=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D0=BB=D0=B0=D0=B9=D0=B4=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Main.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/Main.java b/src/Main.java index 96feeb9..0818708 100644 --- a/src/Main.java +++ b/src/Main.java @@ -14,10 +14,14 @@ public class Main { AirplaneWithRadarFrame.setResizable(false); DrawningAirplaneWithRadar DrawningEntityAirplaneWithRadar = new DrawningAirplaneWithRadar(); AirplaneWithRadarPanel.setLayout(null); - JButton RightButton = new JButton("→"); - JButton LeftButton = new JButton("←"); - JButton UpButton = new JButton("↑"); - JButton DownButton = new JButton("↓"); + BufferedImage RightIcon = ImageIO.read(new File("RightButton.png")); + BufferedImage LeftIcon = ImageIO.read(new File("LeftButton.png")); + BufferedImage UpIcon = ImageIO.read(new File("UpButton.png")); + BufferedImage DownIcon = ImageIO.read(new File("DownButton.png")); + JButton RightButton = new JButton(new ImageIcon(RightIcon)); + JButton LeftButton = new JButton(new ImageIcon(LeftIcon)); + JButton UpButton = new JButton(new ImageIcon(UpIcon)); + JButton DownButton = new JButton(new ImageIcon(DownIcon)); JButton CreateButton = new JButton(); CreateButton.setText("Создать"); CreateButton.setBounds(12, 401, 90, 40); -- 2.25.1