From e1ac61109d94d12c2c928cd83620e6926d7cf729 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 20:29:31 +0400 Subject: [PATCH 01/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D1=81=D1=83=D1=89?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=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 0d60e02b8a8a5ecf23a454666dc5fa5ab30b70f5 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 20:51:17 +0400 Subject: [PATCH 02/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B1=D0=B0=D0=B7=D0=BE=D0=B2=D0=BE=D0=B3=D0=BE?= =?UTF-8?q?=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20=D0=BF=D1=80=D0=BE?= =?UTF-8?q?=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8=20DrawningAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 219 ++++++++++++++++++++++++ AirBomber/AirBomber/EntityAirPlane.cs | 31 +++- 2 files changed, 249 insertions(+), 1 deletion(-) 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..d884669 --- /dev/null +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -0,0 +1,219 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal class DrawningAirPlane + { + /// + /// Класс-сущность + /// + public EntityAirPlane? EntityAirPlane { get; protected set; } + /// + /// Ширина окна + /// + private int _pictureWidth; + /// + /// Высота окна + /// + private int _pictureHeight; + /// + /// Левая координата прорисовки самолета + /// + protected int _startPosX; + /// + /// Верхняя кооридната прорисовки самолета + /// + protected int _startPosY; + /// + /// Ширина прорисовки самолета + /// + protected readonly int _airPlaneWidth = 100; + /// + /// Высота прорисовки самолета + /// + protected readonly int _airPlaneHeight = 55; + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Ширина картинки + /// Высота картинки + public DrawningAirPlane(int speed, double weight, Color bodyColor, int + width, int height) + { + // TODO: Продумать проверки + _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) + { + // TODO: Продумать проверки + _pictureWidth = width; + _pictureHeight = height; + _airPlaneWidth = airPlaneWidth; + _airPlaneHeight = airPlaneHeight; + EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); + } + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + // TODO: Изменение x, y, если при установке объект выходит за границы + _startPosX = x; + _startPosY = y; + } + /// + /// Изменение направления перемещения + /// + /// Направление + public void MoveTransport(DirectionType direction) + { + if (EntityAirPlane == null) + { + return; + } + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX - EntityAirPlane.Step > 0) + { + _startPosX -= (int)EntityAirPlane.Step; + } + break; + //вверх + case DirectionType.Up: + if (_startPosY - EntityAirPlane.Step > 0) + { + _startPosY -= (int)EntityAirPlane.Step; + } + break; + // вправо + case DirectionType.Right: + // TODO: Продумать логику + break; + //вниз + case DirectionType.Down: + // TODO: Продумать логику + break; + } + } + /// + /// Прорисовка объекта + /// + /// + 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), + } + ); + } + + } +} diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index 643523a..d0f206c 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -6,7 +6,36 @@ 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; + } + } } -- 2.25.1 From e8e666afdc2829e6f2b0ea10f566c6552fee0f23 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 21:00:38 +0400 Subject: [PATCH 03/21] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?-=D1=81=D1=83=D1=89=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20"=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"=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0=20EntityAi?= =?UTF-8?q?rBomber?= 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 051adc5..e1a1f81 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -6,22 +6,15 @@ 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 Color BombsColor { get; private set; } public bool FuelTanks { get; private set; } - public double Step => (double)Speed * 100 / Weight; - public void Init(int speed, double weight, Color bodyColor, Color + public EntityAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; Bombs = bombs; BombsColor = bombsColor; -- 2.25.1 From 5a4093e10f90361ddd2c09bc152ef39dfb8fdedf Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 21:16:06 +0400 Subject: [PATCH 04/21] =?UTF-8?q?=D0=9E=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?-=D0=BF=D1=80=D0=BE=D1=80=D0=B8=D1=81=D0=BE=D0=B2=D0=BA=D0=B8?= =?UTF-8?q?=20"=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"=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82?= =?UTF-8?q?=D0=B0=20DrawningAirBomber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 179 ++++------------------- AirBomber/AirBomber/DrawningAirPlane.cs | 2 +- 2 files changed, 28 insertions(+), 153 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index b9decf0..a5d0dbe 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -7,87 +7,42 @@ 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; - public bool Init(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия обвеса + /// Признак наличия антикрыла + /// Признак наличия гоночной полосы + /// Ширина картинки + /// Высота картинки + public DrawningAirBomber(int speed, double weight, Color bodyColor, Color + additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : + + base(speed, weight, bodyColor, width, height, 110, 60) { - _pictureWidth = width; - _pictureHeight = height; - if (width < _bomberWidth || height < _bomberHeight) + if (EntityAirPlane != null) { - return false; - } - EntityAirBomber = new EntityAirBomber(); - EntityAirBomber.Init(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks); - return true; - } - public void SetPosition(int x, int y) - { - if (x < 0 || x + _bomberWidth > _pictureWidth) - { - x = _pictureWidth - _bomberWidth; + EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); } - if (y < 0 || y + _bomberWidth > _pictureHeight) - { - y = _pictureHeight - _bomberHeight; - } - _startPosX = x; - _startPosY = y; } - public void MoveTransport(DirectionType direction) + public override void DrawPlane(Graphics g) { - 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; - } - } - public void DrawBomber(Graphics g) - { - if (EntityAirBomber == null) + if (EntityAirPlane is not EntityAirPlane sportCar) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAirBomber.AdditionalColor); - Brush bodyColor = new SolidBrush(EntityAirBomber.BodyColor); - Brush bombsColor = new SolidBrush(EntityAirBomber.BombsColor); - Brush wingsColor = new SolidBrush(Color.DeepPink); - if (EntityAirBomber.Bombs) + Brush additionalBrush = new + SolidBrush(airBomber.AdditionalColor); + // обвесы + if (airBomber.Bombs) { g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); @@ -95,89 +50,9 @@ namespace AirBomber g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 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), - } - ); + base.DrawPlane(g); + // fueltanks if (EntityAirBomber.FuelTanks) { g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index d884669..982df68 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace AirBomber { - internal class DrawningAirPlane + public class DrawningAirPlane { /// /// Класс-сущность -- 2.25.1 From 63b5bc994b625596bff5e7f4596d95e45165096f Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 21:25:37 +0400 Subject: [PATCH 05/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B2=20DrawningAirBomber?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index a5d0dbe..50ea92b 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -30,17 +30,16 @@ namespace AirBomber { EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); } - } public override void DrawPlane(Graphics g) { - if (EntityAirPlane is not EntityAirPlane sportCar) + if (EntityAirPlane is not EntityAirPlane airBomber) { return; } Pen pen = new(Color.Black); - Brush additionalBrush = new - SolidBrush(airBomber.AdditionalColor); + Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); + base.DrawPlane(g); // обвесы if (airBomber.Bombs) { @@ -51,9 +50,8 @@ namespace AirBomber g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); } - base.DrawPlane(g); // fueltanks - if (EntityAirBomber.FuelTanks) + if (airBomber.FuelTanks) { g.FillRectangle(additionalBrush, _startPosX + 63, _startPosY + 34, 20, 15); g.DrawRectangle(pen, _startPosX + 63, _startPosY + 34, 20, 15); -- 2.25.1 From 23663c6c473a26163cb78e3afc935d8e581fb73a Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 21:44:42 +0400 Subject: [PATCH 06/21] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=D0=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 11 ++++++----- AirBomber/AirBomber/DrawningAirPlane.cs | 1 + AirBomber/AirBomber/EntityAirBomber.cs | 1 + 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index 50ea92b..f18461c 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -4,6 +4,7 @@ using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBomber; namespace AirBomber { @@ -16,9 +17,8 @@ namespace AirBomber /// Вес /// Основной цвет /// Дополнительный цвет - /// Признак наличия обвеса - /// Признак наличия антикрыла - /// Признак наличия гоночной полосы + /// Признак наличия обвеса + /// Признак наличия антикрыла /// Ширина картинки /// Высота картинки public DrawningAirBomber(int speed, double weight, Color bodyColor, Color @@ -28,17 +28,18 @@ namespace AirBomber { if (EntityAirPlane != null) { - EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, fuelTanks); + EntityAirPlane = new EntityAirBomber(speed, weight, bodyColor, additionalColor, bombs, bombsColor, fuelTanks); } } public override void DrawPlane(Graphics g) { - if (EntityAirPlane is not EntityAirPlane airBomber) + if (EntityAirPlane is not EntityAirBomber airBomber) { return; } Pen pen = new(Color.Black); Brush additionalBrush = new SolidBrush(airBomber.AdditionalColor); + Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы if (airBomber.Bombs) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 982df68..f746d98 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBomber; namespace AirBomber { diff --git a/AirBomber/AirBomber/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index e1a1f81..5a1c723 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBomber; namespace AirBomber { -- 2.25.1 From 12ba5a0148ba7f9a64e3b0043bab32b54fd906e3 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:08:25 +0400 Subject: [PATCH 07/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20IMoveableObject,=20=D0=BD=D0=BE=D0=B2=D1=8B?= =?UTF-8?q?=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B2=20Drawni?= =?UTF-8?q?ngAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 71 ++++++++++++++++++++++++- AirBomber/AirBomber/EntityAirPlane.cs | 1 + AirBomber/AirBomber/IMoveableObject.cs | 12 +++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 AirBomber/AirBomber/IMoveableObject.cs diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index f746d98..c9af062 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -215,6 +215,75 @@ namespace AirBomber } ); } - + /// + /// Координата X объекта + /// + public int GetPosX => _startPosX; + /// + /// Координата Y объекта + /// + public int GetPosY => _startPosY; + /// + /// Ширина объекта + /// + public int GetWidth => _airPlaneWidth; + /// + /// Высота объекта + /// + public int GetHeight => _airPlaneHeight; + /// + /// Проверка, что объект может переместится по указанному направлению + /// + /// Направление + /// true - можно переместится по указанному направлению + 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 => false,// TODO: Продумать логику + //вниз + DirectionType.Down => false,// TODO: Продумать логику + _ => 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; + } + } } } diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index d0f206c..8934f22 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using AirBomber; namespace AirBomber { diff --git a/AirBomber/AirBomber/IMoveableObject.cs b/AirBomber/AirBomber/IMoveableObject.cs new file mode 100644 index 0000000..9cc5cfd --- /dev/null +++ b/AirBomber/AirBomber/IMoveableObject.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace AirBomber +{ + internal interface IMoveableObject + { + } +} -- 2.25.1 From e6028b4a0e50d7bc770db6613333fff85b0dcf6e Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:15:39 +0400 Subject: [PATCH 08/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0-=D1=80?= =?UTF-8?q?=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B8=20=D0=B8?= =?UTF-8?q?=D0=BD=D1=82=D0=B5=D1=80=D1=84=D0=B5=D0=B9=D1=81=D0=B0=20-=20Dr?= =?UTF-8?q?awningObjectAirPlane?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObjectAirPlane.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/DrawningObjectAirPlane.cs diff --git a/AirBomber/AirBomber/DrawningObjectAirPlane.cs b/AirBomber/AirBomber/DrawningObjectAirPlane.cs new file mode 100644 index 0000000..18343ab --- /dev/null +++ b/AirBomber/AirBomber/DrawningObjectAirPlane.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 DrawningObjectAirPlane + { + } +} -- 2.25.1 From 297eb3a2abc8fe7ce7a0ff036def367398e1bc98 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:20:15 +0400 Subject: [PATCH 09/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0=20ObjectPar?= =?UTF-8?q?ameters?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/ObjectParameters.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/ObjectParameters.cs diff --git a/AirBomber/AirBomber/ObjectParameters.cs b/AirBomber/AirBomber/ObjectParameters.cs new file mode 100644 index 0000000..ffb8fa4 --- /dev/null +++ b/AirBomber/AirBomber/ObjectParameters.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 ObjectParameters + { + } +} -- 2.25.1 From 03c6fa946c5ebfcdbdf5dc6111562ebd09c7a0b7 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:21:39 +0400 Subject: [PATCH 10/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=BF=D0=B5=D1=80=D0=B5=D1=87=D0=B8=D1=81=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20Status?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/Status.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/Status.cs diff --git a/AirBomber/AirBomber/Status.cs b/AirBomber/AirBomber/Status.cs new file mode 100644 index 0000000..7f97095 --- /dev/null +++ b/AirBomber/AirBomber/Status.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 Status + { + } +} -- 2.25.1 From b69d10b87293f0a13c8e731c430e7102c35eed7b Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:25:36 +0400 Subject: [PATCH 11/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20AbstractStrategy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractStrategy.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/AbstractStrategy.cs diff --git a/AirBomber/AirBomber/AbstractStrategy.cs b/AirBomber/AirBomber/AbstractStrategy.cs new file mode 100644 index 0000000..e71c750 --- /dev/null +++ b/AirBomber/AirBomber/AbstractStrategy.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 AbstractStrategy + { + } +} -- 2.25.1 From f3380608697b73fc8b2ae45baa06ace80142b40b Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:28:54 +0400 Subject: [PATCH 12/21] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86?= =?UTF-8?q?=D0=B8=D0=B8=20=D0=B0=D0=B1=D1=81=D1=82=D1=80=D0=B0=D0=BA=D1=82?= =?UTF-8?q?=D0=BD=D0=BE=D0=B3=D0=BE=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0?= =?UTF-8?q?=20-=20MoveToCenter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/MoveToCenter.cs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 AirBomber/AirBomber/MoveToCenter.cs diff --git a/AirBomber/AirBomber/MoveToCenter.cs b/AirBomber/AirBomber/MoveToCenter.cs new file mode 100644 index 0000000..699394c --- /dev/null +++ b/AirBomber/AirBomber/MoveToCenter.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 MoveToCenter + { + } +} -- 2.25.1 From 5c75d533a1a68ef09db5d529031b70704d4aaf98 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 22:41:12 +0400 Subject: [PATCH 13/21] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D0=BE=D1=88?= =?UTF-8?q?=D0=B8=D0=B1=D0=BE=D0=BA,=20=D0=B8=D0=B7=D0=BC=D0=B5=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/AbstractStrategy.cs | 121 +++++++++++++++++++++++- AirBomber/AirBomber/EntityAirBomber.cs | 2 +- AirBomber/AirBomber/IMoveableObject.cs | 22 ++++- AirBomber/AirBomber/MoveToCenter.cs | 47 ++++++++- AirBomber/AirBomber/ObjectParameters.cs | 44 ++++++++- AirBomber/AirBomber/Status.cs | 5 +- 6 files changed, 235 insertions(+), 6 deletions(-) diff --git a/AirBomber/AirBomber/AbstractStrategy.cs b/AirBomber/AirBomber/AbstractStrategy.cs index e71c750..7b44070 100644 --- a/AirBomber/AirBomber/AbstractStrategy.cs +++ b/AirBomber/AirBomber/AbstractStrategy.cs @@ -6,7 +6,126 @@ using System.Threading.Tasks; namespace AirBomber { - internal class AbstractStrategy + 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(); + } + /// + /// Перемещение влево + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveLeft() => MoveTo(DirectionType.Left); + /// + /// Перемещение вправо + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveRight() => MoveTo(DirectionType.Right); + /// + /// Перемещение вверх + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + protected bool MoveUp() => MoveTo(DirectionType.Up); + /// + /// Перемещение вниз + /// + /// Результат перемещения (true - удалось переместиться, false - неудача) + 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(); + /// + /// Попытка перемещения в требуемом направлении + /// + /// Направление + /// Результат попытки (true - удалось переместиться, false - неудача) + 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/EntityAirBomber.cs b/AirBomber/AirBomber/EntityAirBomber.cs index 5a1c723..e64ad03 100644 --- a/AirBomber/AirBomber/EntityAirBomber.cs +++ b/AirBomber/AirBomber/EntityAirBomber.cs @@ -14,7 +14,7 @@ namespace AirBomber public Color BombsColor { get; private set; } public bool FuelTanks { get; private set; } public EntityAirBomber(int speed, double weight, Color bodyColor, Color - additionalColor, bool bombs, Color bombsColor, bool fuelTanks) + additionalColor, bool bombs, Color bombsColor, bool fuelTanks) : base(speed, weight, bodyColor) { AdditionalColor = additionalColor; Bombs = bombs; diff --git a/AirBomber/AirBomber/IMoveableObject.cs b/AirBomber/AirBomber/IMoveableObject.cs index 9cc5cfd..92a08fc 100644 --- a/AirBomber/AirBomber/IMoveableObject.cs +++ b/AirBomber/AirBomber/IMoveableObject.cs @@ -6,7 +6,27 @@ using System.Threading.Tasks; namespace AirBomber { - internal interface IMoveableObject + public interface IMoveableObject { + /// + /// Получение координаты X объекта + /// + ObjectParameters? GetObjectPosition { get; } + /// + /// Шаг объекта + /// + int GetStep { get; } + /// + /// Проверка, можно ли переместиться по нужному направлению + /// + /// + /// + bool CheckCanMove(DirectionType direction); + /// + /// Изменение направления пермещения объекта + /// + /// Направление + void MoveObject(DirectionType direction); + } } diff --git a/AirBomber/AirBomber/MoveToCenter.cs b/AirBomber/AirBomber/MoveToCenter.cs index 699394c..f600563 100644 --- a/AirBomber/AirBomber/MoveToCenter.cs +++ b/AirBomber/AirBomber/MoveToCenter.cs @@ -6,7 +6,52 @@ using System.Threading.Tasks; namespace AirBomber { - internal class MoveToCenter + 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(); + } + } + } + } } diff --git a/AirBomber/AirBomber/ObjectParameters.cs b/AirBomber/AirBomber/ObjectParameters.cs index ffb8fa4..99e383f 100644 --- a/AirBomber/AirBomber/ObjectParameters.cs +++ b/AirBomber/AirBomber/ObjectParameters.cs @@ -6,7 +6,49 @@ using System.Threading.Tasks; namespace AirBomber { - internal class ObjectParameters + 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; + /// + /// Конструктор + /// + /// Координата X + /// Координата Y + /// Ширина + /// Высота + 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 index 7f97095..3e0828d 100644 --- a/AirBomber/AirBomber/Status.cs +++ b/AirBomber/AirBomber/Status.cs @@ -6,7 +6,10 @@ using System.Threading.Tasks; namespace AirBomber { - internal class Status + public enum Status { + NotInit, + InProgress, + Finish } } -- 2.25.1 From 5890fcbba7004d6c9a478309033b95d2b9c9014a Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 23:12:58 +0400 Subject: [PATCH 14/21] =?UTF-8?q?=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=84=D0=BE=D1=80=D0=BC=D1=8B=20(?= =?UTF-8?q?=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B8,=20=D1=8D=D0=BB=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D1=82=D0=BE=D0=B2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningObjectAirPlane.cs | 25 +++++++++- AirBomber/AirBomber/FormAirBomber.Designer.cs | 50 ++++++++++++++----- AirBomber/AirBomber/FormAirBomber.cs | 47 +++++++++++------ 3 files changed, 94 insertions(+), 28 deletions(-) diff --git a/AirBomber/AirBomber/DrawningObjectAirPlane.cs b/AirBomber/AirBomber/DrawningObjectAirPlane.cs index 18343ab..fe16e4a 100644 --- a/AirBomber/AirBomber/DrawningObjectAirPlane.cs +++ b/AirBomber/AirBomber/DrawningObjectAirPlane.cs @@ -6,7 +6,30 @@ using System.Threading.Tasks; namespace AirBomber { - internal class DrawningObjectAirPlane + 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?.MoveTransport(direction); } } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 5e931c9..26b2b51 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -28,25 +28,27 @@ /// private void InitializeComponent() { - buttonCreate = new Button(); + buttonCreateAirBomber = new Button(); buttonDown = new Button(); buttonLeft = new Button(); buttonRight = new Button(); buttonUp = new Button(); pictureBoxAirBomber = new PictureBox(); + comboBoxStrategy = new ComboBox(); + buttonCreateAirPlane = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // - // buttonCreate + // buttonCreateAirBomber // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(29, 479); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(148, 34); - buttonCreate.TabIndex = 0; - buttonCreate.Text = "Создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateAirBomber.Location = new Point(29, 447); + buttonCreateAirBomber.Name = "buttonCreateAirBomber"; + buttonCreateAirBomber.Size = new Size(191, 66); + buttonCreateAirBomber.TabIndex = 0; + buttonCreateAirBomber.Text = "Создать бомбардировщик"; + buttonCreateAirBomber.UseVisualStyleBackColor = true; + buttonCreateAirBomber.Click += buttonCreateAirBomber_Click; // // buttonDown // @@ -106,16 +108,38 @@ pictureBoxAirBomber.TabIndex = 5; pictureBoxAirBomber.TabStop = false; // + // comboBoxStrategy + // + comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxStrategy.FormattingEnabled = true; + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" }); + comboBoxStrategy.Location = new Point(755, 26); + comboBoxStrategy.Name = "comboBoxStrategy"; + comboBoxStrategy.Size = new Size(219, 33); + comboBoxStrategy.TabIndex = 6; + // + // buttonCreateAirPlane + // + buttonCreateAirPlane.Location = new Point(249, 447); + buttonCreateAirPlane.Name = "buttonCreateAirPlane"; + buttonCreateAirPlane.Size = new Size(191, 65); + buttonCreateAirPlane.TabIndex = 7; + buttonCreateAirPlane.Text = "Создать самолёт"; + buttonCreateAirPlane.UseVisualStyleBackColor = true; + buttonCreateAirPlane.Click += buttonCreateAirPlane_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); + Controls.Add(buttonCreateAirPlane); + Controls.Add(comboBoxStrategy); Controls.Add(buttonUp); Controls.Add(buttonRight); Controls.Add(buttonLeft); Controls.Add(buttonDown); - Controls.Add(buttonCreate); + Controls.Add(buttonCreateAirBomber); Controls.Add(pictureBoxAirBomber); Name = "FormAirBomber"; Text = "Бомбардировщик"; @@ -125,11 +149,13 @@ #endregion - private Button buttonCreate; + private Button buttonCreateAirBomber; private Button buttonDown; private Button buttonLeft; private Button buttonRight; private Button buttonUp; private PictureBox pictureBoxAirBomber; + private ComboBox comboBoxStrategy; + private Button buttonCreateAirPlane; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index cf453fb..a365f9c 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -2,37 +2,52 @@ { 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 buttonCreateAirBomber_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)), + _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)), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - - _drawningAirBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); + Convert.ToBoolean(random.Next(0, 2)), Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), + Convert.ToBoolean(random.Next(0, 2)), + pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + + _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); + + _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; } @@ -40,19 +55,21 @@ switch (name) { case "buttonUp": - _drawningAirBomber.MoveTransport(DirectionType.Up); + _drawningAirPlane.MoveTransport(DirectionType.Up); break; case "buttonDown": - _drawningAirBomber.MoveTransport(DirectionType.Down); + _drawningAirPlane.MoveTransport(DirectionType.Down); break; case "buttonLeft": - _drawningAirBomber.MoveTransport(DirectionType.Left); + _drawningAirPlane.MoveTransport(DirectionType.Left); break; case "buttonRight": - _drawningAirBomber.MoveTransport(DirectionType.Right); + _drawningAirPlane.MoveTransport(DirectionType.Right); break; } Draw(); } + + } } \ No newline at end of file -- 2.25.1 From 68ac0088fd2925d2814b799a019db35e708bc3b8 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 23:43:59 +0400 Subject: [PATCH 15/21] =?UTF-8?q?=D0=A4=D0=B8=D0=BA=D1=81=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D1=8B,=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3=D0=B8=D0=B8=20MoveTo?= =?UTF-8?q?Center?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 9 ++--- AirBomber/AirBomber/DrawningAirPlane.cs | 16 +++++--- AirBomber/AirBomber/FormAirBomber.Designer.cs | 16 ++++++++ AirBomber/AirBomber/FormAirBomber.cs | 37 ++++++++++++++++++- 4 files changed, 66 insertions(+), 12 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index f18461c..acb1c5c 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -42,23 +42,20 @@ namespace AirBomber Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы - if (airBomber.Bombs) - { + g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); - } + // fueltanks - if (airBomber.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/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index c9af062..18f23d8 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -112,11 +112,17 @@ namespace AirBomber break; // вправо case DirectionType.Right: - // TODO: Продумать логику + if (_startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth) + { + _startPosX += (int)EntityAirPlane.Step; + } break; //вниз case DirectionType.Down: - // TODO: Продумать логику + if (_startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight) + { + _startPosY += (int)EntityAirPlane.Step; + } break; } } @@ -249,9 +255,9 @@ namespace AirBomber //вверх DirectionType.Up => _startPosY - EntityAirPlane.Step > 0, // вправо - DirectionType.Right => false,// TODO: Продумать логику - //вниз - DirectionType.Down => false,// TODO: Продумать логику + DirectionType.Right => _startPosX + EntityAirPlane.Step < _pictureWidth, + //вниз + DirectionType.Down => _startPosY + EntityAirPlane.Step < _pictureHeight, _ => false, }; } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 26b2b51..637d4fb 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -36,6 +36,7 @@ pictureBoxAirBomber = new PictureBox(); comboBoxStrategy = new ComboBox(); buttonCreateAirPlane = new Button(); + buttonStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // @@ -110,6 +111,7 @@ // // comboBoxStrategy // + comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" }); @@ -120,6 +122,7 @@ // // buttonCreateAirPlane // + buttonCreateAirPlane.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; buttonCreateAirPlane.Location = new Point(249, 447); buttonCreateAirPlane.Name = "buttonCreateAirPlane"; buttonCreateAirPlane.Size = new Size(191, 65); @@ -128,11 +131,23 @@ buttonCreateAirPlane.UseVisualStyleBackColor = true; buttonCreateAirPlane.Click += buttonCreateAirPlane_Click; // + // buttonStep + // + buttonStep.Anchor = AnchorStyles.Top | AnchorStyles.Right; + buttonStep.Location = new Point(862, 77); + buttonStep.Name = "buttonStep"; + buttonStep.Size = new Size(112, 49); + buttonStep.TabIndex = 8; + buttonStep.Text = "Шаг"; + buttonStep.UseVisualStyleBackColor = true; + buttonStep.Click += buttonStep_Click; + // // FormAirBomber // AutoScaleDimensions = new SizeF(10F, 25F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(986, 540); + Controls.Add(buttonStep); Controls.Add(buttonCreateAirPlane); Controls.Add(comboBoxStrategy); Controls.Add(buttonUp); @@ -157,5 +172,6 @@ private PictureBox pictureBoxAirBomber; private ComboBox comboBoxStrategy; private Button buttonCreateAirPlane; + private Button buttonStep; } } \ No newline at end of file diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index a365f9c..785941a 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -69,7 +69,42 @@ } 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 -- 2.25.1 From 21f5c7ac1be9e54f85d3911511080fcac57f5e49 Mon Sep 17 00:00:00 2001 From: malimova Date: Fri, 6 Oct 2023 23:57:59 +0400 Subject: [PATCH 16/21] =?UTF-8?q?=D0=9B=D0=BE=D0=B3=D0=B8=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3=D0=B8=D0=B8=20MoveTo?= =?UTF-8?q?Border=20+=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D0=B8=D0=B5=20=D1=80=D0=B0=D0=B7=D0=BC=D0=B5=D1=80=D0=BE?= =?UTF-8?q?=D0=B2=20=D0=BE=D0=B1=D0=BE=D0=B8=D1=85=20=D0=BE=D0=B1=D1=8A?= =?UTF-8?q?=D0=B5=D0=BA=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 2 +- AirBomber/AirBomber/DrawningAirPlane.cs | 4 ++-- AirBomber/AirBomber/FormAirBomber.cs | 2 +- AirBomber/AirBomber/MoveToBorder.cs | 27 ++++++++++++++++++++++++ 4 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 AirBomber/AirBomber/MoveToBorder.cs diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index acb1c5c..b8eabe9 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -24,7 +24,7 @@ namespace AirBomber public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : - base(speed, weight, bodyColor, width, height, 110, 60) + base(speed, weight, bodyColor, width, height, 160, 118) { if (EntityAirPlane != null) { diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 18f23d8..64dce49 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -32,11 +32,11 @@ namespace AirBomber /// /// Ширина прорисовки самолета /// - protected readonly int _airPlaneWidth = 100; + protected readonly int _airPlaneWidth = 150; /// /// Высота прорисовки самолета /// - protected readonly int _airPlaneHeight = 55; + protected readonly int _airPlaneHeight = 118; /// /// Конструктор /// diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 785941a..45f158b 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -81,7 +81,7 @@ switch { 0 => new MoveToCenter(), - //1 => new MoveToBorder(), + 1 => new MoveToBorder(), _ => null, }; if (_abstractStrategy == null) diff --git a/AirBomber/AirBomber/MoveToBorder.cs b/AirBomber/AirBomber/MoveToBorder.cs new file mode 100644 index 0000000..435ab8d --- /dev/null +++ b/AirBomber/AirBomber/MoveToBorder.cs @@ -0,0 +1,27 @@ +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(); + + } + } +} -- 2.25.1 From 8cd9bd77c14757304d2d99d01549a278841fcba3 Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 7 Oct 2023 09:06:57 +0400 Subject: [PATCH 17/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BC=D0=B5=D1=82=D0=BE=D0=B4?= =?UTF-8?q?=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 38 ------------------- AirBomber/AirBomber/DrawningObjectAirPlane.cs | 2 +- AirBomber/AirBomber/FormAirBomber.Designer.cs | 2 +- AirBomber/AirBomber/FormAirBomber.cs | 8 ++-- AirBomber/AirBomber/IMoveableObject.cs | 1 - AirBomber/AirBomber/MoveToBorder.cs | 1 - 6 files changed, 6 insertions(+), 46 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 64dce49..3d6d33a 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -88,44 +88,6 @@ namespace AirBomber /// Изменение направления перемещения /// /// Направление - public void MoveTransport(DirectionType direction) - { - if (EntityAirPlane == null) - { - return; - } - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX - EntityAirPlane.Step > 0) - { - _startPosX -= (int)EntityAirPlane.Step; - } - break; - //вверх - case DirectionType.Up: - if (_startPosY - EntityAirPlane.Step > 0) - { - _startPosY -= (int)EntityAirPlane.Step; - } - break; - // вправо - case DirectionType.Right: - if (_startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth) - { - _startPosX += (int)EntityAirPlane.Step; - } - break; - //вниз - case DirectionType.Down: - if (_startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight) - { - _startPosY += (int)EntityAirPlane.Step; - } - break; - } - } /// /// Прорисовка объекта /// diff --git a/AirBomber/AirBomber/DrawningObjectAirPlane.cs b/AirBomber/AirBomber/DrawningObjectAirPlane.cs index fe16e4a..bce8cdb 100644 --- a/AirBomber/AirBomber/DrawningObjectAirPlane.cs +++ b/AirBomber/AirBomber/DrawningObjectAirPlane.cs @@ -30,6 +30,6 @@ namespace AirBomber public bool CheckCanMove(DirectionType direction) => _drawningAirPlane?.CanMove(direction) ?? false; public void MoveObject(DirectionType direction) => - _drawningAirPlane?.MoveTransport(direction); + _drawningAirPlane?.MovePlane(direction); } } diff --git a/AirBomber/AirBomber/FormAirBomber.Designer.cs b/AirBomber/AirBomber/FormAirBomber.Designer.cs index 637d4fb..7dd0993 100644 --- a/AirBomber/AirBomber/FormAirBomber.Designer.cs +++ b/AirBomber/AirBomber/FormAirBomber.Designer.cs @@ -114,7 +114,7 @@ comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right; comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; comboBoxStrategy.FormattingEnabled = true; - comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToRightEdge" }); + comboBoxStrategy.Items.AddRange(new object[] { "MoveToCenter", "MoveToBorder" }); comboBoxStrategy.Location = new Point(755, 26); comboBoxStrategy.Name = "comboBoxStrategy"; comboBoxStrategy.Size = new Size(219, 33); diff --git a/AirBomber/AirBomber/FormAirBomber.cs b/AirBomber/AirBomber/FormAirBomber.cs index 45f158b..aa7e5ba 100644 --- a/AirBomber/AirBomber/FormAirBomber.cs +++ b/AirBomber/AirBomber/FormAirBomber.cs @@ -55,16 +55,16 @@ switch (name) { case "buttonUp": - _drawningAirPlane.MoveTransport(DirectionType.Up); + _drawningAirPlane.MovePlane(DirectionType.Up); break; case "buttonDown": - _drawningAirPlane.MoveTransport(DirectionType.Down); + _drawningAirPlane.MovePlane(DirectionType.Down); break; case "buttonLeft": - _drawningAirPlane.MoveTransport(DirectionType.Left); + _drawningAirPlane.MovePlane(DirectionType.Left); break; case "buttonRight": - _drawningAirPlane.MoveTransport(DirectionType.Right); + _drawningAirPlane.MovePlane(DirectionType.Right); break; } Draw(); diff --git a/AirBomber/AirBomber/IMoveableObject.cs b/AirBomber/AirBomber/IMoveableObject.cs index 92a08fc..2c271c2 100644 --- a/AirBomber/AirBomber/IMoveableObject.cs +++ b/AirBomber/AirBomber/IMoveableObject.cs @@ -27,6 +27,5 @@ namespace AirBomber /// /// Направление void MoveObject(DirectionType direction); - } } diff --git a/AirBomber/AirBomber/MoveToBorder.cs b/AirBomber/AirBomber/MoveToBorder.cs index 435ab8d..b6bb968 100644 --- a/AirBomber/AirBomber/MoveToBorder.cs +++ b/AirBomber/AirBomber/MoveToBorder.cs @@ -21,7 +21,6 @@ namespace AirBomber var objParams = GetObjectParameters; if (objParams == null) return; if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight(); - } } } -- 2.25.1 From c11d4126a5ac23c01299a17ebc4d03eba5f1b904 Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 7 Oct 2023 09:27:50 +0400 Subject: [PATCH 18/21] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2?= =?UTF-8?q?=D0=BB=D0=B5=D0=BD=D0=B8=D0=B5=20=D0=BB=D0=BE=D0=B3=D0=B8=D0=BA?= =?UTF-8?q?=D0=B8=20=D0=B4=D0=B2=D0=B8=D0=B6=D0=B5=D0=BD=D0=B8=D1=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 3d6d33a..daeaea6 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -81,6 +81,14 @@ namespace AirBomber public void SetPosition(int x, int y) { // TODO: Изменение x, y, если при установке объект выходит за границы + if (x < 0 || x + _airPlaneWidth > _pictureWidth) + { + x = _pictureWidth - _airPlaneWidth; + } + if (y < 0 || y + _airPlaneHeight > _pictureHeight) + { + y = _pictureHeight - _airPlaneHeight; + } _startPosX = x; _startPosY = y; } @@ -217,9 +225,9 @@ namespace AirBomber //вверх DirectionType.Up => _startPosY - EntityAirPlane.Step > 0, // вправо - DirectionType.Right => _startPosX + EntityAirPlane.Step < _pictureWidth, + DirectionType.Right => _startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth, //вниз - DirectionType.Down => _startPosY + EntityAirPlane.Step < _pictureHeight, + DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight< _pictureHeight, _ => false, }; } -- 2.25.1 From fd17593df5bb84de4ca742b625b44ed2ae9a3c68 Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 7 Oct 2023 09:46:26 +0400 Subject: [PATCH 19/21] =?UTF-8?q?=D0=94=D0=BE=D1=80=D0=B0=D0=B1=D0=BE?= =?UTF-8?q?=D1=82=D0=BA=D0=B0=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20?= =?UTF-8?q?=D1=81=D1=82=D1=80=D0=B0=D1=82=D0=B5=D0=B3=D0=B8=D0=B8,=20?= =?UTF-8?q?=D1=87=D0=B8=D1=81=D1=82=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 4 +--- AirBomber/AirBomber/DrawningAirPlane.cs | 2 +- AirBomber/AirBomber/MoveToBorder.cs | 1 + 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index b8eabe9..ef48919 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -22,7 +22,7 @@ namespace AirBomber /// Ширина картинки /// Высота картинки public DrawningAirBomber(int speed, double weight, Color bodyColor, Color - additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : + additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : base(speed, weight, bodyColor, width, height, 160, 118) { @@ -42,14 +42,12 @@ namespace AirBomber Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы - g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); g.FillEllipse(bombsColor, _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); diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index daeaea6..237e2dd 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -227,7 +227,7 @@ namespace AirBomber // вправо DirectionType.Right => _startPosX + EntityAirPlane.Step + _airPlaneWidth < _pictureWidth, //вниз - DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight< _pictureHeight, + DirectionType.Down => _startPosY + EntityAirPlane.Step + _airPlaneHeight < _pictureHeight, _ => false, }; } diff --git a/AirBomber/AirBomber/MoveToBorder.cs b/AirBomber/AirBomber/MoveToBorder.cs index b6bb968..f0c5ff3 100644 --- a/AirBomber/AirBomber/MoveToBorder.cs +++ b/AirBomber/AirBomber/MoveToBorder.cs @@ -21,6 +21,7 @@ namespace AirBomber var objParams = GetObjectParameters; if (objParams == null) return; if (objParams.RightBorder < FieldWidth - GetStep()) MoveRight(); + if (objParams.DownBorder < FieldHeight - GetStep()) MoveDown(); } } } -- 2.25.1 From 379eabc701ff74e70200283f5496b85f9a85a05e Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 7 Oct 2023 10:53:33 +0400 Subject: [PATCH 20/21] =?UTF-8?q?=D0=97=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=83=D0=B6=D0=B5=20=D1=81=D0=B4?= =?UTF-8?q?=D0=B5=D0=BB=D0=B0=D0=BD=D0=BD=D1=8B=D1=85=20=D0=B2=20=D0=BF?= =?UTF-8?q?=D1=80=D0=BE=D1=88=D0=BB=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1=D0=B5?= =?UTF-8?q?=20TODOs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirPlane.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/AirBomber/AirBomber/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 237e2dd..31a4a17 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -67,6 +67,10 @@ namespace AirBomber width, int height, int airPlaneWidth, int airPlaneHeight) { // TODO: Продумать проверки + if (width < _airPlaneWidth || height < _airPlaneHeight) + { + return; + } _pictureWidth = width; _pictureHeight = height; _airPlaneWidth = airPlaneWidth; -- 2.25.1 From c8cd888bf16e0caf7ee4492a2222c7039c14ca27 Mon Sep 17 00:00:00 2001 From: malimova Date: Sat, 7 Oct 2023 10:59:50 +0400 Subject: [PATCH 21/21] =?UTF-8?q?=D0=A4=D0=BE=D1=80=D0=BC=D0=B0=D1=82?= =?UTF-8?q?=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8=D0=B5=20=D0=BA=D0=BE?= =?UTF-8?q?=D0=B4=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirBomber/AirBomber/DrawningAirBomber.cs | 22 ++++++++++------------ AirBomber/AirBomber/DrawningAirPlane.cs | 4 ++++ AirBomber/AirBomber/EntityAirPlane.cs | 1 - AirBomber/AirBomber/MoveToBorder.cs | 1 - AirBomber/AirBomber/Program.cs | 1 - 5 files changed, 14 insertions(+), 15 deletions(-) diff --git a/AirBomber/AirBomber/DrawningAirBomber.cs b/AirBomber/AirBomber/DrawningAirBomber.cs index ef48919..5ed19eb 100644 --- a/AirBomber/AirBomber/DrawningAirBomber.cs +++ b/AirBomber/AirBomber/DrawningAirBomber.cs @@ -23,7 +23,6 @@ namespace AirBomber /// Высота картинки public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool bombs, Color bombsColor, bool fuelTanks, int width, int height) : - base(speed, weight, bodyColor, width, height, 160, 118) { if (EntityAirPlane != null) @@ -42,18 +41,17 @@ namespace AirBomber Brush bombsColor = new SolidBrush(airBomber.BombsColor); base.DrawPlane(g); // обвесы - g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); - g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); - g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); - g.FillEllipse(bombsColor, _startPosX + 140, _startPosY + 50, 15, 15); - g.DrawEllipse(pen, _startPosX + 140, _startPosY + 50, 15, 15); + g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 20, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 20, 15, 29); + g.FillEllipse(bombsColor, _startPosX + 90, _startPosY + 70, 15, 29); + g.DrawEllipse(pen, _startPosX + 90, _startPosY + 70, 15, 29); + g.FillEllipse(bombsColor, _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); - + 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/DrawningAirPlane.cs b/AirBomber/AirBomber/DrawningAirPlane.cs index 31a4a17..758f92c 100644 --- a/AirBomber/AirBomber/DrawningAirPlane.cs +++ b/AirBomber/AirBomber/DrawningAirPlane.cs @@ -49,6 +49,10 @@ namespace AirBomber width, int height) { // TODO: Продумать проверки + if (width < _airPlaneWidth || height < _airPlaneHeight) + { + return; + } _pictureWidth = width; _pictureHeight = height; EntityAirPlane = new EntityAirPlane(speed, weight, bodyColor); diff --git a/AirBomber/AirBomber/EntityAirPlane.cs b/AirBomber/AirBomber/EntityAirPlane.cs index 8934f22..a8341c9 100644 --- a/AirBomber/AirBomber/EntityAirPlane.cs +++ b/AirBomber/AirBomber/EntityAirPlane.cs @@ -37,6 +37,5 @@ namespace AirBomber Weight = weight; BodyColor = bodyColor; } - } } diff --git a/AirBomber/AirBomber/MoveToBorder.cs b/AirBomber/AirBomber/MoveToBorder.cs index f0c5ff3..b853ffd 100644 --- a/AirBomber/AirBomber/MoveToBorder.cs +++ b/AirBomber/AirBomber/MoveToBorder.cs @@ -15,7 +15,6 @@ namespace AirBomber return objParams.RightBorder >= FieldWidth - GetStep() && objParams.DownBorder >= FieldHeight - GetStep(); } - protected override void MoveToTarget() { var objParams = GetObjectParameters; diff --git a/AirBomber/AirBomber/Program.cs b/AirBomber/AirBomber/Program.cs index f167f45..76b85fe 100644 --- a/AirBomber/AirBomber/Program.cs +++ b/AirBomber/AirBomber/Program.cs @@ -7,7 +7,6 @@ namespace AirBomber /// [STAThread] static void Main() - { // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. -- 2.25.1