From d9f60fed993749966dd14467b3ae51f3e50971ec Mon Sep 17 00:00:00 2001 From: tyxz0 Date: Sun, 3 Mar 2024 10:29:46 +0400 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B1=D0=B0=D0=B7=D0=B7=D0=BE=D0=B2=D1=8B=D0=B5=20=D0=B8=20?= =?UTF-8?q?=D0=B4=D0=BE=D1=87=D0=B5=D1=80=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB?= =?UTF-8?q?=D0=B0=D1=81=D1=81=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DoubleDeckerBus/DoubleDeckerBus.csproj | 4 - .../DoubleDeckerBus/Drawnings/DrawingBus.cs | 101 +++++---- .../Drawnings/DrawingDoubleDeckerBus.cs | 196 ++---------------- .../Entities/EntityDoubleDeckerBus.cs | 14 +- .../MovementStrategy/IMoveableObject..cs | 12 ++ 5 files changed, 86 insertions(+), 241 deletions(-) create mode 100644 DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject..cs diff --git a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj index b2208b1..244387d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj +++ b/DoubleDeckerBus/DoubleDeckerBus/DoubleDeckerBus.csproj @@ -23,8 +23,4 @@ - - - - \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs b/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs index b20aaeb..9ce608e 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingBus.cs @@ -9,29 +9,38 @@ namespace DoubleDeckerBus.Drawnings; public class DrawingBus { - public EntityBus? EntityBus { get; private set; } + public EntityBus? EntityBus { get; protected set; } private int? _pictureWidth; private int? _pictureHeight; - private int? _startPosX; + protected int? _startPosX; - private int? _startPosY; + protected int? _startPosY; - private readonly int _DrawingBusWidth = 120; + private readonly int _drawingBusWidth = 105; - private readonly int _DrawingBusHight = 60; + private readonly int _drawingBusHeight = 50; - public void Init(int speed, double weight, Color bodyColor) + private DrawingBus() { - EntityBus = new EntityBus(speed, weight, bodyColor); - EntityBus.Init(speed, weight, bodyColor); _pictureWidth = null; _pictureHeight = null; _startPosX = null; _startPosY = null; } + + public DrawingBus(int speed, int weight, Color bodyColor) : this() + { + EntityBus = new EntityBus(speed, weight, bodyColor); + } + + protected DrawingBus(int drawingBusWidth, int drawingBusHeight) : this() + { + _drawingBusWidth = drawingBusWidth; + _drawingBusHeight = drawingBusHeight; + } /// /// размер окна /// @@ -40,7 +49,7 @@ public class DrawingBus /// public bool SetPictureSize(int width, int hight) { - if (_DrawingBusWidth > width || _DrawingBusHight > hight) + if (_drawingBusWidth > width || _drawingBusHeight > hight) { return false; } @@ -49,14 +58,14 @@ public class DrawingBus _pictureWidth = width; _pictureHeight = hight; - if (_startPosX.HasValue && _startPosX.Value + _DrawingBusWidth > _pictureWidth) + if (_startPosX.HasValue && _startPosX.Value + _drawingBusWidth > _pictureWidth) { - _startPosX = _pictureWidth - _DrawingBusWidth; + _startPosX = _pictureWidth - _drawingBusWidth; } - if (_startPosY.HasValue && _startPosY + _DrawingBusHight > _pictureHeight) + if (_startPosY.HasValue && _startPosY + _drawingBusHeight > _pictureHeight) { - _startPosY = _pictureHeight - _DrawingBusHight; + _startPosY = _pictureHeight - _drawingBusHeight; } return true; @@ -83,18 +92,18 @@ public class DrawingBus y = -y; } - if (x + _DrawingBusWidth > _pictureWidth) + if (x + _drawingBusWidth > _pictureWidth) { - _startPosX = _pictureWidth - _DrawingBusWidth; + _startPosX = _pictureWidth - _drawingBusWidth; } else { _startPosX = x; } - if (y + _DrawingBusHight > _pictureHeight) + if (y + _drawingBusHeight > _pictureHeight) { - _startPosY = _pictureHeight - _DrawingBusHight; + _startPosY = _pictureHeight - _drawingBusHeight; } else { @@ -125,13 +134,13 @@ public class DrawingBus } return true; case DirectionType.Right: - if (_startPosX.Value + _DrawingBusWidth + EntityBus.Step < _pictureWidth) + if (_startPosX.Value + _drawingBusWidth + EntityBus.Step < _pictureWidth) { _startPosX += (int)EntityBus.Step; } return true; case DirectionType.Down: - if (_startPosY.Value + _DrawingBusHight + EntityBus.Step < _pictureHeight) + if (_startPosY.Value + _drawingBusHeight + EntityBus.Step < _pictureHeight) { _startPosY += (int)EntityBus.Step; } @@ -142,7 +151,7 @@ public class DrawingBus } } - public void DrawTrasnport(Graphics g) + public virtual void DrawTrasnport(Graphics g) { if (EntityBus == null || !_startPosX.HasValue || !_startPosY.HasValue) { @@ -155,49 +164,49 @@ public class DrawingBus //кузов 1го этажа - PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY + 20), - new PointF((float)_startPosX, (float)_startPosY + 45), - new PointF((float)_startPosX + 100, (float)_startPosY + 45), + PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY), + new PointF((float)_startPosX, (float)_startPosY + 25), new PointF((float)_startPosX + 100, (float)_startPosY + 25), - new PointF((float)_startPosX + 97, (float)_startPosY + 20) }; + new PointF((float)_startPosX + 100, (float)_startPosY + 5), + new PointF((float)_startPosX + 97, (float)_startPosY) }; g.FillPolygon(mainBrush, bus); g.DrawPolygon(pen, bus); //окна 1ый этаж - g.FillRectangle(blueBr, _startPosX.Value + 2, _startPosY.Value + 25, 12, 10); - g.FillRectangle(blueBr, _startPosX.Value + 16, _startPosY.Value + 25, 12, 10); - g.FillRectangle(blueBr, _startPosX.Value + 42, _startPosY.Value + 25, 6, 10); - g.FillRectangle(blueBr, _startPosX.Value + 50, _startPosY.Value + 25, 13, 10); - g.FillRectangle(blueBr, _startPosX.Value + 66, _startPosY.Value + 25, 14, 10); + g.FillRectangle(blueBr, _startPosX.Value + 2, _startPosY.Value + 5, 12, 10); + g.FillRectangle(blueBr, _startPosX.Value + 16, _startPosY.Value + 5, 12, 10); + g.FillRectangle(blueBr, _startPosX.Value + 42, _startPosY.Value + 5, 6, 10); + g.FillRectangle(blueBr, _startPosX.Value + 50, _startPosY.Value + 5, 13, 10); + g.FillRectangle(blueBr, _startPosX.Value + 66, _startPosY.Value + 5, 14, 10); - g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 25, 12, 10); - g.DrawRectangle(pen, _startPosX.Value + 16, _startPosY.Value + 25, 12, 10); - g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 25, 6, 10); - g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 25, 13, 10); - g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 25, 14, 10); + g.DrawRectangle(pen, _startPosX.Value + 2, _startPosY.Value + 5, 12, 10); + g.DrawRectangle(pen, _startPosX.Value + 16, _startPosY.Value + 5, 12, 10); + g.DrawRectangle(pen, _startPosX.Value + 42, _startPosY.Value + 5, 6, 10); + g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 5, 13, 10); + g.DrawRectangle(pen, _startPosX.Value + 66, _startPosY.Value + 5, 14, 10); //переднее окно первый этаж - PointF[] window2 = { new PointF((float)_startPosX + 85, (float)_startPosY + 25), - new PointF((float)_startPosX + 100, (float)_startPosY + 25), - new PointF((float)_startPosX + 100, (float)_startPosY + 40), - new PointF((float)_startPosX + 85, (float)_startPosY + 35) }; + PointF[] window2 = { new PointF((float)_startPosX + 85, (float)_startPosY + 5), + new PointF((float)_startPosX + 100, (float)_startPosY + 5), + new PointF((float)_startPosX + 100, (float)_startPosY + 20), + new PointF((float)_startPosX + 85, (float)_startPosY + 15) }; g.FillPolygon(blueBr, window2); g.DrawPolygon(pen, window2); //дверь Brush brownBr = new SolidBrush(Color.Brown); - g.FillRectangle(blueBr, _startPosX.Value + 30, _startPosY.Value + 25, 10, 15); - g.FillRectangle(brownBr, _startPosX.Value + 30, _startPosY.Value + 40, 10, 5); + g.FillRectangle(blueBr, _startPosX.Value + 30, _startPosY.Value + 5, 10, 15); + g.FillRectangle(brownBr, _startPosX.Value + 30, _startPosY.Value + 20, 10, 5); - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 25, 10, 15); - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 40, 10, 5); + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 5, 10, 15); + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 20, 10, 5); //колёса - g.FillEllipse(brownBr, _startPosX.Value + 6, _startPosY.Value + 37, 16, 16); - g.FillEllipse(brownBr, _startPosX.Value + 78, _startPosY.Value + 37, 16, 16); + g.FillEllipse(brownBr, _startPosX.Value + 6, _startPosY.Value + 17, 16, 16); + g.FillEllipse(brownBr, _startPosX.Value + 78, _startPosY.Value + 17, 16, 16); - g.DrawEllipse(pen, _startPosX.Value + 6, _startPosY.Value + 37, 16, 16); - g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 37, 16, 16); + g.DrawEllipse(pen, _startPosX.Value + 6, _startPosY.Value + 17, 16, 16); + g.DrawEllipse(pen, _startPosX.Value + 78, _startPosY.Value + 17, 16, 16); } } diff --git a/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingDoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingDoubleDeckerBus.cs index 533472a..f13bae5 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingDoubleDeckerBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/Drawnings/DrawingDoubleDeckerBus.cs @@ -4,165 +4,33 @@ namespace DoubleDeckerBus.Drawnings; /// /// /// -public class DrawingDoubleDeckerBus +public class DrawingDoubleDeckerBus : DrawingBus { - public EntityDoubleDeckerBus? EntityDoubleDeckerBus { get; private set; } - - private int? _pictureWidth; - - private int? _pictureHeight; - - private int? _startPosX; - - private int? _startPosY; - - private readonly int _DrawingBusWidth = 120; - - private readonly int _DrawingBusHight = 60; - - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) + public DrawingDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base (105,50) { - EntityDoubleDeckerBus = new EntityDoubleDeckerBus(); - EntityDoubleDeckerBus.Init(speed, weight, bodyColor, additionalColor, secondFloor, stripes); - _pictureWidth = null; - _pictureHeight = null; - _startPosX = null; - _startPosY = null; - } - /// - /// размер окна - /// - /// - /// - /// - public bool SetPictureSize(int width, int hight) - { - if (_DrawingBusWidth > width || _DrawingBusHight > hight) - { - return false; - } - - - _pictureWidth = width; - _pictureHeight = hight; - - if (_startPosX.HasValue && _startPosX.Value + _DrawingBusWidth > _pictureWidth) - { - _startPosX = _pictureWidth - _DrawingBusWidth; - } - - if (_startPosY.HasValue && _startPosY + _DrawingBusHight > _pictureHeight) - { - _startPosY = _pictureHeight - _DrawingBusHight; - } - - return true; - - } - /// - /// установить начальную позицию - /// - /// - /// - public void SetPosition(int x, int y) - { - if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - - if (x < 0) - { - x = -x; - } - if (y < 0) - { - y = -y; - } - - if (x + _DrawingBusWidth > _pictureWidth) - { - _startPosX = _pictureWidth - _DrawingBusWidth; - } - else - { - _startPosX = x; - } - - if (y + _DrawingBusHight > _pictureHeight) - { - _startPosY = _pictureHeight - _DrawingBusHight; - } - else - { - _startPosY = y; - } + EntityBus = new EntityDoubleDeckerBus(speed, weight, bodyColor, additionalColor, secondFloor, stripes); } - public bool MoveTransport(DirectionType direction) + public override void DrawTrasnport(Graphics g) { - if (EntityDoubleDeckerBus == null || !_startPosX.HasValue || !_startPosY.HasValue) - { - return false; - } - - switch (direction) - { - case DirectionType.Left: - if (_startPosX.Value - EntityDoubleDeckerBus.Step > 0) - { - _startPosX -= (int)EntityDoubleDeckerBus.Step; - } - return true; - - case DirectionType.Up: - if (_startPosY.Value - EntityDoubleDeckerBus.Step > 0) - { - _startPosY -= (int)EntityDoubleDeckerBus.Step; - } - return true; - case DirectionType.Right: - if (_startPosX.Value + _DrawingBusWidth + EntityDoubleDeckerBus.Step < _pictureWidth) - { - _startPosX += (int)EntityDoubleDeckerBus.Step; - } - return true; - case DirectionType.Down: - if (_startPosY.Value + _DrawingBusHight + EntityDoubleDeckerBus.Step < _pictureHeight) - { - _startPosY += (int)EntityDoubleDeckerBus.Step; - } - return true; - default: - return false; - - } - } - - public void DrawTrasnport(Graphics g) - { - if (EntityDoubleDeckerBus == null || !_startPosX.HasValue || !_startPosY.HasValue) + if (EntityBus == null || EntityBus is not EntityDoubleDeckerBus doubleDeckerBus || !_startPosX.HasValue || !_startPosY.HasValue ) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityDoubleDeckerBus.AdditionalColor); - Brush mainBrush = new SolidBrush(EntityDoubleDeckerBus.BodyColor); + Brush additionalBrush = new SolidBrush(doubleDeckerBus.AdditionalColor); + Brush mainBrush = new SolidBrush(doubleDeckerBus.BodyColor); Brush blueBr = new SolidBrush(Color.LightBlue); - - //кузов 1го этажа - PointF[] bus = { new PointF((float)_startPosX + 5, (float)_startPosY + 20), - new PointF((float)_startPosX + 5, (float)_startPosY + 45), - new PointF((float)_startPosX + 105, (float)_startPosY + 45), - new PointF((float)_startPosX + 105, (float)_startPosY + 25), - new PointF((float)_startPosX + 102, (float)_startPosY + 20) }; - g.FillPolygon(mainBrush, bus); - g.DrawPolygon(pen, bus); + _startPosX += 5; + _startPosY += 20; + base.DrawTrasnport(g); + _startPosX -= 5; + _startPosY -= 20; //полоски - if (EntityDoubleDeckerBus.Stripes) + if (doubleDeckerBus.Stripes) { g.FillRectangle(additionalBrush, _startPosX.Value + 5, _startPosY.Value + 39, 100, 3); PointF[] stripe = { new PointF((float)_startPosX + 5, (float)_startPosY + 22), new PointF((float)_startPosX + 5, (float)_startPosY + 25), new PointF((float)_startPosX + 104, (float)_startPosY + 25), new PointF((float)_startPosX + 103, (float)_startPosY + 22) }; @@ -170,44 +38,8 @@ public class DrawingDoubleDeckerBus } - //окна 1ый этаж - g.FillRectangle(blueBr, _startPosX.Value + 7, _startPosY.Value + 25, 12, 10); - g.FillRectangle(blueBr, _startPosX.Value + 21, _startPosY.Value + 25, 12, 10); - g.FillRectangle(blueBr, _startPosX.Value + 47, _startPosY.Value + 25, 6, 10); - g.FillRectangle(blueBr, _startPosX.Value + 55, _startPosY.Value + 25, 13, 10); - g.FillRectangle(blueBr, _startPosX.Value + 71, _startPosY.Value + 25, 14, 10); - - g.DrawRectangle(pen, _startPosX.Value + 7, _startPosY.Value + 25, 12, 10); - g.DrawRectangle(pen, _startPosX.Value + 21, _startPosY.Value + 25, 12, 10); - g.DrawRectangle(pen, _startPosX.Value + 47, _startPosY.Value + 25, 6, 10); - g.DrawRectangle(pen, _startPosX.Value + 55, _startPosY.Value + 25, 13, 10); - g.DrawRectangle(pen, _startPosX.Value + 71, _startPosY.Value + 25, 14, 10); - - //переднее окно первый этаж - PointF[] window2 = { new PointF((float)_startPosX + 90, (float)_startPosY + 25), - new PointF((float)_startPosX + 105, (float)_startPosY + 25), - new PointF((float)_startPosX + 105, (float)_startPosY + 40), - new PointF((float)_startPosX + 90, (float)_startPosY + 35) }; - g.FillPolygon(blueBr, window2); - g.DrawPolygon(pen, window2); - - //дверь - Brush brownBr = new SolidBrush(Color.Brown); - g.FillRectangle(blueBr, _startPosX.Value + 35, _startPosY.Value + 25, 10, 15); - g.FillRectangle(brownBr, _startPosX.Value + 35, _startPosY.Value + 40, 10, 5); - - g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 25, 10, 15); - g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 40, 10, 5); - - //колёса - g.FillEllipse(brownBr, _startPosX.Value + 11, _startPosY.Value + 37, 16, 16); - g.FillEllipse(brownBr, _startPosX.Value + 83, _startPosY.Value + 37, 16, 16); - - g.DrawEllipse(pen, _startPosX.Value + 11, _startPosY.Value + 37, 16, 16); - g.DrawEllipse(pen, _startPosX.Value + 83, _startPosY.Value + 37, 16, 16); - //второй этаж с всякими зафуфрючками - if (EntityDoubleDeckerBus.SecondFloor) + if (doubleDeckerBus.SecondFloor) { //верх кузова PointF[] bus_second_floor = { new PointF((float)_startPosX + 5, (float)_startPosY + 5), diff --git a/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs index ebdf755..310f73d 100644 --- a/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs +++ b/DoubleDeckerBus/DoubleDeckerBus/Entities/EntityDoubleDeckerBus.cs @@ -1,6 +1,6 @@ namespace DoubleDeckerBus.Entities; -public class EntityDoubleDeckerBus -{ +public class EntityDoubleDeckerBus : EntityBus +{ public Color AdditionalColor { get; private set; } /// @@ -13,22 +13,18 @@ public class EntityDoubleDeckerBus public bool Stripes { get; private set; } /// - /// + /// Конструктор наследуемого класса /// /// /// /// /// - /// - /// /// - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) + public EntityDoubleDeckerBus(int speed, double weight, Color bodyColor, Color additionalColor, bool secondFloor, bool stripes) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; SecondFloor = secondFloor; Stripes = stripes; + } } \ No newline at end of file diff --git a/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject..cs b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject..cs new file mode 100644 index 0000000..069bcbb --- /dev/null +++ b/DoubleDeckerBus/DoubleDeckerBus/MovementStrategy/IMoveableObject..cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace DoubleDeckerBus.MovementStrategy +{ + internal interface Interface1 + { + } +}