From bfcdcb08c644cefa9337fc74026ecd34075387ae Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 15:11:56 +0400 Subject: [PATCH 1/9] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D0=BE=20Lab2?= =?UTF-8?q?.=20=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=20=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8?= =?UTF-8?q?=20EntityAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/EntityAirPlane.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/EntityAirPlane.cs diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs new file mode 100644 index 0000000..643523a --- /dev/null +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class EntityAirPlane + { + } +} -- 2.25.1 From 610206aade49a091b4b071b3e5b330b440291774 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 15:45:04 +0400 Subject: [PATCH 2/9] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20DrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 192 ++++++++++++++++++++++++ 1 file changed, 192 insertions(+) create mode 100644 AirBomber/AirBomber/DrawningAirPlane.cs diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs new file mode 100644 index 0000000..29c5d16 --- /dev/null +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -0,0 +1,192 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class DrawningAirPlane + { + public EntityAirPlane? EntityAirPlane { get; protected set; } + private int _pictureWidth; + private int _pictureHeight; + protected int _startPosX; + protected int _startPosY; + protected readonly int _airPlaneWidth = 150; + protected readonly int _airPlaneHeight = 118; + public DrawningAirPlane(int speed, double weight, Color bodyColor, int + width, int height) + { + if (width < _airPlaneWidth || height < _airPlaneHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + } + protected DrawningAirPlane(int speed, double weight, Color bodyColor, int + width, int height, int airPlaneWidth, int airPlaneHeight) + { + if (width < _airPlaneWidth || height < _airPlaneHeight) + { + return; + } + _pictureWidth = width; + _pictureHeight = height; + _airPlaneWidth = airPlaneWidth; + _airPlaneHeight = airPlaneHeight; + EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + } + public void SetPosition(int x, int y) + { + if (x < 0 || x + _airPlaneWidth > _pictureWidth) + { + x = _pictureWidth - _airPlaneWidth; + } + if (y < 0 || y + _airPlaneHeight > _pictureHeight) + { + y = _pictureHeight - _airPlaneHeight; + } + _startPosX = x; + _startPosY = y; + } + public virtual void DrawPlane(Graphics g) + { + if (EntityAirPlane == null) + { + return; + } + Pen pen = new(Color.Black); + Brush bodyColor = new SolidBrush(EntityAirPlane.BodyColor); + Brush wingsColor = new SolidBrush(Color.DeepPink); + g.FillPolygon(bodyColor, new Point[] //nose + { + new Point(_startPosX + 19, _startPosY + 50), + new Point(_startPosX + 19, _startPosY + 69), + new Point(_startPosX + 1, _startPosY + 59), + } + ); + g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //body + g.FillPolygon(bodyColor, new Point[] //up left wing + { + new Point(_startPosX + 36, _startPosY + 49), + new Point(_startPosX + 36, _startPosY + 1), + new Point(_startPosX + 45, _startPosY + 1), + new Point(_startPosX + 55, _startPosY + 49), + } + ); + g.FillPolygon(bodyColor, new Point[] //down left wing + { + new Point(_startPosX + 36, _startPosY + 71), + new Point(_startPosX + 36, _startPosY + 116), + new Point(_startPosX + 45, _startPosY + 116), + new Point(_startPosX + 54, _startPosY + 71), + } + ); + g.FillPolygon(wingsColor, new Point[] //up right wing + { + new Point(_startPosX + 120, _startPosY + 49), + new Point(_startPosX + 120, _startPosY + 42), + new Point(_startPosX + 140, _startPosY + 7), + new Point(_startPosX + 140, _startPosY + 49), + } + ); + g.FillPolygon(wingsColor, new Point[] //down right wing + { + new Point(_startPosX + 120, _startPosY + 70), + new Point(_startPosX + 120, _startPosY + 77), + new Point(_startPosX + 140, _startPosY + 112), + new Point(_startPosX + 140, _startPosY + 70), + } + ); + + g.DrawPolygon(pen, new Point[] //nose + { + new Point(_startPosX + 20, _startPosY + 49), + new Point(_startPosX + 20, _startPosY + 70), + new Point(_startPosX, _startPosY + 59), + } + ); + g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //body + g.DrawPolygon(pen, new Point[] //up left wing + { + new Point(_startPosX + 35, _startPosY + 49), + new Point(_startPosX + 35, _startPosY), + new Point(_startPosX + 45, _startPosY), + new Point(_startPosX + 55, _startPosY + 49), + } + ); + g.DrawPolygon(pen, new Point[] //down left wing + { + new Point(_startPosX + 36, _startPosY + 71), + new Point(_startPosX + 36, _startPosY + 116), + new Point(_startPosX + 45, _startPosY + 116), + new Point(_startPosX + 54, _startPosY + 71), + } + ); + g.DrawPolygon(pen, new Point[] //up right wing + { + new Point(_startPosX + 120, _startPosY + 49), + new Point(_startPosX + 120, _startPosY + 42), + new Point(_startPosX + 140, _startPosY + 7), + new Point(_startPosX + 140, _startPosY + 49), + } + ); + g.DrawPolygon(pen, new Point[] //down right wing + { + new Point(_startPosX + 120, _startPosY + 70), + new Point(_startPosX + 120, _startPosY + 77), + new Point(_startPosX + 140, _startPosY + 112), + new Point(_startPosX + 140, _startPosY + 70), + } + ); + } + public int GetPosX => _startPosX; + public int GetPosY => _startPosY; + public int GetWidth => _airPlaneWidth; + public int GetHeight => _airPlaneHeight; + public bool CanMove(DirectionType direction) + { + if (EntityAirPlane == null) + { + return false; + } + return direction switch + { + //влево + DirectionType.Left => _startPosX - EntityAirPlane.Step > 0, + //вверх + DirectionType.Up => _startPosY - EntityAirPlane.Step > 0, + // вправо + DirectionType.Right => _startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight, + _ => false, + }; + } + public void MovePlane(DirectionType direction) + { + if (!CanMove(direction) || EntityAirPlane == null) + { + return; + } + switch (direction) + { + case DirectionType.Left: + _startPosX -= (int)EntityAirPlane.Step; + break; + case DirectionType.Up: + _startPosY -= (int)EntityAirPlane.Step; + break; + case DirectionType.Right: + _startPosX += (int)EntityAirPlane.Step; + break; + case DirectionType.Down: + _startPosY += (int)EntityAirPlane.Step; + break; + } + } + } +} -- 2.25.1 From 127a35dea675bd8ec54f3c52cfca0a99fa767e39 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 15:49:30 +0400 Subject: [PATCH 3/9] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81-?= =?UTF-8?q?=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D1=8C=20=C2=AB=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82=D0=BE=D0=B3?= =?UTF-8?q?=D0=BE=C2=BB=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/EntityAirBomber.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 3d1c052..30eac2f 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -6,21 +6,14 @@ using System.Threading.Tasks; namespace AirBomber { - public class EntityAirBomber + public class EntityAirBomber : EntityAirPlane { - public int Speed { get; private set; } - public double Weight { get; private set; } - public Color BodyColor { get; private set; } public Color AdditionalColor { get; private set; } public bool Bombs { get; private set; } public bool FuelTanks { get; private set; } public int Engines { get; private set; } - public double Step => (double)Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines) + public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines) : base(speed, weight, bodyColor) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Bombs = bombs; FuelTanks = fuelTanks; -- 2.25.1 From dd3c7079533ba40db2e28da064a7a3ea36ca1719 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 16:04:12 +0400 Subject: [PATCH 4/9] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20?= =?UTF-8?q?=D0=BF=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20?= =?UTF-8?q?=C2=AB=D0=BF=D1=80=D0=BE=D0=B4=D0=B2=D0=B8=D0=BD=D1=83=D1=82?= =?UTF-8?q?=D0=BE=D0=B3=D0=BE=C2=BB=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20+=20fix=20in=20EntityAirBomber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 195 +++-------------------- AirBomber/AirBomber/EntityAirBomber.cs | 4 +- 2 files changed, 22 insertions(+), 177 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 4358657..f92ad33 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -6,190 +6,37 @@ using System.Threading.Tasks; namespace AirBomber { - public class DrawningAirBomber + public class DrawningAirBomber : DrawningAirPlane { - public EntityAirBomber? EntityAirBomber { get; private set; } - private int _pictureWidth; - private int _pictureHeight; - private int _startPosX; - private int _startPosY; - private readonly int _bomberWidth = 160; - private readonly int _bomberHeight = 118; - private DrawningEngines drawningEngines; - - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines, int width, int height) + public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int width, int height) : + base(speed, weight, bodyColor, width, height, 160, 118) { - if (width < _bomberWidth || height < _bomberHeight) + if (EntityAirPlane != null) { - return false; - } - _pictureWidth = width; - _pictureHeight = height; - EntityAirBomber = new EntityAirBomber(); - EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, fuelTanks, engines); - - drawningEngines = new DrawningEngines(); - drawningEngines.SetAmount(engines); - - return true; - } - - public void SetPosition(int x, int y) - { - if (x < 0 || x + _bomberWidth > _pictureWidth) - { - x = _pictureWidth - _bomberWidth; - } - - if (y < 0 || y + _bomberWidth > _pictureHeight) - { - y = _pictureHeight - _bomberHeight; - } - _startPosX = x; - _startPosY = y; - } - public void MoveTransport(DirectionType direction) - { - if (EntityAirBomber == null) - { - return; - } - switch (direction) - { - case DirectionType.Left: - if (_startPosX - EntityAirBomber.Step > 0) - { - _startPosX -= (int)EntityAirBomber.Step; - } - break; - case DirectionType.Up: - if (_startPosY - EntityAirBomber.Step > 0) - { - _startPosY -= (int)EntityAirBomber.Step; - } - break; - case DirectionType.Right: - if (_startPosX + EntityAirBomber.Step + _bomberWidth < _pictureWidth) - { - _startPosX += (int)EntityAirBomber.Step; - } - break; - case DirectionType.Down: - if (_startPosY + EntityAirBomber.Step + _bomberHeight < _pictureHeight) - { - _startPosY += (int)EntityAirBomber.Step; - } - break; + EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); } } - public void DrawBomber(Graphics g) + public override void DrawPlane(Graphics g) { - if (EntityAirBomber == null) + if (EntityAirPlane is not EntityAirBomber airBomber) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor); - Brush bodyColor = new SolidBrush(EntityAirBomber.BodyColor); - Brush wingsColor = new SolidBrush(Color.DeepPink); - if (EntityAirBomber.Bombs) - { - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 30, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 30, 15, 15); - g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 70, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 70, 15, 15); - } - g.FillPolygon(additionalBrush, new Point[] //nose - { - new Point(_startPosX + 19, _startPosY + 50), - new Point(_startPosX + 19, _startPosY + 69), - new Point(_startPosX + 1, _startPosY + 59), - } - ); - g.FillRectangle(bodyColor, _startPosX + 20, _startPosY + 50, 120, 20); //body - g.FillPolygon(additionalBrush, new Point[] //up left wing - { - new Point(_startPosX + 36, _startPosY + 49), - new Point(_startPosX + 36, _startPosY + 1), - new Point(_startPosX + 45, _startPosY + 1), - new Point(_startPosX + 55, _startPosY + 49), - } - ); - g.FillPolygon(additionalBrush, new Point[] //down left wing - { - new Point(_startPosX + 36, _startPosY + 71), - new Point(_startPosX + 36, _startPosY + 116), - new Point(_startPosX + 45, _startPosY + 116), - new Point(_startPosX + 54, _startPosY + 71), - } - ); - g.FillPolygon(wingsColor, new Point[] //up right wing - { - new Point(_startPosX + 120, _startPosY + 49), - new Point(_startPosX + 120, _startPosY + 42), - new Point(_startPosX + 140, _startPosY + 7), - new Point(_startPosX + 140, _startPosY + 49), - } - ); - g.FillPolygon(wingsColor, new Point[] //down right wing - { - new Point(_startPosX + 120, _startPosY + 70), - new Point(_startPosX + 120, _startPosY + 77), - new Point(_startPosX + 140, _startPosY + 112), - new Point(_startPosX + 140, _startPosY + 70), - } - ); - - g.DrawPolygon(pen, new Point[] //nose - { - new Point(_startPosX + 20, _startPosY + 49), - new Point(_startPosX + 20, _startPosY + 70), - new Point(_startPosX, _startPosY + 59), - } - ); - g.DrawRectangle(pen, _startPosX + 19, _startPosY + 49, 121, 21); //body - g.DrawPolygon(pen, new Point[] //up left wing - { - new Point(_startPosX + 35, _startPosY + 49), - new Point(_startPosX + 35, _startPosY), - new Point(_startPosX + 45, _startPosY), - new Point(_startPosX + 55, _startPosY + 49), - } - ); - g.DrawPolygon(pen, new Point[] //down left wing - { - new Point(_startPosX + 36, _startPosY + 71), - new Point(_startPosX + 36, _startPosY + 116), - new Point(_startPosX + 45, _startPosY + 116), - new Point(_startPosX + 54, _startPosY + 71), - } - ); - g.DrawPolygon(pen, new Point[] //up right wing - { - new Point(_startPosX + 120, _startPosY + 49), - new Point(_startPosX + 120, _startPosY + 42), - new Point(_startPosX + 140, _startPosY + 7), - new Point(_startPosX + 140, _startPosY + 49), - } - ); - g.DrawPolygon(pen, new Point[] //down right wing - { - new Point(_startPosX + 120, _startPosY + 70), - new Point(_startPosX + 120, _startPosY + 77), - new Point(_startPosX + 140, _startPosY + 112), - new Point(_startPosX + 140, _startPosY + 70), - } - ); - if (EntityAirBomber.FuelTanks) - { - g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 34, 30, 15); - g.DrawRectangle(pen, _startPosX + 85, _startPosY + 34, 30, 15); - g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 70, 30, 15); - g.DrawRectangle(pen, _startPosX + 85, _startPosY + 70, 30, 15); - } - drawningEngines.DrawEngines(g, _startPosX, _startPosY); + Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); + base.DrawPlane(g); + // bombs + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); + g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); + g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); + // fueltanks + g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); + g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15); + g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15); + g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15); } } } diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 30eac2f..2b4b3fa 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -11,13 +11,11 @@ namespace AirBomber public Color AdditionalColor { get; private set; } public bool Bombs { get; private set; } public bool FuelTanks { get; private set; } - public int Engines { get; private set; } - public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int engines) : base(speed, weight, bodyColor) + public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Bombs = bombs; FuelTanks = fuelTanks; - Engines = engines; } } } -- 2.25.1 From 64b0091916f5f493f54c0fe4782c9d1e288455f7 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 16:39:03 +0400 Subject: [PATCH 5/9] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2,=20=D0=B4?= =?UTF-8?q?=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=BE=D0=B2=20(=D0=BA=D0=B0=D0=BA=20?= =?UTF-8?q?=D0=B2=D0=BE=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D0=B1?= =?UTF-8?q?=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractStrategy.cs | 70 +++++++++++++++++++ AirBomber/AirBomber/DrawningAirPlane.cs | 6 +- AirBomber/AirBomber/DrawningObjectAirPlane.cs | 31 ++++++++ AirBomber/AirBomber/EntityAirPlane.cs | 12 +++- AirBomber/AirBomber/IMoveableObject.cs | 16 +++++ AirBomber/AirBomber/ObjectParameters.cs | 29 ++++++++ AirBomber/AirBomber/Status.cs | 15 ++++ 7 files changed, 174 insertions(+), 5 deletions(-) create mode 100644 AirBomber/AirBomber/AbstractStrategy.cs create mode 100644 AirBomber/AirBomber/DrawningObjectAirPlane.cs create mode 100644 AirBomber/AirBomber/IMoveableObject.cs create mode 100644 AirBomber/AirBomber/ObjectParameters.cs create mode 100644 AirBomber/AirBomber/Status.cs diff --git a/AirBomber/AirBomber/AbstractStrategy.cs b/AirBomber/AirBomber/AbstractStrategy.cs new file mode 100644 index 0000000..6859bd6 --- /dev/null +++ b/AirBomber/AirBomber/AbstractStrategy.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public abstract class AbstractStrategy + { + private IMoveableObject? _moveableObject; + private Status _state = Status.NotInit; + protected int FieldWidth { get; private set; } + protected int FieldHeight { get; private set; } + public Status GetStatus() { return _state; } + public void SetData(IMoveableObject moveableObject, int width, int height) + { + if (moveableObject == null) + { + _state = Status.NotInit; + return; + } + _state = Status.InProgress; + _moveableObject = moveableObject; + FieldWidth = width; + FieldHeight = height; + } + public void MakeStep() + { + if (_state != Status.InProgress) + { + return; + } + if (IsTargetDestinaion()) + { + _state = Status.Finish; + return; + } + MoveToTarget(); + } + protected bool MoveLeft() => MoveTo(DirectionType.Left); + protected bool MoveRight() => MoveTo(DirectionType.Right); + protected bool MoveUp() => MoveTo(DirectionType.Up); + protected bool MoveDown() => MoveTo(DirectionType.Down); + protected ObjectParameters? GetObjectParameters => _moveableObject?.GetObjectPosition; + protected int? GetStep() + { + if (_state != Status.InProgress) + { + return null; + } + return _moveableObject?.GetStep; + } + protected abstract void MoveToTarget(); + protected abstract bool IsTargetDestinaion(); + private bool MoveTo(DirectionType directionType) + { + if (_state != Status.InProgress) + { + return false; + } + if (_moveableObject?.CheckCanMove(directionType) ?? false) + { + _moveableObject.MoveObject(directionType); + return true; + } + return false; + } + } +} diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 29c5d16..455d9f6 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -15,8 +15,7 @@ namespace AirBomber protected int _startPosY; protected readonly int _airPlaneWidth = 150; protected readonly int _airPlaneHeight = 118; - public DrawningAirPlane(int speed, double weight, Color bodyColor, int - width, int height) + public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height) { if (width < _airPlaneWidth || height < _airPlaneHeight) { @@ -26,8 +25,7 @@ namespace AirBomber _pictureHeight = height; EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); } - protected DrawningAirPlane(int speed, double weight, Color bodyColor, int - width, int height, int airPlaneWidth, int airPlaneHeight) + protected DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height, int airPlaneWidth, int airPlaneHeight) { if (width < _airPlaneWidth || height < _airPlaneHeight) { diff --git a/AirBomber/AirBomber/DrawningObjectAirPlane.cs b/AirBomber/AirBomber/DrawningObjectAirPlane.cs new file mode 100644 index 0000000..90aa636 --- /dev/null +++ b/AirBomber/AirBomber/DrawningObjectAirPlane.cs @@ -0,0 +1,31 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class DrawningObjectAirPlane : IMoveableObject + { + private readonly DrawningAirPlane? _drawningAirPlane = null; + public DrawningObjectAirPlane(DrawningAirPlane drawningAirPlane) + { + _drawningAirPlane = drawningAirPlane; + } + public ObjectParameters? GetObjectPosition + { + get + { + if (_drawningAirPlane == null || _drawningAirPlane.EntityAirPlane == null) + { + return null; + } + return new ObjectParameters(_drawningAirPlane.GetPosX, _drawningAirPlane.GetPosY, _drawningAirPlane.GetWidth, _drawningAirPlane.GetHeight); + } + } + public int GetStep => (int)(_drawningAirPlane?.EntityAirPlane?.Step ?? 0); + public bool CheckCanMove(DirectionType direction) => _drawningAirPlane?.CanMove(direction) ?? false; + public void MoveObject(DirectionType direction) => _drawningAirPlane?.MovePlane(direction); + } +} diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index 643523a..a4b993e 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -6,7 +6,17 @@ using System.Threading.Tasks; namespace AirBomber { - internal class EntityAirPlane + public class EntityAirPlane { + public int Speed { get; private set; } + public double Weight { get; private set; } + public Color BodyColor { get; private set; } + public double Step => (double)Speed * 100 / Weight; + public EntityAirPlane(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } } } diff --git a/AirBomber/AirBomber/IMoveableObject.cs b/AirBomber/AirBomber/IMoveableObject.cs new file mode 100644 index 0000000..10bbf1b --- /dev/null +++ b/AirBomber/AirBomber/IMoveableObject.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public interface IMoveableObject + { + ObjectParameters? GetObjectPosition { get; } + int GetStep { get; } + bool CheckCanMove(DirectionType direction); + void MoveObject(DirectionType direction); + } +} diff --git a/AirBomber/AirBomber/ObjectParameters.cs b/AirBomber/AirBomber/ObjectParameters.cs new file mode 100644 index 0000000..b710e36 --- /dev/null +++ b/AirBomber/AirBomber/ObjectParameters.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class ObjectParameters + { + private readonly int _x; + private readonly int _y; + private readonly int _width; + private readonly int _height; + public int LeftBorder => _x; + public int TopBorder => _y; + public int RightBorder => _x + _width; + public int DownBorder => _y + _height; + public int ObjectMiddleHorizontal => _x + _width / 2; + public int ObjectMiddleVertical => _y + _height / 2; + public ObjectParameters(int x, int y, int width, int height) + { + _x = x; + _y = y; + _width = width; + _height = height; + } + } +} diff --git a/AirBomber/AirBomber/Status.cs b/AirBomber/AirBomber/Status.cs new file mode 100644 index 0000000..3e0828d --- /dev/null +++ b/AirBomber/AirBomber/Status.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public enum Status + { + NotInit, + InProgress, + Finish + } +} -- 2.25.1 From 00d9cfc7d1d78357508ecebf72823e560a17bff8 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 17:03:12 +0400 Subject: [PATCH 6/9] =?UTF-8?q?=D0=9F=D0=BE=D0=BB=D0=BD=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D1=8C=D1=8E=20=D0=BF=D0=B5=D1=80=D0=B5=D0=BD=D0=B5=D1=81=D0=B5?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=B0=D1=8F=20?= =?UTF-8?q?=D0=BB=D0=B0=D0=B1=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.Designer.cs | 65 +++++++++++++--- AirBomber/AirBomber/FormAirBomber.cs | 77 +++++++++++++++---- AirBomber/AirBomber/MoveToBorder.cs | 26 +++++++ AirBomber/AirBomber/MoveToCenter.cs | 56 ++++++++++++++ 4 files changed, 198 insertions(+), 26 deletions(-) create mode 100644 AirBomber/AirBomber/MoveToBorder.cs create mode 100644 AirBomber/AirBomber/MoveToCenter.cs diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index c0d96ee..a8ba700 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -28,25 +28,28 @@ /// private void InitializeComponent() { - buttonCreate = new Button(); + buttonCreateAirBomber = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); pictureBoxAirBomber = new PictureBox(); + buttonCreateAirPlane = new Button(); + comboBoxStrategy = new ComboBox(); + buttonStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // - // buttonCreate + // buttonCreateAirBomber // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(47, 364); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(186, 45); - buttonCreate.TabIndex = 0; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateAirBomber.Location = new Point(40, 343); + buttonCreateAirBomber.Name = "buttonCreateAirBomber"; + buttonCreateAirBomber.Size = new Size(186, 66); + buttonCreateAirBomber.TabIndex = 0; + buttonCreateAirBomber.Text = "Создать бомбардировщик"; + buttonCreateAirBomber.UseVisualStyleBackColor = true; + buttonCreateAirBomber.Click += buttonCreateAirBomber_Click; // // buttonLeft // @@ -105,16 +108,51 @@ pictureBoxAirBomber.TabIndex = 5; pictureBoxAirBomber.TabStop = false; // + // buttonCreateAirPlane + // + buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateAirPlane.Location = new Point(248, 343); + buttonCreateAirPlane.Name = "buttonCreateAirPlane"; + buttonCreateAirPlane.Size = new Size(186, 66); + buttonCreateAirPlane.TabIndex = 6; + buttonCreateAirPlane.Text = "Создать самолёт"; + buttonCreateAirPlane.UseVisualStyleBackColor = true; + buttonCreateAirPlane.Click += buttonCreateAirPlane_Click; + // + // comboBoxStrategy + // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" }); + comboBoxStrategy.Location = new Point(590, 21); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(182, 33); + comboBoxStrategy.TabIndex = 7; + // + // buttonStep + // + buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStep.Location = new Point(660, 70); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(112, 34); + buttonStep.TabIndex = 8; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(800, 450); + Controls.Add(buttonStep); + Controls.Add(comboBoxStrategy); + Controls.Add(buttonCreateAirPlane); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); - Controls.Add(buttonCreate); + Controls.Add(buttonCreateAirBomber); Controls.Add(pictureBoxAirBomber); Name = "FormAirBomber"; Text = "Бомбардировщик"; @@ -124,11 +162,14 @@ #endregion - private Button buttonCreate; + private Button buttonCreateAirBomber; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private Button buttonDown; private PictureBox pictureBoxAirBomber; + private Button buttonCreateAirPlane; + private ComboBox comboBoxStrategy; + private Button buttonStep; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 2612e1c..1d3a1c3 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -2,36 +2,48 @@ namespace AirBomber { public partial class FormAirBomber : Form { - private DrawningAirBomber? _drawningAirBomber; + private DrawningAirPlane? _drawningAirPlane; + private AbstractStrategy? _abstractStrategy; public FormAirBomber() { InitializeComponent(); } private void Draw() { - if (_drawningAirBomber == null) + if (_drawningAirPlane == null) { return; } Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningAirBomber.DrawBomber(gr); + _drawningAirPlane.DrawPlane(gr); pictureBoxAirBomber.Image = bmp; } - private void buttonCreate_Click(object sender, EventArgs e) + private void buttonCreateAirPlane_Click(object sender, EventArgs e) { Random random = new(); - _drawningAirBomber = new DrawningAirBomber(); - _drawningAirBomber.Init(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - random.Next(1, 4) * 2, pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - _drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); + _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonCreateAirBomber_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + + _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + + } private void buttonMove_Click(object sender, EventArgs e) { - if (_drawningAirBomber == null) + if (_drawningAirPlane == null) { return; } @@ -39,19 +51,56 @@ namespace AirBomber switch (name) { case "buttonUp": - _drawningAirBomber.MoveTransport(DirectionType.Up); + _drawningAirPlane.MovePlane(DirectionType.Up); break; case "buttonDown": - _drawningAirBomber.MoveTransport(DirectionType.Down); + _drawningAirPlane.MovePlane(DirectionType.Down); break; case "buttonLeft": - _drawningAirBomber.MoveTransport(DirectionType.Left); + _drawningAirPlane.MovePlane(DirectionType.Left); break; case "buttonRight": - _drawningAirBomber.MoveTransport(DirectionType.Right); + _drawningAirPlane.MovePlane(DirectionType.Right); break; } Draw(); } + + private void buttonStep_Click(object sender, EventArgs e) + { + if (_drawningAirPlane == null) + { + return; + } + if (comboBoxStrategy.Enabled) + { + _abstractStrategy = comboBoxStrategy.SelectedIndex + switch + { + 0 => new MoveToCenter(), + 1 => new MoveToBorder(), + _ => null, + }; + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.SetData(new + DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, + pictureBoxAirBomber.Height); + comboBoxStrategy.Enabled = false; + } + if (_abstractStrategy == null) + { + return; + } + _abstractStrategy.MakeStep(); + Draw(); + if (_abstractStrategy.GetStatus() == Status.Finish) + { + comboBoxStrategy.Enabled = true; + _abstractStrategy = null; + } + } } } \ No newline at end of file diff --git a/AirBomber/AirBomber/MoveToBorder.cs b/AirBomber/AirBomber/MoveToBorder.cs new file mode 100644 index 0000000..b853ffd --- /dev/null +++ b/AirBomber/AirBomber/MoveToBorder.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class MoveToBorder : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) return false; + + return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep(); + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) return; + if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight(); + if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown(); + } + } +} diff --git a/AirBomber/AirBomber/MoveToCenter.cs b/AirBomber/AirBomber/MoveToCenter.cs new file mode 100644 index 0000000..99711ff --- /dev/null +++ b/AirBomber/AirBomber/MoveToCenter.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class MoveToCenter : AbstractStrategy + { + protected override bool IsTargetDestinaion() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return false; + } + return objParams.ObjectMiddleHorizontal <= FieldWidth / 2 && + objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 && + objParams.ObjectMiddleVertical <= FieldHeight / 2 && + objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2; + } + protected override void MoveToTarget() + { + var objParams = GetObjectParameters; + if (objParams == null) + { + return; + } + var diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2; + if (Math.Abs(diffX) > GetStep()) + { + if (diffX > 0) + { + MoveLeft(); + } + else + { + MoveRight(); + } + } + var diffY = objParams.ObjectMiddleVertical - FieldHeight / 2; + if (Math.Abs(diffY) > GetStep()) + { + if (diffY > 0) + { + MoveUp(); + } + else + { + MoveDown(); + } + } + } + } +} -- 2.25.1 From 52dd126a68a449900705d40697ad91f16f5e78c1 Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 17:20:02 +0400 Subject: [PATCH 7/9] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=20?= =?UTF-8?q?=D0=B8=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20=D0=BF=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2?= =?UTF-8?q?=D0=BA=D0=B8=20IDrawningEngines?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/IDrawningEngines.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 AirBomber/AirBomber/IDrawningEngines.cs diff --git a/AirBomber/AirBomber/IDrawningEngines.cs b/AirBomber/AirBomber/IDrawningEngines.cs new file mode 100644 index 0000000..dfeb2c8 --- /dev/null +++ b/AirBomber/AirBomber/IDrawningEngines.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal interface IDrawningEngines + { + public void SetAmount(int a); + public void DrawEngines(Graphics g, int _startPosX, int _startPosY); + } +} -- 2.25.1 From ec08a44682cc1ed06d0b9525d8c1afadee88c82f Mon Sep 17 00:00:00 2001 From: malimova Date: Sun, 26 Nov 2023 22:01:52 +0400 Subject: [PATCH 8/9] =?UTF-8?q?=D0=92=D1=81=D1=91=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE=20=D0=B2=20=D1=83=D1=81=D0=BB=D0=BE?= =?UTF-8?q?=D0=B6=D0=BD=D0=B5=D0=BD=D0=BD=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 20 +-- AirBomber/AirBomber/DrawningAirPlane.cs | 25 ++-- AirBomber/AirBomber/DrawningEnginesCircle.cs | 94 +++++++++++++ ...Engines.cs => DrawningEnginesRectangle.cs} | 2 +- .../AirBomber/DrawningEnginesTriangle.cs | 130 ++++++++++++++++++ AirBomber/AirBomber/FormAirBomber.cs | 25 ++-- 6 files changed, 261 insertions(+), 35 deletions(-) create mode 100644 AirBomber/AirBomber/DrawningEnginesCircle.cs rename AirBomber/AirBomber/{DrawningEngines.cs => DrawningEnginesRectangle.cs} (98%) create mode 100644 AirBomber/AirBomber/DrawningEnginesTriangle.cs diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index f92ad33..1d4e68a 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -8,8 +8,8 @@ namespace AirBomber { public class DrawningAirBomber : DrawningAirPlane { - public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int width, int height) : - base(speed, weight, bodyColor, width, height, 160, 118) + public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, bool fuelTanks, int width, int height, int engines, int enginesShape) : + base(speed, weight, bodyColor, width, height, engines, enginesShape) { if (EntityAirPlane != null) { @@ -26,17 +26,17 @@ namespace AirBomber Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); base.DrawPlane(g); // bombs - g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 20, 15, 29); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); - g.FillEllipse(additionalBrush, _startPosX + 90, _startPosY + 70, 15, 29); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); + g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 30, 15, 15); + g.DrawEllipse(pen, _startPosX + 140, _startPosY + 30, 15, 15); + g.FillEllipse(additionalBrush, _startPosX + 140, _startPosY + 70, 15, 15); + g.DrawEllipse(pen, _startPosX + 140, _startPosY + 70, 15, 15); // fueltanks - g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); - g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15); - g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 70, 20, 15); - g.DrawRectangle(pen, _startPosX + 63, _startPosY + 70, 20, 15); + g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 34, 30, 15); + g.DrawRectangle(pen, _startPosX + 85, _startPosY + 34, 30, 15); + g.FillRectangle(additionalBrush, _startPosX + 85, _startPosY + 70, 30, 15); + g.DrawRectangle(pen, _startPosX + 85, _startPosY + 70, 30, 15); } } } diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 455d9f6..b28b224 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -15,7 +15,8 @@ namespace AirBomber protected int _startPosY; protected readonly int _airPlaneWidth = 150; protected readonly int _airPlaneHeight = 118; - public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height) + private IDrawningEngines drawningEngines; + public DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height, int engines, int enginesShape) { if (width < _airPlaneWidth || height < _airPlaneHeight) { @@ -24,18 +25,19 @@ namespace AirBomber _pictureWidth = width; _pictureHeight = height; EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); - } - protected DrawningAirPlane(int speed, double weight, Color bodyColor, int width, int height, int airPlaneWidth, int airPlaneHeight) - { - if (width < _airPlaneWidth || height < _airPlaneHeight) + switch (enginesShape) { - return; + case 1: + drawningEngines = new DrawningEnginesCircle(); + break; + case 2: + drawningEngines = new DrawningEnginesTriangle(); + break; + default: + drawningEngines = new DrawningEnginesRectangle(); + break; } - _pictureWidth = width; - _pictureHeight = height; - _airPlaneWidth = airPlaneWidth; - _airPlaneHeight = airPlaneHeight; - EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + drawningEngines.SetAmount(engines); } public void SetPosition(int x, int y) { @@ -140,6 +142,7 @@ namespace AirBomber new Point(_startPosX + 140, _startPosY + 70), } ); + drawningEngines.DrawEngines(g, _startPosX, _startPosY); } public int GetPosX => _startPosX; public int GetPosY => _startPosY; diff --git a/AirBomber/AirBomber/DrawningEnginesCircle.cs b/AirBomber/AirBomber/DrawningEnginesCircle.cs new file mode 100644 index 0000000..e6ae763 --- /dev/null +++ b/AirBomber/AirBomber/DrawningEnginesCircle.cs @@ -0,0 +1,94 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class DrawningEnginesCircle : IDrawningEngines + { + private Engines amount; + public void SetAmount(int a) + { + if (a <= 2) + { + amount = Engines.Two; + } + else if (a == 4) + { + amount = Engines.Four; + } + else if (a >= 6) + { + amount = Engines.Six; + } + } + public void DrawEngines(Graphics g, int _startPosX, int _startPosY) + { + Brush enginesColor = new SolidBrush(Color.Black); + + g.FillPolygon(enginesColor, new Point[] //two up + { + new Point(_startPosX + 51, _startPosY + 30), + new Point(_startPosX + 75, _startPosY + 30), + new Point(_startPosX + 75, _startPosY + 40), + new Point(_startPosX + 53, _startPosY + 40), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 28, 13, 13); + g.FillPolygon(enginesColor, new Point[] //two down + { + new Point(_startPosX + 52, _startPosY + 80), + new Point(_startPosX + 75, _startPosY + 80), + new Point(_startPosX + 75, _startPosY + 90), + new Point(_startPosX + 50, _startPosY + 90), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 78, 13, 13); + + if (amount == Engines.Four || amount == Engines.Six) + { + g.FillPolygon(enginesColor, new Point[] //four up + { + new Point(_startPosX + 48, _startPosY + 18), + new Point(_startPosX + 75, _startPosY + 18), + new Point(_startPosX + 75, _startPosY + 28), + new Point(_startPosX + 50, _startPosY + 28), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 16, 13, 13); + g.FillPolygon(enginesColor, new Point[] //four down + { + new Point(_startPosX + 49, _startPosY + 92), + new Point(_startPosX + 75, _startPosY + 92), + new Point(_startPosX + 75, _startPosY + 102), + new Point(_startPosX + 47, _startPosY + 102), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 90, 13, 13); + } + if (amount == Engines.Six) + { + g.FillPolygon(enginesColor, new Point[] //six up + { + new Point(_startPosX + 46, _startPosY + 6), + new Point(_startPosX + 75, _startPosY + 6), + new Point(_startPosX + 75, _startPosY + 16), + new Point(_startPosX + 48, _startPosY + 16), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 4, 13, 13); + g.FillPolygon(enginesColor, new Point[] //six down + { + new Point(_startPosX + 47, _startPosY + 104), + new Point(_startPosX + 75, _startPosY + 104), + new Point(_startPosX + 75, _startPosY + 114), + new Point(_startPosX + 45, _startPosY + 114), + } + ); + g.FillEllipse(enginesColor, _startPosX + 71, _startPosY + 102, 13, 13); + } + } + } +} diff --git a/AirBomber/AirBomber/DrawningEngines.cs b/AirBomber/AirBomber/DrawningEnginesRectangle.cs similarity index 98% rename from AirBomber/AirBomber/DrawningEngines.cs rename to AirBomber/AirBomber/DrawningEnginesRectangle.cs index 64d97f8..8801ec8 100644 --- a/AirBomber/AirBomber/DrawningEngines.cs +++ b/AirBomber/AirBomber/DrawningEnginesRectangle.cs @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace AirBomber { - internal class DrawningEngines + public class DrawningEnginesRectangle : IDrawningEngines { private Engines amount; public void SetAmount(int a) diff --git a/AirBomber/AirBomber/DrawningEnginesTriangle.cs b/AirBomber/AirBomber/DrawningEnginesTriangle.cs new file mode 100644 index 0000000..bd6b48b --- /dev/null +++ b/AirBomber/AirBomber/DrawningEnginesTriangle.cs @@ -0,0 +1,130 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + public class DrawningEnginesTriangle : IDrawningEngines + { + private Engines amount; + public void SetAmount(int a) + { + if (a <= 2) + { + amount = Engines.Two; + } + else if (a == 4) + { + amount = Engines.Four; + } + else if (a >= 6) + { + amount = Engines.Six; + } + } + public void DrawEngines(Graphics g, int _startPosX, int _startPosY) + { + Brush enginesColor = new SolidBrush(Color.Black); + + g.FillPolygon(enginesColor, new Point[] //two up + { + new Point(_startPosX + 51, _startPosY + 30), + new Point(_startPosX + 75, _startPosY + 30), + new Point(_startPosX + 75, _startPosY + 40), + new Point(_startPosX + 53, _startPosY + 40), + } + ); + g.FillPolygon(enginesColor, new Point[] //two up TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 33), + new Point(_startPosX + 80, _startPosY + 28), + new Point(_startPosX + 80, _startPosY + 41), + } + ); + g.FillPolygon(enginesColor, new Point[] //two down + { + new Point(_startPosX + 52, _startPosY + 80), + new Point(_startPosX + 75, _startPosY + 80), + new Point(_startPosX + 75, _startPosY + 90), + new Point(_startPosX + 50, _startPosY + 90), + } + ); + g.FillPolygon(enginesColor, new Point[] //two down TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 83), + new Point(_startPosX + 80, _startPosY + 78), + new Point(_startPosX + 80, _startPosY + 91), + } + ); + + if (amount == Engines.Four || amount == Engines.Six) + { + g.FillPolygon(enginesColor, new Point[] //four up + { + new Point(_startPosX + 48, _startPosY + 18), + new Point(_startPosX + 75, _startPosY + 18), + new Point(_startPosX + 75, _startPosY + 28), + new Point(_startPosX + 50, _startPosY + 28), + } + ); + g.FillPolygon(enginesColor, new Point[] //four up TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 23), + new Point(_startPosX + 80, _startPosY + 16), + new Point(_startPosX + 80, _startPosY + 27), + } + ); + g.FillPolygon(enginesColor, new Point[] //four down + { + new Point(_startPosX + 49, _startPosY + 92), + new Point(_startPosX + 75, _startPosY + 92), + new Point(_startPosX + 75, _startPosY + 102), + new Point(_startPosX + 47, _startPosY + 102), + } + ); + g.FillPolygon(enginesColor, new Point[] //four down TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 97), + new Point(_startPosX + 80, _startPosY + 92), + new Point(_startPosX + 80, _startPosY + 105), + } + ); + } + if (amount == Engines.Six) + { + g.FillPolygon(enginesColor, new Point[] //six up + { + new Point(_startPosX + 46, _startPosY + 6), + new Point(_startPosX + 75, _startPosY + 6), + new Point(_startPosX + 75, _startPosY + 16), + new Point(_startPosX + 48, _startPosY + 16), + } + ); + g.FillPolygon(enginesColor, new Point[] //six up TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 11), + new Point(_startPosX + 80, _startPosY + 5), + new Point(_startPosX + 80, _startPosY + 17), + } + ); + g.FillPolygon(enginesColor, new Point[] //six down + { + new Point(_startPosX + 47, _startPosY + 104), + new Point(_startPosX + 75, _startPosY + 104), + new Point(_startPosX + 75, _startPosY + 114), + new Point(_startPosX + 45, _startPosY + 114), + } + ); + g.FillPolygon(enginesColor, new Point[] //six down TRIANGLE SHAPE + { + new Point(_startPosX + 73, _startPosY + 109), + new Point(_startPosX + 80, _startPosY + 103), + new Point(_startPosX + 80, _startPosY + 115), + } + ); + } + } + } +} diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 1d3a1c3..17830fd 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -19,28 +19,28 @@ namespace AirBomber _drawningAirPlane.DrawPlane(gr); pictureBoxAirBomber.Image = bmp; } - private void buttonCreateAirPlane_Click(object sender, EventArgs e) - { - Random random = new(); - _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - - _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); - Draw(); - } private void buttonCreateAirBomber_Click(object sender, EventArgs e) { Random random = new(); _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(1, 3)); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + private void buttonCreateAirPlane_Click(object sender, EventArgs e) + { + Random random = new(); + _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(1, 3)); + + _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Draw(); + } private void buttonMove_Click(object sender, EventArgs e) { if (_drawningAirPlane == null) @@ -65,7 +65,6 @@ namespace AirBomber } Draw(); } - private void buttonStep_Click(object sender, EventArgs e) { if (_drawningAirPlane == null) -- 2.25.1 From c3bb9c66ccb6124ed8dbe21216e618aa67e437f7 Mon Sep 17 00:00:00 2001 From: malimova Date: Wed, 29 Nov 2023 21:08:42 +0400 Subject: [PATCH 9/9] =?UTF-8?q?=D0=92=D1=81=D1=91=20=D1=81=D0=B4=D0=B5?= =?UTF-8?q?=D0=BB=D0=B0=D0=BD=D0=BE,=20Lab2=20=D1=81=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/FormAirBomber.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 17830fd..6922714 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -25,7 +25,7 @@ namespace AirBomber _drawningAirPlane = new DrawningAirBomber(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(1, 3)); + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); @@ -36,7 +36,7 @@ namespace AirBomber Random random = new(); _drawningAirPlane = new DrawningAirPlane(random.Next(100, 300), random.Next(1000, 3000), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(1, 3)); + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height, random.Next(1, 4) * 2, random.Next(0, 4)); _drawningAirPlane.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); @@ -84,8 +84,7 @@ namespace AirBomber { return; } - _abstractStrategy.SetData(new - DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, + _abstractStrategy.SetData(new DrawningObjectAirPlane(_drawningAirPlane), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); comboBoxStrategy.Enabled = false; } -- 2.25.1