From efa7dd085be31b754b0a432b6a01ba045a2d28b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sun, 15 Oct 2023 20:53:26 +0400 Subject: [PATCH 1/2] export --- Resources/DownArrow.png | Bin 0 -> 414 bytes Resources/LeftArrow.png | Bin 0 -> 439 bytes Resources/RightArrow.png | Bin 0 -> 377 bytes Resources/UpArrow.png | Bin 0 -> 439 bytes src/DirectionType.java | 6 ++ src/DoorNumberType.java | 5 + src/DrawningDoor.java | 57 +++++++++++ src/DrawningDoubleDeckerBus.java | 157 +++++++++++++++++++++++++++++++ src/EntityDoubleDeckerBus.java | 62 ++++++++++++ src/FormDoubleDeckerBus.java | 94 ++++++++++++++++++ 10 files changed, 381 insertions(+) create mode 100644 Resources/DownArrow.png create mode 100644 Resources/LeftArrow.png create mode 100644 Resources/RightArrow.png create mode 100644 Resources/UpArrow.png create mode 100644 src/DirectionType.java create mode 100644 src/DoorNumberType.java create mode 100644 src/DrawningDoor.java create mode 100644 src/DrawningDoubleDeckerBus.java create mode 100644 src/EntityDoubleDeckerBus.java create mode 100644 src/FormDoubleDeckerBus.java diff --git a/Resources/DownArrow.png b/Resources/DownArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..ec660ba61e837835fcfb1671de5089607b05dd79 GIT binary patch literal 414 zcmV;P0b%}$P)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0W(QNK~zXf?UK7r zgg_XD8ELJ&ls<;Fu{Ysjr@o8CSJAa05r_rlZp&-fx@uxi#`81(k_^IJ*3$Ws&DlfP z^DSYbKp+s<7s08KB*|GE#}9qqzcfwr%9p*!vg}F-agCk(vMk^D^2jeSesF=dO4 z`J8mebXya*ZTpRQS53zzH%Y;kw@2mw_u_X7B624+$D)*NDi9FBG>BBV;`1eH755|##iRU5M>i_@%07*qo IM6N<$g2qv@d;kCd literal 0 HcmV?d00001 diff --git a/Resources/LeftArrow.png b/Resources/LeftArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..51d95ac732f711fdd5775fbd735e1e5536587a10 GIT binary patch literal 439 zcmV;o0Z9IdP)Px#1ZP1_K>z@;j|==^1poj532;bRa{vGi!vFvd!vV){sAK>D0Zd6mK~zXf?Up-E z!$1&*y|_o>)p85^P`XHAQwGk0#Z?k$EMZ%40j>fSB99Z;<{x$<5yd;+T|1E?U4P()F5nx^RqM=KOpUsN2&->6qQ2BSRBKe!j^BPQt_^;}0yUDwxTS$=Ue z;

gXq6IS7(Q_;;v+UniK?nzxfO90lk^9*RoXPo3%2=QA{{? zVk;h0O4x`8ml9p#ok$7sa7j||>?fPcsC(|c@Est%5uY)(dV$jV&VpX6 z7FUc5U!p8^+G2tmn{n?<*H$+c@+tRDxC{{EdPx$Gf6~2R7gwJ*1b-{Fc1guJI`!X zX1)S|TKfSaI8D>rs;a(P$bp&9wYUgQl4Moa^-IU;)VK&HqDKJu=!sQ@i{J(%qE`TT zj)jY10lsJE3u(=R;Fx$Y91B;$9)AOXr=FUR#;%5ic+=;dYZ5$$BjR12=bv5jX~IM_ zROg*y&URkRn$|_=3|557-%pY3k`x}qGH%uyD-MAwNpyn#{(CE z(a|_*a#?F{j4|J>m#9&3)P6MH1HjhfKg@hB{r9S)K5m@ldfQhk?epLPqJ`S~W`q9$ XF6oya+nxKm00000NkvXXu0mjfE99rn literal 0 HcmV?d00001 diff --git a/Resources/UpArrow.png b/Resources/UpArrow.png new file mode 100644 index 0000000000000000000000000000000000000000..d3c45c0714596ccfa1b79dd648f8367ede0d68bd GIT binary patch literal 439 zcmeAS@N?(olHy`uVBq!ia0vp^av;pX1|+Qw)-3{3jKx9jP7LeL$-D$|SkfJR9T^xl z_H+M9WCij$3p^r=85sBugD~Uq{1quc4a%M_jv*f2Zzt`~I&2`&zP5s2#U%T_QpMR< zia+=(GB1U5K8c-_chsyzzjm6RuJ7`7$9}G~o9Qxft#IVm#-DdNf7>0j{7_-jWpjS| zr-j!f9bYz`*z|_o^8Kv`A=92R-7M4P58tR4YH>RDh;vZu?Y6NpdACm#kXldwZMyl~-pBKX<>Hr(Gy>Jh)}gTu#l}Wxv?EYaBOMuR9Vb z@;7j$u~ul$$*(uft&i;syK&umtI)JBLWj?V&-m#0)&AK2T^e1-mt}t2@mJffVsWzi zB$dea#2Lxw)~$Q(Z}qLhW?nUClkpvs2WbkzLb6Mw<(8T_Zzs4kQv(E1) bJF08y^84R(D*RxrS=)5ewcZaHt_Xzy!C1V; literal 0 HcmV?d00001 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/DoorNumberType.java b/src/DoorNumberType.java new file mode 100644 index 0000000..d503c6d --- /dev/null +++ b/src/DoorNumberType.java @@ -0,0 +1,5 @@ +public enum DoorNumberType { + Three, + Four, + Five +} diff --git a/src/DrawningDoor.java b/src/DrawningDoor.java new file mode 100644 index 0000000..e7331d2 --- /dev/null +++ b/src/DrawningDoor.java @@ -0,0 +1,57 @@ +import javax.swing.*; +import java.awt.*; + +public class DrawningDoor { + JPanel DoubleDeckerBusPanel; + private DoorNumberType DoorNumberType; + private Color blackColor; + private int Width; + private int Height; + public int CurX; + public int CurY; + + public boolean Init(int width, int height, int curX, int curY, JPanel doubleDeckerBusPanel) { + Width = width; + Height = height; + CurX = curX; + CurY = curY; + blackColor = Color.BLACK; + DoubleDeckerBusPanel = doubleDeckerBusPanel; + return true; + } + + public void ChangeDoorsNumber(int x) { + if (x <= 3) { + DoorNumberType = DoorNumberType.Three; + } + if (x == 4) { + DoorNumberType = DoorNumberType.Four; + } + if (x >= 5) { + DoorNumberType = DoorNumberType.Five; + } + } + + public DoorNumberType DoorNumberType() { + return DoorNumberType; + } + + public void DrawDoors() { + Graphics2D g2d = (Graphics2D) DoubleDeckerBusPanel.getGraphics(); + g2d.setColor(blackColor); + g2d.fillRect(CurX + 15, CurY + 40, 10, 20); + g2d.fillRect(CurX + 30, CurY + 40, 10, 20); + + if (DoorNumberType == DoorNumberType.Three || DoorNumberType == DoorNumberType.Four || DoorNumberType == DoorNumberType.Five) { + g2d.fillRect(CurX + 45, CurY + 40, 10, 20); + } + + if (DoorNumberType == DoorNumberType.Four || DoorNumberType == DoorNumberType.Five) { + g2d.fillRect(CurX + 60, CurY + 40, 10, 20); + } + + if (DoorNumberType == DoorNumberType.Five) { + g2d.fillRect(CurX + 75, CurY + 40, 10, 20); + } + } +} diff --git a/src/DrawningDoubleDeckerBus.java b/src/DrawningDoubleDeckerBus.java new file mode 100644 index 0000000..0f0c3ab --- /dev/null +++ b/src/DrawningDoubleDeckerBus.java @@ -0,0 +1,157 @@ +import javax.swing.*; +import java.awt.*; +import java.util.Random; + +public class DrawningDoubleDeckerBus { + JPanel DoubleDeckerBusPanel; + private EntityDoubleDeckerBus EntityDoubleDeckerBus; + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX = 0; + private int _startPosY = 0; + private final int _busWidth = 110; + private final int _busHeight = 70; + private DrawningDoor DrawningDoor; + + public EntityDoubleDeckerBus EntityDoubleDeckerBus() { + return EntityDoubleDeckerBus; + } + + public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, int doorNumber, + int width, int height, boolean secondFloor, boolean ladder, boolean lineBetweenFloor, JPanel doubleDeckerBusPanel) { + if (width <= _busWidth || height <= _busHeight) { + return false; + } + + _startPosX = 0; + _startPosY = 0; + doubleDeckerBusPanel.setSize(width, height); + DoubleDeckerBusPanel = doubleDeckerBusPanel; + doubleDeckerBusPanel.paint(DoubleDeckerBusPanel.getGraphics()); + _pictureWidth = width; + _pictureHeight = height; + EntityDoubleDeckerBus = new EntityDoubleDeckerBus(); + EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, doorNumber, secondFloor, ladder, lineBetweenFloor); + DrawningDoor = new DrawningDoor(); + DrawningDoor.Init(_busWidth, _busHeight, _startPosX, _startPosY, doubleDeckerBusPanel); + Random random = new Random(); + DrawningDoor.ChangeDoorsNumber(random.nextInt(2,6)); + return true; + } + + public void SetPosition(int x, int y){ + if (EntityDoubleDeckerBus == null) { + return; + } + + _startPosX = x; + _startPosY = y; + + if (x + _busWidth <= _pictureWidth || y + _busHeight <= _pictureHeight) { + _startPosX = 0; + _startPosY = 0; + } + } + + public void MoveTransport(DirectionType direction){ + if (EntityDoubleDeckerBus == null) + return; + DoubleDeckerBusPanel.paint(DoubleDeckerBusPanel.getGraphics()); + switch (direction) + { + case Left: + if (_startPosX - EntityDoubleDeckerBus.Step() >= 0) + _startPosX -= (int)EntityDoubleDeckerBus.Step(); + else + _startPosX = 0; + break; + case Up: + if (_startPosY - EntityDoubleDeckerBus.Step() >= 0) + _startPosY -= (int)EntityDoubleDeckerBus.Step(); + else + _startPosY = 0; + break; + case Right: + if (_startPosX + EntityDoubleDeckerBus.Step() + _busWidth < _pictureWidth) + _startPosX += (int)EntityDoubleDeckerBus.Step(); + else + _startPosX = _pictureWidth - _busWidth; + break; + case Down: + if (_startPosY + EntityDoubleDeckerBus.Step() + _busHeight < _pictureHeight) + _startPosY += (int)EntityDoubleDeckerBus.Step(); + else + _startPosY = _pictureHeight - _busHeight; + break; + } + DrawningDoor.CurX = _startPosX; + DrawningDoor.CurY = _startPosY; + } + + public void DrawTransport() { + Graphics2D g2d = (Graphics2D) DoubleDeckerBusPanel.getGraphics(); + + if (EntityDoubleDeckerBus == null) { + return; + } + + // Границы первого этажа автобуса + g2d.setColor(EntityDoubleDeckerBus.BodyColor()); + g2d.fillRect(_startPosX, _startPosY + 30, 100, 30); + + // Колеса + g2d.setColor(Color.black); + g2d.fillOval(_startPosX + 7, _startPosY + 55, 10, 10); + g2d.fillOval(_startPosX + 77, _startPosY + 55, 10, 10); + + // Окна + g2d.setColor(Color.blue); + g2d.fillOval(_startPosX + 10, _startPosY + 35, 10, 15); + g2d.fillOval(_startPosX + 50, _startPosY + 35, 10, 15); + g2d.fillOval(_startPosX + 70, _startPosY + 35, 10, 15); + g2d.fillOval(_startPosX + 90, _startPosY + 35, 10, 15); + + // двери + DrawningDoor.DrawDoors(); + + // второй этаж + if (EntityDoubleDeckerBus.SecondFloor()) + { + g2d.setColor(EntityDoubleDeckerBus.BodyColor()); + // Границы второго этажа автобуса + g2d.setColor(EntityDoubleDeckerBus.AdditionalColor()); + g2d.fillRect(_startPosX, _startPosY, 100, 30); + + // Окна второго этажа + g2d.setColor(Color.BLUE); + g2d.fillOval(_startPosX + 12, _startPosY + 5, 10, 15); + g2d.fillOval(_startPosX + 30, _startPosY + 5, 10, 15); + g2d.fillOval(_startPosX + 50, _startPosY + 5, 10, 15); + g2d.fillOval(_startPosX + 70, _startPosY + 5, 10, 15); + g2d.fillOval(_startPosX + 90, _startPosY + 5, 10, 15); + } + + // лестница + if (EntityDoubleDeckerBus.Ladder()) + { + if (EntityDoubleDeckerBus.SecondFloor()) { + //Вертикальные прямые + g2d.setColor(Color.black); + g2d.drawLine(_startPosX, _startPosY + 55, _startPosX, _startPosY + 25); + g2d.drawLine(_startPosX + 10, _startPosY + 55, _startPosX + 10, _startPosY + 25); + + //Горизонтальные прямые + g2d.drawLine(_startPosX, _startPosY + 35, _startPosX + 10, _startPosY + 35); + g2d.drawLine(_startPosX, _startPosY + 45, _startPosX + 10, _startPosY + 45); + g2d.drawLine(_startPosX, _startPosY + 55, _startPosX + 10, _startPosY + 55); + } + } + + // полоса между этажами + if (EntityDoubleDeckerBus.LineBetweenFloor()) + { + g2d.setColor(Color.black); + g2d.fillRect(_startPosX, _startPosY + 30, 100, 3); + } + } +} diff --git a/src/EntityDoubleDeckerBus.java b/src/EntityDoubleDeckerBus.java new file mode 100644 index 0000000..9339cab --- /dev/null +++ b/src/EntityDoubleDeckerBus.java @@ -0,0 +1,62 @@ +import java.awt.*; + +public class EntityDoubleDeckerBus { + private int Speed; + private int DoorNumber; + private double Weight; + private Color BodyColor; + private Color AdditionalColor; + private boolean SecondFloor; + private boolean Ladder; + private boolean LineBetweenFloor; + private double Step; + + public int Speed() { + return Speed; + } + + public int DoorNumber() { + return DoorNumber; + } + + public double Weight() { + return Weight; + } + + public Color BodyColor() { + return BodyColor; + } + + public Color AdditionalColor() { + return AdditionalColor; + } + + public boolean SecondFloor() { + return SecondFloor; + } + + public boolean Ladder() { + return Ladder; + } + + public boolean LineBetweenFloor() { + return LineBetweenFloor; + } + + public double Step() { + return Step; + } + + public void Init(int speed, double weight, Color bodyColor, Color additionalColor, + int doorNumber, boolean secondFloor ,boolean ladder, boolean lineBetweenFloor) { + Speed = speed; + Weight = weight; + Step = (double) Speed * 100 / Weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + SecondFloor = secondFloor; + DoorNumber = doorNumber; + Ladder = ladder; + LineBetweenFloor = lineBetweenFloor; + } +} diff --git a/src/FormDoubleDeckerBus.java b/src/FormDoubleDeckerBus.java new file mode 100644 index 0000000..34bec7a --- /dev/null +++ b/src/FormDoubleDeckerBus.java @@ -0,0 +1,94 @@ +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.awt.image.BufferedImage; +import java.io.File; +import java.io.IOException; +import java.util.Random; +import javax.imageio.ImageIO; +import javax.swing.*; + +public class FormDoubleDeckerBus { + public static void main(String[] args) throws IOException { + JFrame DoubleDeckerBusFrame = new JFrame(); + JPanel DoubleDeckerBusPanel = new JPanel(); + DoubleDeckerBusFrame.setLayout(new BorderLayout()); + DoubleDeckerBusFrame.setSize(900, 500); + DoubleDeckerBusFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); + DoubleDeckerBusFrame.setLayout(new BorderLayout(1,1)); + DrawningDoubleDeckerBus DrawningDoubleDeckerBus = new DrawningDoubleDeckerBus(); + DoubleDeckerBusPanel.setLayout(null); + BufferedImage RightIcon = ImageIO.read(new File("Resources/RightArrow.png")); + BufferedImage LeftIcon = ImageIO.read(new File("Resources/LeftArrow.png")); + BufferedImage UpIcon = ImageIO.read(new File("Resources/UpArrow.png")); + BufferedImage DownIcon = ImageIO.read(new File("Resources/DownArrow.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); + RightButton.setBounds(840,411,30,30); + LeftButton.setBounds(768,411,30,30); + UpButton.setBounds(804,375,30,30); + DownButton.setBounds(804,411,30,30); + DoubleDeckerBusPanel.add(CreateButton); + DoubleDeckerBusPanel.add(RightButton); + DoubleDeckerBusPanel.add(LeftButton); + DoubleDeckerBusPanel.add(UpButton); + DoubleDeckerBusPanel.add(DownButton); + DoubleDeckerBusFrame.add(DoubleDeckerBusPanel, BorderLayout.CENTER); + Random random = new Random(); + CreateButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + DrawningDoubleDeckerBus.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)), + random.nextInt(2, 5), DoubleDeckerBusPanel.getWidth(), DoubleDeckerBusPanel.getHeight(), + random.nextBoolean(), random.nextBoolean(), random.nextBoolean(), DoubleDeckerBusPanel); + DrawningDoubleDeckerBus.DrawTransport(); + } + }); + RightButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null) + return; + DrawningDoubleDeckerBus.MoveTransport(DirectionType.Right); + DrawningDoubleDeckerBus.DrawTransport(); + } + }); + LeftButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null) + return; + DrawningDoubleDeckerBus.MoveTransport(DirectionType.Left); + DrawningDoubleDeckerBus.DrawTransport(); + } + }); + UpButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null) + return; + DrawningDoubleDeckerBus.MoveTransport(DirectionType.Up); + DrawningDoubleDeckerBus.DrawTransport(); + } + }); + DownButton.addActionListener(new ActionListener() { + @Override + public void actionPerformed(ActionEvent e) { + if(DrawningDoubleDeckerBus.EntityDoubleDeckerBus() == null) + return; + DrawningDoubleDeckerBus.MoveTransport(DirectionType.Down); + DrawningDoubleDeckerBus.DrawTransport(); + } + }); + + DoubleDeckerBusFrame.setVisible(true); + } +} -- 2.25.1 From 46c7fd0dfcdfbb353ffb291e5a1677af73613168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Tue, 17 Oct 2023 20:56:36 +0400 Subject: [PATCH 2/2] fix --- src/DrawningDoor.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/DrawningDoor.java b/src/DrawningDoor.java index e7331d2..51a82eb 100644 --- a/src/DrawningDoor.java +++ b/src/DrawningDoor.java @@ -42,15 +42,15 @@ public class DrawningDoor { g2d.fillRect(CurX + 15, CurY + 40, 10, 20); g2d.fillRect(CurX + 30, CurY + 40, 10, 20); - if (DoorNumberType == DoorNumberType.Three || DoorNumberType == DoorNumberType.Four || DoorNumberType == DoorNumberType.Five) { + if (DoorNumberType() == DoorNumberType.Three || DoorNumberType() == DoorNumberType.Four || DoorNumberType() == DoorNumberType.Five) { g2d.fillRect(CurX + 45, CurY + 40, 10, 20); } - if (DoorNumberType == DoorNumberType.Four || DoorNumberType == DoorNumberType.Five) { + if (DoorNumberType() == DoorNumberType.Four || DoorNumberType() == DoorNumberType.Five) { g2d.fillRect(CurX + 60, CurY + 40, 10, 20); } - if (DoorNumberType == DoorNumberType.Five) { + if (DoorNumberType() == DoorNumberType.Five) { g2d.fillRect(CurX + 75, CurY + 40, 10, 20); } } -- 2.25.1