From cc59420fbf9c1b138af611baada974b1e421e772 Mon Sep 17 00:00:00 2001 From: BoiledMilk123 Date: Wed, 22 May 2024 20:32:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B7=D0=B0=D0=BA=D0=BE=D0=BD=D1=87=D0=B8?= =?UTF-8?q?=D0=BB=20labwork02?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Drawnings/DrawingElectricLocomotive.java | 20 +++++--- .../src/Drawnings/DrawingLocomotive.java | 15 ++++-- .../src/Drawnings/DrawingOrnamentWheels.java | 39 +++++++++++++-- .../DrawningSecondOrnamentWheels.java | 48 +++++++++++++++++++ .../Entities/EntityElectricLocomotive.java | 20 +------- .../src/FormElectricLocomotive.java | 1 + 6 files changed, 110 insertions(+), 33 deletions(-) create mode 100644 ProjectElectricLocomotive/src/Drawnings/DrawningSecondOrnamentWheels.java diff --git a/ProjectElectricLocomotive/src/Drawnings/DrawingElectricLocomotive.java b/ProjectElectricLocomotive/src/Drawnings/DrawingElectricLocomotive.java index a4c2b03..0b44a2c 100644 --- a/ProjectElectricLocomotive/src/Drawnings/DrawingElectricLocomotive.java +++ b/ProjectElectricLocomotive/src/Drawnings/DrawingElectricLocomotive.java @@ -20,22 +20,28 @@ public class DrawingElectricLocomotive extends DrawingLocomotive switch (varOrnament) { case 0: - _ornament = new DrawingWheels(); - break; - case 1: _ornament = new DrawingOrnamentWheels(); break; + case 1: + _ornament = new DrawningSecondOrnamentWheels(); + break; default: - _ornament = new DrawingOrnamentSecondWheels(); + _ornament = new DrawingWheels(); break; } - _ornament.SetCountWheels(rnd.nextInt(1,3)); + _ornament.SetCountWheels(rnd.nextInt(1,5)); } @Override public void DrawTransport(Graphics g) { if (!(_entityLocomotive instanceof EntityElectricLocomotive _entityElectricLocomotive) || _startPosX == null) return; + super.DrawTransport(g); + + g.setColor(Color.white); + g.fillRect(_startPosX + 48, _startPosY + 38, 20, 10); + g.fillRect(_startPosX + 9, _startPosY + 38, 20, 10); + // Создание перьев и кистей для прорисовки электровоза Color blackColor = Color.BLACK; Color deepSkyBlueColor = new Color(0, 191, 255); @@ -67,14 +73,14 @@ public class DrawingElectricLocomotive extends DrawingLocomotive // Прорисовка "хранилища батарей" электровоза + g.fillRect(_startPosX.intValue() + 36, _startPosY + 37, 8, 4); g.setColor(yellowColor); g.drawLine(pointLightning1.x, pointLightning1.y, pointLightning2.x, pointLightning2.y); g.drawLine(pointLightning2.x, pointLightning2.y, pointLightning3.x, pointLightning3.y); g.drawLine(pointLightning3.x, pointLightning3.y, pointLightning4.x, pointLightning4.y); - - g.setColor(blackColor); } + _ornament.DrawWheels(g, _startPosX, _startPosY); } diff --git a/ProjectElectricLocomotive/src/Drawnings/DrawingLocomotive.java b/ProjectElectricLocomotive/src/Drawnings/DrawingLocomotive.java index 7828927..46262b8 100644 --- a/ProjectElectricLocomotive/src/Drawnings/DrawingLocomotive.java +++ b/ProjectElectricLocomotive/src/Drawnings/DrawingLocomotive.java @@ -6,6 +6,7 @@ import ProjectElectricLocomotive.src.DirectionType; import ProjectElectricLocomotive.src.Entities.EntityLocomotive; import java.awt.*; +import java.util.Random; public class DrawingLocomotive { public EntityLocomotive _entityLocomotive; @@ -13,7 +14,6 @@ public class DrawingLocomotive { { return _entityLocomotive; } - public DrawingWheels _wheels; protected Integer _startPosX = null; public Integer getPosX() { return _startPosX; @@ -147,6 +147,16 @@ public class DrawingLocomotive { // Совокупность точек полигона уголка второй "юбки" Point[] secondTrianglePoints = { point6, point7, point8 }; + g.setColor(blackColor); + g.fillOval(_startPosX + 58, _startPosY + 37, 10, 10); + g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8); + g.fillOval(_startPosX + 48, _startPosY + 37, 10, 10); + g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8); + g.fillOval(_startPosX + 19, _startPosY + 37, 10, 10); + g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8); + g.fillOval(_startPosX + 9, _startPosY + 37, 10, 10); + g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8); + // Прорисовка уголков "юбок" g.setColor(_entityLocomotive.GetBodyColor()); g.fillPolygon(new Polygon(new int[]{ point3.x, point4.x, point5.x }, new int[]{ point3.y, point4.y, point5.y }, 3)); @@ -163,8 +173,5 @@ public class DrawingLocomotive { g.setColor(deepSkyBlueColor); g.drawRect(_startPosX + 12, _startPosY + 9, 8, 8); g.drawRect(_startPosX+ 63, _startPosY + 9, 8, 8); - - _wheels.DrawWheels(g, _startPosX, _startPosY); - } } diff --git a/ProjectElectricLocomotive/src/Drawnings/DrawingOrnamentWheels.java b/ProjectElectricLocomotive/src/Drawnings/DrawingOrnamentWheels.java index 3cbb572..a7377a7 100644 --- a/ProjectElectricLocomotive/src/Drawnings/DrawingOrnamentWheels.java +++ b/ProjectElectricLocomotive/src/Drawnings/DrawingOrnamentWheels.java @@ -1,17 +1,48 @@ package ProjectElectricLocomotive.src.Drawnings; +import ProjectElectricLocomotive.src.CountWheels; + import java.awt.*; public class DrawingOrnamentWheels implements IDrawingOrnament { - + private CountWheels _wheels; @Override - public void SetCountWheels(int count) { - + public void SetCountWheels(int count) + { + for(CountWheels temp : CountWheels.values()) + { + if(temp.GetCountWheels() >= count) + { + _wheels = temp; + return; + } + } } @Override - public void DrawWheels(Graphics g, int _startPosX, int _startPosY) { + public void DrawWheels(Graphics g,int _startPosX, int _startPosY) + { + g.setColor(Color.BLACK); + switch (_wheels.GetCountWheels()) + { + case 4: + g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 62,_startPosY + 38, _startPosX + 62, _startPosY + 38 + 6 ); + case 3: + g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 52,_startPosY + 38, _startPosX + 52, _startPosY + 38 + 6 ); + + case 2: + g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 23,_startPosY + 38, _startPosX + 23, _startPosY + 38 + 6 ); + + case 1: + g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 13,_startPosY + 38, _startPosX + 13, _startPosY + 38 + 6 ); + + break; + } } } diff --git a/ProjectElectricLocomotive/src/Drawnings/DrawningSecondOrnamentWheels.java b/ProjectElectricLocomotive/src/Drawnings/DrawningSecondOrnamentWheels.java new file mode 100644 index 0000000..cc5ded6 --- /dev/null +++ b/ProjectElectricLocomotive/src/Drawnings/DrawningSecondOrnamentWheels.java @@ -0,0 +1,48 @@ +package ProjectElectricLocomotive.src.Drawnings; + +import ProjectElectricLocomotive.src.CountWheels; + +import java.awt.*; + +public class DrawningSecondOrnamentWheels implements IDrawingOrnament +{ + private CountWheels _wheels; + @Override + public void SetCountWheels(int count) + { + for(CountWheels temp : CountWheels.values()) + { + if(temp.GetCountWheels() >= count) + { + _wheels = temp; + return; + } + } + } + + @Override + public void DrawWheels(Graphics g,int _startPosX, int _startPosY) + { + g.setColor(Color.BLACK); + switch (_wheels.GetCountWheels()) + { + case 4: + g.drawOval(_startPosX + 58, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 58,_startPosY + 38, _startPosX + 58 + 6, _startPosY + 37 + 6 ); + g.drawLine(_startPosX + 64,_startPosY + 38, _startPosX + 58, _startPosY + 37 + 6 ); + case 3: + g.drawOval(_startPosX + 48, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 48,_startPosY + 38, _startPosX + 48 + 6, _startPosY + 37 + 6 ); + g.drawLine(_startPosX + 54,_startPosY + 38, _startPosX + 48, _startPosY + 37 + 6 ); + case 2: + g.drawOval(_startPosX + 19, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 19,_startPosY + 38, _startPosX + 19 + 6, _startPosY + 37 + 6 ); + g.drawLine(_startPosX + 25,_startPosY + 38, _startPosX + 19, _startPosY + 37 + 6 ); + case 1: + g.drawOval(_startPosX + 9, _startPosY + 37, 8, 8); + g.drawLine(_startPosX + 9,_startPosY + 38, _startPosX + 9 + 6, _startPosY + 37 + 6 ); + g.drawLine(_startPosX + 15,_startPosY + 38, _startPosX + 9, _startPosY + 37 + 6 ); + break; + } + } +} diff --git a/ProjectElectricLocomotive/src/Entities/EntityElectricLocomotive.java b/ProjectElectricLocomotive/src/Entities/EntityElectricLocomotive.java index a1fc2f1..e269d27 100644 --- a/ProjectElectricLocomotive/src/Entities/EntityElectricLocomotive.java +++ b/ProjectElectricLocomotive/src/Entities/EntityElectricLocomotive.java @@ -4,13 +4,7 @@ import java.awt.*; import java.util.Random; public class EntityElectricLocomotive extends EntityLocomotive { - private int Speed; - private float Weight; - private Color BodyColor; - public Color GetBodyColor() - { - return BodyColor; - } + private Color AdditionalColor; public Color GetAdditionalColor() { @@ -33,15 +27,5 @@ public class EntityElectricLocomotive extends EntityLocomotive { ElectricHorns = electricHorns; BatteryPlacement = batteryPlacement; } - public void Init(int speed, float weight, Color bodyColor, Color additionalcolor, boolean electricHorns, boolean batteryPlacement) - { - Random rnd = new Random(); - Speed = speed; - Weight = weight; - BodyColor = bodyColor; - AdditionalColor = additionalcolor; - ElectricHorns = electricHorns; - BatteryPlacement = batteryPlacement; - Step = Speed * 100 / Weight; - } + } diff --git a/ProjectElectricLocomotive/src/FormElectricLocomotive.java b/ProjectElectricLocomotive/src/FormElectricLocomotive.java index 580a643..5326b18 100644 --- a/ProjectElectricLocomotive/src/FormElectricLocomotive.java +++ b/ProjectElectricLocomotive/src/FormElectricLocomotive.java @@ -45,6 +45,7 @@ public class FormElectricLocomotive extends JFrame{ setSize(900,500); Width = getWidth(); Height = getHeight(); + setBackground(Color.WHITE); ShowWindow(); RefreshWindow(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);