From c23479c9714458d717e7598f79c40e2333af139e Mon Sep 17 00:00:00 2001 From: spacyboy Date: Thu, 14 Dec 2023 13:43:13 +0400 Subject: [PATCH 1/2] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=A3=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=9B=D0=B0=D0=B1=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/.gitignore | 8 ++ .idea/PIbd-22_Smirnov_A_A_RoadTrain_HARD.iml | 11 ++ .idea/misc.xml | 6 + .idea/modules.xml | 8 ++ .idea/vcs.xml | 6 + Direction.java | 6 + DrawingRoadTrain.java | 90 +++++++++++++ EntityRoadTrain.java | 26 ++++ FormRoadTrain.java | 128 +++++++++++++++++++ Main.java | 5 +- NumWindow.java | 6 + WindowDrawing.java | 39 ++++++ images/down.png | Bin 0 -> 3385 bytes images/left.png | Bin 0 -> 3176 bytes images/right.png | Bin 0 -> 2601 bytes images/up.png | Bin 0 -> 3331 bytes 16 files changed, 335 insertions(+), 4 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/PIbd-22_Smirnov_A_A_RoadTrain_HARD.iml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 Direction.java create mode 100644 DrawingRoadTrain.java create mode 100644 EntityRoadTrain.java create mode 100644 FormRoadTrain.java create mode 100644 NumWindow.java create mode 100644 WindowDrawing.java create mode 100644 images/down.png create mode 100644 images/left.png create mode 100644 images/right.png create mode 100644 images/up.png diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/PIbd-22_Smirnov_A_A_RoadTrain_HARD.iml b/.idea/PIbd-22_Smirnov_A_A_RoadTrain_HARD.iml new file mode 100644 index 0000000..b107a2d --- /dev/null +++ b/.idea/PIbd-22_Smirnov_A_A_RoadTrain_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..3d9c2f8 --- /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..daf7e72 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ 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/Direction.java b/Direction.java new file mode 100644 index 0000000..5b70d63 --- /dev/null +++ b/Direction.java @@ -0,0 +1,6 @@ +public enum Direction { + Up, + Down, + Left, + Right; +} diff --git a/DrawingRoadTrain.java b/DrawingRoadTrain.java new file mode 100644 index 0000000..1c9287e --- /dev/null +++ b/DrawingRoadTrain.java @@ -0,0 +1,90 @@ +import java.awt.*; + +public class DrawingRoadTrain { + private WindowDrawing windowDrawing; + public EntityRoadTrain EntityRoadTrain; + private int _pictureWidth; + private int _pictureHeight; + private int _startPosX; + private int _startPosY; + private int _roadTrainWidth = 200; + private int _roadTrainHeight = 100; + public boolean Init(int speed, double weight, Color bodyColor, Color + additionalColor, boolean wheel, boolean door, boolean light, int numWindow, int width, int height) + { + _pictureWidth = width; + _pictureHeight = height; + if (_pictureHeight < _roadTrainHeight || _pictureWidth < _roadTrainWidth) + return false; + EntityRoadTrain = new EntityRoadTrain(); + EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor,wheel, door, light, numWindow); + + windowDrawing = new WindowDrawing(); + windowDrawing.setNumWindow(numWindow); + return true; + } + public void SetPosition(int x, int y) + { + _startPosX = Math.min(x, _pictureWidth-_roadTrainWidth); + _startPosY = Math.min(y, _pictureHeight- _roadTrainHeight); + } + public void MoveTransport(Direction direction) + { + if (EntityRoadTrain == null){ + return; + } + switch (direction) + { + case Left: + if (_startPosX - EntityRoadTrain.Step > 0) + { + _startPosX -= (int) EntityRoadTrain.Step; + } + break; + case Up: + if (_startPosY - EntityRoadTrain.Step > 0) + { + _startPosY -= (int) EntityRoadTrain.Step; + } + break; + case Right: + if (_startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth) + { + _startPosX += (int) EntityRoadTrain.Step; + } + break; + case Down: + if (_startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight) + { + _startPosY += (int) EntityRoadTrain.Step; + } + break; + } + } + public void DrawTransport(Graphics2D g) { + if (EntityRoadTrain == null) { + return; + } + // машина + g.drawRect(_startPosX, _startPosY + 50, 160, 20); // кузов + g.drawOval(_startPosX + 5, _startPosY + 70, 30, 30); // колесо + g.drawOval(_startPosX + 40, _startPosY + 70, 30, 30); // колесо + g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); // колесо + g.drawRect(_startPosX + 120, _startPosY + 10, 40, 40); // кабина + g.drawRect(_startPosX + 10, _startPosY, 90, 50); // бак с водой + g.drawRect(_startPosX + 130, _startPosY + 20, 30, 20); // окно + g.drawLine(_startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); // держатель для щетки + g.drawRect(_startPosX + 170, _startPosY + 80, 40, 10); // щетка + // обвесы + g.setColor(EntityRoadTrain.AdditionalColor); + if (EntityRoadTrain.Wheel) { + g.fillOval(_startPosX + 75, _startPosY + 70, 30, 30); // колесо + } + if (EntityRoadTrain.Door) { + g.fillRect(_startPosX + 40, _startPosY + 20, 20, 30); // дверь + } + if (EntityRoadTrain.Light) { + g.fillRect(_startPosX + 135, _startPosY, 10, 10); // мигалка + } + } +} diff --git a/EntityRoadTrain.java b/EntityRoadTrain.java new file mode 100644 index 0000000..061cf6e --- /dev/null +++ b/EntityRoadTrain.java @@ -0,0 +1,26 @@ +import java.awt.*; + +public class EntityRoadTrain { + public int Speed; + public double Weight; + public Color BodyColor; + public Color AdditionalColor; + public boolean Wheel; + public boolean Door; + public boolean Light; + public double Step; + public int numWindow; + public void Init(int speed, double weight, Color bodyColor, Color + additionalColor, boolean wheel, boolean door, boolean light, int _numWindow) + { + numWindow = _numWindow; + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + AdditionalColor = additionalColor; + Wheel = wheel; + Door = door; + Light = light; + Step = (double)Speed * 100 / Weight; + } +} diff --git a/FormRoadTrain.java b/FormRoadTrain.java new file mode 100644 index 0000000..34c9e3f --- /dev/null +++ b/FormRoadTrain.java @@ -0,0 +1,128 @@ +import javax.swing.*; +import java.awt.*; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.util.Random; + +public class FormRoadTrain { + private DrawingRoadTrain _drawingRoadTrain; + Canvas canv; + public void Draw(){ + canv.repaint(); + } + public FormRoadTrain(){ + JFrame w=new JFrame ("RoadTrain"); + JButton buttonCreate = new JButton("Create"); + buttonCreate.setBorderPainted(false); + buttonCreate.setContentAreaFilled(false); + buttonCreate.setFont(new Font("Arial", Font.PLAIN, 20)); + JButton up = new JButton(); + up.setBorderPainted(false); + up.setContentAreaFilled(false); + up.setName("up"); + Image img_up = new ImageIcon("images/up.png").getImage(); + Image newImg_up = img_up.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH); + up.setIcon(new ImageIcon(newImg_up)); + + JButton down = new JButton(); + down.setBorderPainted(false); + down.setContentAreaFilled(false); + down.setName("down"); + Image img_down = new ImageIcon("images/down.png").getImage(); + Image newImg_down = img_down.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH); + down.setIcon(new ImageIcon(newImg_down)); + + JButton left = new JButton(); + left.setBorderPainted(false); + left.setContentAreaFilled(false); + left.setName("left"); + Image img_left = new ImageIcon("images/left.png").getImage(); + Image newImg_left = img_left.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH); + left.setIcon(new ImageIcon(newImg_left)); + + JButton right = new JButton(); + right.setBorderPainted(false); + right.setContentAreaFilled(false); + right.setName("right"); + Image img_right = new ImageIcon("images/right.png").getImage(); + Image newImg_right = img_right.getScaledInstance(20, 20, java.awt.Image.SCALE_SMOOTH); + right.setIcon(new ImageIcon(newImg_right)); + + buttonCreate.addActionListener( + new ActionListener() { + public void actionPerformed(ActionEvent e){ + Random random = new Random(); + _drawingRoadTrain = new DrawingRoadTrain(); + _drawingRoadTrain.Init(random.nextInt(100, 300), random.nextInt(1000, 3000), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), + random.nextInt(0, 2) == 1, random.nextInt(0, 2) == 1,random.nextInt(0, 2) == 1, + random.nextInt(1, 4)*10, 1000, 560); + _drawingRoadTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); + canv._drawingRoadTrain = _drawingRoadTrain; + Draw(); + } + } + ); + ActionListener actioListener = new ActionListener() { + public void actionPerformed(ActionEvent e){ + if (_drawingRoadTrain == null) + { + return; + } + switch(((JButton)(e.getSource())).getName()){ + case "up": + _drawingRoadTrain.MoveTransport(Direction.Up); + break; + case "down": + _drawingRoadTrain.MoveTransport(Direction.Down); + break; + case "left": + _drawingRoadTrain.MoveTransport(Direction.Left); + break; + case "right": + _drawingRoadTrain.MoveTransport(Direction.Right); + break; + } + Draw(); + } + }; + up.addActionListener(actioListener); + down.addActionListener(actioListener); + left.addActionListener(actioListener); + right.addActionListener(actioListener); + + w.setSize (1000, 600); + w.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); + w.setLayout(null); + canv = new Canvas(); + canv.setBounds(0, 0, 1000, 600); + buttonCreate.setBounds(30, 500, 100, 30); + up.setBounds(880, 450, 20, 20); + down.setBounds(880, 510, 20, 20); + left.setBounds(850, 480, 20, 20); + right.setBounds(910, 480, 20, 20); + w.add(canv); + w.add(buttonCreate); + w.add(up); + w.add(down); + w.add(left); + w.add(right); + w.setVisible (true); + } +} + +class Canvas extends JComponent{ + public DrawingRoadTrain _drawingRoadTrain; + public Canvas(){ + } + public void paintComponent (Graphics g){ + if (_drawingRoadTrain == null){ + return; + } + super.paintComponents (g) ; + Graphics2D g2d = (Graphics2D)g; + _drawingRoadTrain.DrawTransport(g2d); + super.repaint(); + } +} diff --git a/Main.java b/Main.java index 55d0847..ffafb77 100644 --- a/Main.java +++ b/Main.java @@ -1,7 +1,4 @@ public class Main { - public static void main(String[] args) { - System.out.println("test"); - } - + public static void main(String[] args) { new FormRoadTrain(); } } diff --git a/NumWindow.java b/NumWindow.java new file mode 100644 index 0000000..358af2f --- /dev/null +++ b/NumWindow.java @@ -0,0 +1,6 @@ +public enum NumWindow +{ + tenWindows, + twentyWindows, + thirtyWindows +} diff --git a/WindowDrawing.java b/WindowDrawing.java new file mode 100644 index 0000000..4ce9f95 --- /dev/null +++ b/WindowDrawing.java @@ -0,0 +1,39 @@ +import java.awt.*; + +public class WindowDrawing{ + private NumWindow numWindow; + public NumWindow getSomeProperty() { + return numWindow; + } + public void setNumWindow(int kWindow){ + switch(kWindow){ + case 10: + numWindow = NumWindow.tenWindows; + break; + case 20: + numWindow = NumWindow.twentyWindows; + break; + case 30: + numWindow = NumWindow.thirtyWindows; + break; + default: + numWindow = NumWindow.tenWindows; + System.out.println("Ошибка! Количество " + kWindow); + break; + } + } + void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){ + g.setColor(color); + int windowSpacing = 4; + int windowCount = switch (numWindow) { + case tenWindows -> 10; + case twentyWindows -> 20; + case thirtyWindows -> 30; + }; + for (int j = 0; j < windowCount / 10; j++) { + for (int i = 0; i < 10; i++) { + g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + j * windowSpacing, 4, 4); + } + } + } +} diff --git a/images/down.png b/images/down.png new file mode 100644 index 0000000000000000000000000000000000000000..0f9a8dd7cc7e02f150fbdb1604f07d099f338b60 GIT binary patch literal 3385 zcmeH}`#V&77rraE>}9Y*AliaIndosxQULgh$GE>lRkq^PKwhSMPI>E@E&bW%w- zghVdoHW-ZDDxFF$k=vM2Zei3r8E3}c`(6DB=jZpG=h@Gmz1C+w&suBNcbAu+~G>0An+EU%vXV1{Ud{ya8n7{=D?gke}0d6?*KefLtO2*Q3~Gbj>5y7 zK-)dG6w0$ibk>gsxf$o(OgoY!A@%>)|Jnr3R;4>b&)K1_PHq$`qB3Xhy!k(=q6^g2 z7cE|*p-I=$)>)>vTz`du;hJBJjMp+u%*=n?u+ehU7OSn+Hnw)Z+wXMP?c}m=zq^O0 z*TF-+en$fWj|ByvJjLR0&tkmu7h+=Lu3Sw_x_RsNoxAr_)3P4tKFP~3d|FgoTE;K0 zs1#IH*9dFto0?z$^`_;0Yg_w=&aRI=BC%xf)90b#k-k{H;*V z;=~P35C$dx#NO!{LZPSy{NX@g5o;A4cS6znY~)*^EUO~nI`uAhxfh}nDxn9l45lxl!G`o zdUl*0p0~cRM}Xzet|Mk|I@V=tNIoyGQHs*vqS3{}`QrM;XQCrcx_-fD-iXyy*&iMR zZc84-gFgu$_gH^B7S=j<@?X}yjSWutU)I}`zE9T}^=@de6QX-RcAa~ds(b3lE_d8y z&d08az>CTV!MD+=xIGiUt?z9ke|`6 zuNT;D=JabX9uu$W=0!rlGF|%+OEdDbr4tl%o?i5D|68EHZWE_gw=R<}Ry zY2y>F;0g~$ZqYRipyEfyM195OhPqh+)TmEmqA35<{+o8aMfNA>W85~$H};JOv^--U za&oLOfzVWIE9P|^85fdQ8YNfR_s-GsR{E2Z{THN;%HiiPih22;$3;<+0W^u&@iLy_ zyVg_54H9az&u)5EhunJILuLm_t)!TE1B!aAW|5NIoz0vkM7?_bkqq?qE^XYz*EmbY=N-S%CPE%LyTZN}=E3^*&@O%F^QxM^u&A4F zc8QR0M#ZqRt|uU$(F^(QuVD47iH+|Dw*?+w?s^3oO9)bqtQCe@DLvY041_ zX;hLKMdfg*4gw!x-vu=q@n(@~8Q{ zj*=b`vj05?L%R<2KyYn7$UmR46p4^qDcd31YXzo&AvkRtH>MKwr+;n+>Gz=y5#qFg zPte&_f5Wr?n`c6ruEjfoK6SnVto1`+RZ9thABVF)F0#VRh75;m`;dTwtKa>C$gt;D zT4|(9$Uz?Q;*JQBS@-wS)5!RtQVQOAw+)erUPi)m(@+rww_Kk{8xdA)X4sHNyM1`X z>(Uwu&TpLt=)h~V1=E}`wIMr7Dk->o#}Fd(Ih25Q;bCE(rkZlrX{tir){V%dPx5Ia zA|FS<BNN+Fvp(orz+Gt>k!%U41zXd?KA=Tyh-pgV8MqjM;AWh-`1pENvup|0sZ^ zMOtZCgdrGpo52`<1B@X?U>tUnAhLHkRRFpl2asO`#%Mz@8r>+S;Mp$Ch%9xNHWc+Q zL+IXUj}U?u-yzst0>KD3Xne_TJ}*ILR>wqJgc@x?adtnW;EvZZsv_A?i4cp`IPWpE zLhD)z;dLT{swhko!!)l4K$DkspqjNo9GFqd0L&<>0%qjq4Y^T2rxr z*5(BrrYaI!YGGJe3K*8_XDFd07h0R639bE-3$j0%&{{?g810#27*=j249oK=T+44w*HunP$#Skj@N-F*v6H^Q;Jldj9AS(D4VD90s7-C?YGg zsRQuR5dfFO188v_z{>^z?u!R-?ayFzUo!@va|3``#{hKw6Ts4kKR~-5;Ie7}EulMi zRy!hN)yBa$aPc{Si&dcJ^>blfF$)0PGYa6cHrN@<>`nlk;Yf%wZvvB1fSGD|PttL( zKN{WAzb=`#Rr}NcS?Jk|D zR*&sp6DCo()tQu>RCe$Sm4(j(r4^I1sdek0;`e>RMy%7L_@ugz@LS0gbv>u4z_Fi9 qcQlI}En}Xy&| literal 0 HcmV?d00001 diff --git a/images/left.png b/images/left.png new file mode 100644 index 0000000000000000000000000000000000000000..8b6ae1e00e4c11f06d6cd53d17952d1d6cc098ac GIT binary patch literal 3176 zcmeH}Z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k1pSUYN0k>(N3zu{^aeXyR|x13p#*32l(6g^WZ oZ=Ua~Fx-D`)4%vWx_PZ!M2)@gYdwi5EUcfmG`BS?H}Q=9FXkI%B>(^b literal 0 HcmV?d00001 -- 2.25.1 From c1a4102d9d5666714de38ab373702ebf1fac2784 Mon Sep 17 00:00:00 2001 From: spacyboy Date: Tue, 19 Dec 2023 22:51:32 +0400 Subject: [PATCH 2/2] =?UTF-8?q?=D0=93=D0=BE=D1=82=D0=BE=D0=B2=D0=B0=D1=8F?= =?UTF-8?q?=20=D0=A3=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=B0?= =?UTF-8?q?=D1=8F=20=D0=9B=D0=B0=D0=B1=D0=B0=201?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .idea/misc.xml | 2 +- DrawingRoadTrain.java | 19 ++++++++----------- EntityRoadTrain.java | 6 +++--- FormRoadTrain.java | 2 +- NumWheel.java | 6 ++++++ NumWindow.java | 6 ------ WheelDrawing.java | 42 ++++++++++++++++++++++++++++++++++++++++++ WindowDrawing.java | 39 --------------------------------------- 8 files changed, 61 insertions(+), 61 deletions(-) create mode 100644 NumWheel.java delete mode 100644 NumWindow.java create mode 100644 WheelDrawing.java delete mode 100644 WindowDrawing.java diff --git a/.idea/misc.xml b/.idea/misc.xml index 3d9c2f8..12f22af 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,6 +1,6 @@ - + \ No newline at end of file diff --git a/DrawingRoadTrain.java b/DrawingRoadTrain.java index 1c9287e..7b8830e 100644 --- a/DrawingRoadTrain.java +++ b/DrawingRoadTrain.java @@ -1,7 +1,8 @@ + import java.awt.*; public class DrawingRoadTrain { - private WindowDrawing windowDrawing; + private WheelDrawing wheelDrawing; public EntityRoadTrain EntityRoadTrain; private int _pictureWidth; private int _pictureHeight; @@ -10,17 +11,17 @@ public class DrawingRoadTrain { private int _roadTrainWidth = 200; private int _roadTrainHeight = 100; public boolean Init(int speed, double weight, Color bodyColor, Color - additionalColor, boolean wheel, boolean door, boolean light, int numWindow, int width, int height) + additionalColor, boolean wheel, boolean door, boolean light, int numWheel, int width, int height) { _pictureWidth = width; _pictureHeight = height; if (_pictureHeight < _roadTrainHeight || _pictureWidth < _roadTrainWidth) return false; EntityRoadTrain = new EntityRoadTrain(); - EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor,wheel, door, light, numWindow); + EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor,wheel, door, light, numWheel); - windowDrawing = new WindowDrawing(); - windowDrawing.setNumWindow(numWindow); + wheelDrawing = new WheelDrawing(); + wheelDrawing.setNumWheel(numWheel); return true; } public void SetPosition(int x, int y) @@ -67,9 +68,6 @@ public class DrawingRoadTrain { } // машина g.drawRect(_startPosX, _startPosY + 50, 160, 20); // кузов - g.drawOval(_startPosX + 5, _startPosY + 70, 30, 30); // колесо - g.drawOval(_startPosX + 40, _startPosY + 70, 30, 30); // колесо - g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); // колесо g.drawRect(_startPosX + 120, _startPosY + 10, 40, 40); // кабина g.drawRect(_startPosX + 10, _startPosY, 90, 50); // бак с водой g.drawRect(_startPosX + 130, _startPosY + 20, 30, 20); // окно @@ -77,9 +75,8 @@ public class DrawingRoadTrain { g.drawRect(_startPosX + 170, _startPosY + 80, 40, 10); // щетка // обвесы g.setColor(EntityRoadTrain.AdditionalColor); - if (EntityRoadTrain.Wheel) { - g.fillOval(_startPosX + 75, _startPosY + 70, 30, 30); // колесо - } + wheelDrawing.Draw(_startPosX, _startPosY, EntityRoadTrain.AdditionalColor, g); + if (EntityRoadTrain.Door) { g.fillRect(_startPosX + 40, _startPosY + 20, 20, 30); // дверь } diff --git a/EntityRoadTrain.java b/EntityRoadTrain.java index 061cf6e..e397359 100644 --- a/EntityRoadTrain.java +++ b/EntityRoadTrain.java @@ -9,11 +9,11 @@ public class EntityRoadTrain { public boolean Door; public boolean Light; public double Step; - public int numWindow; + public int numWheel; public void Init(int speed, double weight, Color bodyColor, Color - additionalColor, boolean wheel, boolean door, boolean light, int _numWindow) + additionalColor, boolean wheel, boolean door, boolean light, int numwheel) { - numWindow = _numWindow; + numWheel = numwheel; Speed = speed; Weight = weight; BodyColor = bodyColor; diff --git a/FormRoadTrain.java b/FormRoadTrain.java index 34c9e3f..1672cc2 100644 --- a/FormRoadTrain.java +++ b/FormRoadTrain.java @@ -57,7 +57,7 @@ public class FormRoadTrain { new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), new Color(random.nextInt(0, 256), random.nextInt(0, 256), random.nextInt(0, 256)), random.nextInt(0, 2) == 1, random.nextInt(0, 2) == 1,random.nextInt(0, 2) == 1, - random.nextInt(1, 4)*10, 1000, 560); + random.nextInt(1, 4), 1000, 560); _drawingRoadTrain.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100)); canv._drawingRoadTrain = _drawingRoadTrain; Draw(); diff --git a/NumWheel.java b/NumWheel.java new file mode 100644 index 0000000..c1c8900 --- /dev/null +++ b/NumWheel.java @@ -0,0 +1,6 @@ +public enum NumWheel +{ + oneWheel, + twoWheel, + threeWheel +} diff --git a/NumWindow.java b/NumWindow.java deleted file mode 100644 index 358af2f..0000000 --- a/NumWindow.java +++ /dev/null @@ -1,6 +0,0 @@ -public enum NumWindow -{ - tenWindows, - twentyWindows, - thirtyWindows -} diff --git a/WheelDrawing.java b/WheelDrawing.java new file mode 100644 index 0000000..85389dd --- /dev/null +++ b/WheelDrawing.java @@ -0,0 +1,42 @@ +import java.awt.*; + +public class WheelDrawing { + private NumWheel numWheel; + public NumWheel getSomeProperty() { + return numWheel; + } + public void setNumWheel(int kWheel){ + switch(kWheel){ + case 1: + numWheel = NumWheel.oneWheel; + break; + case 2: + numWheel = NumWheel.twoWheel; + break; + case 3: + numWheel = NumWheel.threeWheel; + break; + default: + numWheel = NumWheel.oneWheel; + System.out.println("Ошибка! Количество " + kWheel); + break; + } + } + void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){ + g.setColor(color); + switch (numWheel) { + case oneWheel -> { + g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); + } + case twoWheel -> { + g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); + g.drawOval(_startPosX + 50, _startPosY + 70, 30, 30); + } + case threeWheel -> { + g.drawOval(_startPosX + 120, _startPosY + 70, 30, 30); + g.drawOval(_startPosX + 55, _startPosY + 70, 30, 30); + g.drawOval(_startPosX + 15, _startPosY + 70, 30, 30); + } + }; + } +} diff --git a/WindowDrawing.java b/WindowDrawing.java deleted file mode 100644 index 4ce9f95..0000000 --- a/WindowDrawing.java +++ /dev/null @@ -1,39 +0,0 @@ -import java.awt.*; - -public class WindowDrawing{ - private NumWindow numWindow; - public NumWindow getSomeProperty() { - return numWindow; - } - public void setNumWindow(int kWindow){ - switch(kWindow){ - case 10: - numWindow = NumWindow.tenWindows; - break; - case 20: - numWindow = NumWindow.twentyWindows; - break; - case 30: - numWindow = NumWindow.thirtyWindows; - break; - default: - numWindow = NumWindow.tenWindows; - System.out.println("Ошибка! Количество " + kWindow); - break; - } - } - void Draw(int _startPosX, int _startPosY, Color color, Graphics2D g){ - g.setColor(color); - int windowSpacing = 4; - int windowCount = switch (numWindow) { - case tenWindows -> 10; - case twentyWindows -> 20; - case thirtyWindows -> 30; - }; - for (int j = 0; j < windowCount / 10; j++) { - for (int i = 0; i < 10; i++) { - g.fillOval(_startPosX + 35 + i * 8, _startPosY + 30 + j * windowSpacing, 4, 4); - } - } - } -} -- 2.25.1