From f465b4ada8ae30e25c3d4448ad3f22a301c6c8c8 Mon Sep 17 00:00:00 2001 From: Egor_Shtyrkin Date: Sun, 14 Apr 2024 19:11:40 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=B4=D0=B5=D0=BB=D0=B0=D0=BB=20=D0=BF?= =?UTF-8?q?=D0=B5=D1=80=D0=B2=D1=83=D1=8E=20=D1=87=D0=B0=D1=81=D1=82=D1=8C?= =?UTF-8?q?=20=D0=B2=D1=82=D0=BE=D1=80=D0=BE=D0=B9=20=D0=BB=D0=B0=D0=B1?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D1=82=D0=BE=D1=80=D0=BD=D0=BE=D0=B9.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DrawningAircraftCarrier.cs | 252 ------------------ .../{ => Drawnings}/DirectionType.cs | 2 +- .../Drawnings/DrawningAircraftCarrier.cs | 74 +++++ .../Drawnings/DrawningWarship.cs | 236 ++++++++++++++++ .../{ => Entities}/EntityAircraftCarrier.cs | 22 +- .../Entities/EntityWarship.cs | 40 +++ .../FormAircraftCarrier.Designer.cs | 49 ++-- .../FormAircraftCarrier.cs | 65 +++-- 8 files changed, 428 insertions(+), 312 deletions(-) delete mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs rename ProjectAircraftCarrier/ProjectAircraftCarrier/{ => Drawnings}/DirectionType.cs (89%) create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningAircraftCarrier.cs create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarship.cs rename ProjectAircraftCarrier/ProjectAircraftCarrier/{ => Entities}/EntityAircraftCarrier.cs (77%) create mode 100644 ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityWarship.cs diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs deleted file mode 100644 index 0970936..0000000 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/DrawningAircraftCarrier.cs +++ /dev/null @@ -1,252 +0,0 @@ -namespace ProjectAircraftCarrier; - -/// -/// Класс, отвечающий за прорисовку и перемещение объекта-сущности -/// -public class DrawningAircraftCarrier -{ - /// - /// Класс-сущность - /// - public EntityAircraftCarrier? EntityAircraftCarrier { get; private set; } - - /// - /// Ширина окна - /// - private int? _pictureWidth; - - /// - /// Высота окна - /// - private int? _pictureHeight; - - /// - /// Левая координата прорисовки авианосца - /// - private int? _startPosX; - - /// - /// Верхняя координата отрисовки авианосца - /// - private int? _startPosY; - - /// - /// Ширина прорисовки авианосца - /// - private readonly int _drawningAircraftCarrierWidth = 145; - - /// - /// Высота прорисовки авианосца - /// - private readonly int _drawningAircraftCarrierHeight = 55; - - /// - /// Инициализация свойств - /// - /// Скорость - /// Вес - /// Основной цвет - /// Дополнительный цвет - /// Признак наличия взлётно-посадочной полосы - /// Признак наличия рубки управления - public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom) - { - EntityAircraftCarrier = new EntityAircraftCarrier(); - EntityAircraftCarrier.Init(speed, weight, bodyColor, additionalColor, aircraftDeck, controlRoom); - _pictureWidth = null; - _pictureHeight = null; - _startPosX = null; - _startPosY = null; - } - - /// - /// Установка границ поля - /// - /// Ширина поля - /// Высота поля - /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах - public bool SetPictureSize(int width, int height) - { - if (width < _drawningAircraftCarrierWidth || height < _drawningAircraftCarrierHeight) - { - return false; - } - - _pictureWidth = width; - _pictureHeight = height; - if (_startPosX != null || _startPosY != null) - { - if (_startPosX + _drawningAircraftCarrierWidth > _pictureWidth) - { - _startPosX = -_drawningAircraftCarrierWidth + _pictureWidth; - } - else if (_startPosX < 0) - { - _startPosX = 0; - } - if (_startPosY + _drawningAircraftCarrierHeight > _pictureHeight) - { - _startPosY = -_drawningAircraftCarrierHeight + _pictureHeight; - } - else if (_startPosY < 0) - { - _startPosY = 0; - } - } - return true; - - } - - /// - /// Установка позиции - /// - /// Координата X - /// Координата Y - public void SetPosition(int x, int y) - { - if(!_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - - if(x < 0 || x + _drawningAircraftCarrierWidth > _pictureWidth) - { - x = 0; - } - - if(y < 0 || y + _drawningAircraftCarrierHeight > _pictureHeight) - { - y = 0; - } - - _startPosX = x; - _startPosY = y; - } - - /// - /// Измнение направления перемещения - /// - /// Направление - /// true - перемещение выполнено, false - перемещение невозможно - public bool MoveTransport(DirectionType direction) - { - if(EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return false; - } - - switch (direction) - { - //влево - case DirectionType.Left: - if (_startPosX.Value - EntityAircraftCarrier.Step > 0) - { - _startPosX -= (int)EntityAircraftCarrier.Step; - } - return true; - //вверх - case DirectionType.Up: - if (_startPosY.Value - EntityAircraftCarrier.Step > 0) - { - _startPosY -= (int)EntityAircraftCarrier.Step; - } - return true; - //вправо - case DirectionType.Right: - if (_startPosX.Value + _drawningAircraftCarrierWidth + EntityAircraftCarrier.Step < _pictureWidth) - { - _startPosX += (int)EntityAircraftCarrier.Step; - } - return true; - //вниз - case DirectionType.Down: - if (_startPosY.Value + _drawningAircraftCarrierHeight + EntityAircraftCarrier.Step < _pictureHeight) - { - _startPosY += (int)EntityAircraftCarrier.Step; - } - return true; - default: - return false; - } - } - - /// - /// Прорисовка объекта - /// - /// - public void DrawTransport(Graphics g) - { - if (EntityAircraftCarrier == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue) - { - return; - } - - Pen pen = new(Color.Black); - Brush additionalBrush = new SolidBrush(EntityAircraftCarrier.AdditionalColor); - - //границы авианосца - Point[] FramePoints = { - new Point(_startPosX.Value + 5, _startPosY.Value), - new Point(_startPosX.Value + 105, _startPosY.Value), - new Point(_startPosX.Value + 145, _startPosY.Value + 25), - new Point(_startPosX.Value + 105, _startPosY.Value + 50), - new Point(_startPosX.Value + 5, _startPosY.Value + 50), - }; - g.DrawPolygon(pen, FramePoints); - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 5, 18); - g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 27, 5, 18); - - //корпус авианосца - Brush br = new SolidBrush(EntityAircraftCarrier.BodyColor); - g.FillPolygon(br, FramePoints); - - //отсеки авианосца - Brush brGray = new SolidBrush(Color.Gray); - g.FillRectangle(brGray, _startPosX.Value + 80, _startPosY.Value + 10, 15, 30); - g.FillRectangle(brGray, _startPosX.Value + 60, _startPosY.Value + 20, 20, 10); - g.FillEllipse(brGray, _startPosX.Value + 100, _startPosY.Value + 14, 20, 20); - - //выделяем рамкой отсеки авианосца - g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 10, 15, 30); - g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 20, 20, 10); - g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 14, 20, 20); - - //двигатели авианосца - Brush brBlack = new SolidBrush(Color.Black); - g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 5, 5, 18); - g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 27, 5, 18); - - //рубка управления - if (EntityAircraftCarrier.ControlRoom) - { - g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 42, 15, 15); - g.FillRectangle(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 42, 15, 15); - g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 46, 15, 7); - g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 46, 5, 7); - g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 46, 5, 7); - g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 42, 15, 15); - g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 42, 15, 15); - g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 46, 15, 7); - g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 46, 5, 7); - g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 46, 5, 7); - g.DrawRectangle(pen, _startPosX.Value + 39, _startPosY.Value + 46, 7, 7); - g.DrawRectangle(pen, _startPosX.Value + 69, _startPosY.Value + 46, 7, 7); - - } - - //палуба для взлёта самолётов - if (EntityAircraftCarrier.AircraftDeck) - { - Point[] DeckPoint = - { - new Point(_startPosX.Value + 5, _startPosY.Value + 25), - new Point(_startPosX.Value + 5, _startPosY.Value + 45), - new Point(_startPosX.Value + 50, _startPosY.Value + 20), - new Point(_startPosX.Value + 50, _startPosY.Value), - }; - g.FillPolygon(additionalBrush, DeckPoint); - g.DrawPolygon(pen, DeckPoint); - g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 35, _startPosX.Value + 50, _startPosY.Value + 10); - } - } -} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DirectionType.cs similarity index 89% rename from ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs rename to ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DirectionType.cs index ad2d556..535eb13 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/DirectionType.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DirectionType.cs @@ -1,4 +1,4 @@ -namespace ProjectAircraftCarrier; +namespace ProjectAircraftCarrier.Drawnings; /// /// Направление перемещения diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningAircraftCarrier.cs new file mode 100644 index 0000000..28c938a --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningAircraftCarrier.cs @@ -0,0 +1,74 @@ +using ProjectAircraftCarrier.Entities; +using System.Drawing; + +namespace ProjectAircraftCarrier.Drawnings; + +/// +/// Класс, отвечающий за прорисовку и перемещение объекта-сущности +/// +public class DrawningAircraftCarrier : DrawningWarship +{ + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + /// Дополнительный цвет + /// Признак наличия взлётно-посадочной полосы + /// Признак наличия рубки управления + public DrawningAircraftCarrier(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom) : base(145, 55) + { + EntityWarship = new EntityAircraftCarrier(speed, weight, bodyColor, additionalColor, aircraftDeck, controlRoom); + } + + public override void DrawTransport(Graphics g) + { + if (EntityWarship == null || EntityWarship is not EntityAircraftCarrier warship || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + Brush additionalBrush = new SolidBrush(warship.AdditionalColor); + + _startPosX += 5; + _startPosY += 10; + base.DrawTransport(g); + _startPosX -= 5; + _startPosX -= 10; + + //рубка управления + if (warship.ControlRoom) + { + g.FillRectangle(additionalBrush, _startPosX.Value + 35, _startPosY.Value + 42, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 65, _startPosY.Value + 42, 15, 15); + g.FillRectangle(additionalBrush, _startPosX.Value + 50, _startPosY.Value + 46, 15, 7); + g.FillRectangle(additionalBrush, _startPosX.Value + 30, _startPosY.Value + 46, 5, 7); + g.FillRectangle(additionalBrush, _startPosX.Value + 80, _startPosY.Value + 46, 5, 7); + g.DrawRectangle(pen, _startPosX.Value + 35, _startPosY.Value + 42, 15, 15); + g.DrawRectangle(pen, _startPosX.Value + 65, _startPosY.Value + 42, 15, 15); + g.DrawRectangle(pen, _startPosX.Value + 50, _startPosY.Value + 46, 15, 7); + g.DrawRectangle(pen, _startPosX.Value + 30, _startPosY.Value + 46, 5, 7); + g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 46, 5, 7); + g.DrawRectangle(pen, _startPosX.Value + 39, _startPosY.Value + 46, 7, 7); + g.DrawRectangle(pen, _startPosX.Value + 69, _startPosY.Value + 46, 7, 7); + + } + + //палуба для взлёта самолётов + if (warship.AircraftDeck) + { + Point[] DeckPoint = + { + new Point(_startPosX.Value + 5, _startPosY.Value + 25), + new Point(_startPosX.Value + 5, _startPosY.Value + 45), + new Point(_startPosX.Value + 50, _startPosY.Value + 20), + new Point(_startPosX.Value + 50, _startPosY.Value), + }; + g.FillPolygon(additionalBrush, DeckPoint); + g.DrawPolygon(pen, DeckPoint); + g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 35, _startPosX.Value + 50, _startPosY.Value + 10); + } + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarship.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarship.cs new file mode 100644 index 0000000..888d41a --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Drawnings/DrawningWarship.cs @@ -0,0 +1,236 @@ +using ProjectAircraftCarrier.Entities; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectAircraftCarrier.Drawnings; + +public class DrawningWarship +{ + /// + /// Класс-сущность + /// + public EntityWarship? EntityWarship { get; protected set; } + + /// + /// Ширина окна + /// + private int? _pictureWidth; + + /// + /// Высота окна + /// + private int? _pictureHeight; + + /// + /// Левая координата прорисовки военного корабля + /// + protected int? _startPosX; + + /// + /// Верхняя координата отрисовки военного корабля + /// + protected int? _startPosY; + + /// + /// Ширина прорисовки военного корабля + /// + private readonly int _drawningWarshipWidth = 145; + + /// + /// Высота прорисовки военного корабля + /// + private readonly int _drawningWarshipHeight = 50; + + /// + /// Пустой конструктор + /// + private DrawningWarship() + { + _pictureWidth = null; + _pictureHeight = null; + _startPosX = null; + _startPosY = null; + } + + /// + /// Конструктор + /// + /// Скорость + /// Вес + /// Основной цвет + public DrawningWarship(int speed, double weight, Color bodyColor) : this() + { + EntityWarship = new EntityWarship(speed, weight, bodyColor); + } + + /// + /// Конструктор для наследников + /// + /// Ширина прорисовки военного корабля + /// Высота прорисовки военного корабля + protected DrawningWarship(int drawningWarshipWidth, int drawningWarshipHeight) : this() + { + _drawningWarshipWidth = drawningWarshipWidth; + _drawningWarshipHeight = drawningWarshipHeight; + } + + /// + /// Установка границ поля + /// + /// Ширина поля + /// Высота поля + /// true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах + public bool SetPictureSize(int width, int height) + { + if (width < _drawningWarshipWidth || height < _drawningWarshipHeight) + { + return false; + } + + _pictureWidth = width; + _pictureHeight = height; + if (_startPosX != null || _startPosY != null) + { + if (_startPosX + _drawningWarshipWidth > _pictureWidth) + { + _startPosX = -_drawningWarshipWidth + _pictureWidth; + } + else if (_startPosX < 0) + { + _startPosX = 0; + } + if (_startPosY + _drawningWarshipHeight > _pictureHeight) + { + _startPosY = -_drawningWarshipHeight + _pictureHeight; + } + else if (_startPosY < 0) + { + _startPosY = 0; + } + } + return true; + + } + + /// + /// Установка позиции + /// + /// Координата X + /// Координата Y + public void SetPosition(int x, int y) + { + if (!_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return; + } + + if (x < 0 || x + _drawningWarshipWidth > _pictureWidth) + { + x = 0; + } + + if (y < 0 || y + _drawningWarshipHeight > _pictureHeight) + { + y = 0; + } + + _startPosX = x; + _startPosY = y; + } + + /// + /// Измнение направления перемещения + /// + /// Направление + /// true - перемещение выполнено, false - перемещение невозможно + public bool MoveTransport(DirectionType direction) + { + if (EntityWarship == null || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return false; + } + + switch (direction) + { + //влево + case DirectionType.Left: + if (_startPosX.Value - EntityWarship.Step > 0) + { + _startPosX -= (int)EntityWarship.Step; + } + return true; + //вверх + case DirectionType.Up: + if (_startPosY.Value - EntityWarship.Step > 0) + { + _startPosY -= (int)EntityWarship.Step; + } + return true; + //вправо + case DirectionType.Right: + if (_startPosX.Value + _drawningWarshipWidth + EntityWarship.Step < _pictureWidth) + { + _startPosX += (int)EntityWarship.Step; + } + return true; + //вниз + case DirectionType.Down: + if (_startPosY.Value + _drawningWarshipHeight + EntityWarship.Step < _pictureHeight) + { + _startPosY += (int)EntityWarship.Step; + } + return true; + default: + return false; + } + } + + /// + /// Прорисовка объекта + /// + /// + public virtual void DrawTransport(Graphics g) + { + if (EntityWarship == null || !_startPosX.HasValue || !_startPosY.HasValue) + { + return; + } + + Pen pen = new(Color.Black); + + //границы военного корабля + Point[] FramePoints = { + new Point(_startPosX.Value + 5, _startPosY.Value), + new Point(_startPosX.Value + 105, _startPosY.Value), + new Point(_startPosX.Value + 145, _startPosY.Value + 25), + new Point(_startPosX.Value + 105, _startPosY.Value + 50), + new Point(_startPosX.Value + 5, _startPosY.Value + 50), + }; + g.DrawPolygon(pen, FramePoints); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 5, 5, 18); + g.DrawRectangle(pen, _startPosX.Value, _startPosY.Value + 27, 5, 18); + + //корпус военного корабля + Brush br = new SolidBrush(EntityWarship.BodyColor); + g.FillPolygon(br, FramePoints); + + //отсеки военного корабля + Brush brGray = new SolidBrush(Color.Gray); + g.FillRectangle(brGray, _startPosX.Value + 80, _startPosY.Value + 10, 15, 30); + g.FillRectangle(brGray, _startPosX.Value + 60, _startPosY.Value + 20, 20, 10); + g.FillEllipse(brGray, _startPosX.Value + 100, _startPosY.Value + 14, 20, 20); + + //выделяем рамкой отсеки военного корабля + g.DrawRectangle(pen, _startPosX.Value + 80, _startPosY.Value + 10, 15, 30); + g.DrawRectangle(pen, _startPosX.Value + 60, _startPosY.Value + 20, 20, 10); + g.DrawEllipse(pen, _startPosX.Value + 100, _startPosY.Value + 14, 20, 20); + + //двигатели военного корабля + Brush brBlack = new SolidBrush(Color.Black); + g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 5, 5, 18); + g.FillRectangle(brBlack, _startPosX.Value, _startPosY.Value + 27, 5, 18); + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityAircraftCarrier.cs similarity index 77% rename from ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs rename to ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityAircraftCarrier.cs index 18896d3..5253039 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/EntityAircraftCarrier.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityAircraftCarrier.cs @@ -1,25 +1,10 @@ -namespace ProjectAircraftCarrier; +namespace ProjectAircraftCarrier.Entities; /// /// Класс-сущность "Авианосец" /// -public class EntityAircraftCarrier +public class EntityAircraftCarrier : EntityWarship { - /// - /// Скорость - /// - public int Speed { get; private set; } - - /// - /// Вес - /// - public double Weight { get; private set; } - - /// - /// Основной цвет - /// - public Color BodyColor { get; private set; } - /// /// Дополнительный цвет (для опциональных элементов) /// @@ -51,9 +36,6 @@ public class EntityAircraftCarrier /// Признак наличия рубки управления public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool aircraftDeck, bool controlRoom) { - Speed = speed; - Weight = weight; - BodyColor = bodyColor; AdditionalColor = additionalColor; AircraftDeck = aircraftDeck; ControlRoom = controlRoom; diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityWarship.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityWarship.cs new file mode 100644 index 0000000..b3cc1d4 --- /dev/null +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/Entities/EntityWarship.cs @@ -0,0 +1,40 @@ +namespace ProjectAircraftCarrier.Entities; + +/// +/// Класс-сущность "Военный корабль" +/// +public class EntityWarship +{ + /// + /// Скорость + /// + public int Speed { get; private set; } + + /// + /// Вес + /// + public double Weight { get; private set; } + + /// + /// Основной цвет + /// + public Color BodyColor { get; private set; } + + /// + /// Шаг перемещения авианосца + /// + public double Step => Speed * 100 / Weight; + + /// + /// Конструктор сущности + /// + /// Скорость + /// Вес авианосца + /// Основной цвет + public EntityWarship(int speed, double weight, Color bodyColor) + { + Speed = speed; + Weight = weight; + BodyColor = bodyColor; + } +} diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs index f9ac235..1308807 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.Designer.cs @@ -29,11 +29,12 @@ private void InitializeComponent() { pictureBoxAircraftCarrier = new PictureBox(); - buttonCreate = new Button(); + buttonCreateAircraftCarrier = new Button(); buttonRight = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonLeft = new Button(); + buttonCreateWarship = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAircraftCarrier).BeginInit(); SuspendLayout(); // @@ -48,17 +49,17 @@ pictureBoxAircraftCarrier.TabIndex = 0; pictureBoxAircraftCarrier.TabStop = false; // - // buttonCreate + // buttonCreateAircraftCarrier // - buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreate.Location = new Point(14, 581); - buttonCreate.Margin = new Padding(3, 4, 3, 4); - buttonCreate.Name = "buttonCreate"; - buttonCreate.Size = new Size(86, 31); - buttonCreate.TabIndex = 1; - buttonCreate.Text = "создать"; - buttonCreate.UseVisualStyleBackColor = true; - buttonCreate.Click += buttonCreate_Click; + buttonCreateAircraftCarrier.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateAircraftCarrier.Location = new Point(14, 581); + buttonCreateAircraftCarrier.Margin = new Padding(3, 4, 3, 4); + buttonCreateAircraftCarrier.Name = "buttonCreateAircraftCarrier"; + buttonCreateAircraftCarrier.Size = new Size(188, 31); + buttonCreateAircraftCarrier.TabIndex = 1; + buttonCreateAircraftCarrier.Text = "Создать авианосец"; + buttonCreateAircraftCarrier.UseVisualStyleBackColor = true; + buttonCreateAircraftCarrier.Click += buttonCreate_Click; // // buttonRight // @@ -71,7 +72,7 @@ buttonRight.Size = new Size(30, 30); buttonRight.TabIndex = 2; buttonRight.UseVisualStyleBackColor = true; - buttonRight.Click += buttonMove_Click; + buttonRight.Click += ButtonMove_Click; // // buttonUp // @@ -84,7 +85,7 @@ buttonUp.Size = new Size(30, 30); buttonUp.TabIndex = 3; buttonUp.UseVisualStyleBackColor = true; - buttonUp.Click += buttonMove_Click; + buttonUp.Click += ButtonMove_Click; // // buttonDown // @@ -97,7 +98,7 @@ buttonDown.Size = new Size(30, 30); buttonDown.TabIndex = 4; buttonDown.UseVisualStyleBackColor = true; - buttonDown.Click += buttonMove_Click; + buttonDown.Click += ButtonMove_Click; // // buttonLeft // @@ -110,18 +111,31 @@ buttonLeft.Size = new Size(30, 30); buttonLeft.TabIndex = 5; buttonLeft.UseVisualStyleBackColor = true; - buttonLeft.Click += buttonMove_Click; + buttonLeft.Click += ButtonMove_Click; + // + // buttonCreateWarship + // + buttonCreateWarship.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + buttonCreateWarship.Location = new Point(208, 581); + buttonCreateWarship.Margin = new Padding(3, 4, 3, 4); + buttonCreateWarship.Name = "buttonCreateWarship"; + buttonCreateWarship.Size = new Size(208, 31); + buttonCreateWarship.TabIndex = 6; + buttonCreateWarship.Text = "Создать военный корабль"; + buttonCreateWarship.UseVisualStyleBackColor = true; + buttonCreateWarship.Click += ButtonCreateWarship_Click; // // FormAircraftCarrier // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(918, 628); + Controls.Add(buttonCreateWarship); Controls.Add(buttonLeft); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonRight); - Controls.Add(buttonCreate); + Controls.Add(buttonCreateAircraftCarrier); Controls.Add(pictureBoxAircraftCarrier); Margin = new Padding(3, 4, 3, 4); Name = "FormAircraftCarrier"; @@ -135,10 +149,11 @@ #endregion private PictureBox pictureBoxAircraftCarrier; - private Button buttonCreate; + private Button buttonCreateAircraftCarrier; private Button buttonRight; private Button buttonUp; private Button buttonDown; private Button buttonLeft; + private Button buttonCreateWarship; } } \ No newline at end of file diff --git a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs index e46f886..56376d7 100644 --- a/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs +++ b/ProjectAircraftCarrier/ProjectAircraftCarrier/FormAircraftCarrier.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; +using ProjectAircraftCarrier.Drawnings; namespace ProjectAircraftCarrier; @@ -18,7 +19,7 @@ public partial class FormAircraftCarrier : Form /// /// Поле-объект для прорисовки объекта /// - private DrawningAircraftCarrier? _drawningAircraftCarrier; + private DrawningWarship? _drawningWarship; /// /// Конструктор формы @@ -33,43 +34,63 @@ public partial class FormAircraftCarrier : Form /// private void Draw() { - if (_drawningAircraftCarrier == null) + if (_drawningWarship == null) { return; } Bitmap bmp = new(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); Graphics gr = Graphics.FromImage(bmp); - _drawningAircraftCarrier.DrawTransport(gr); + _drawningWarship.DrawTransport(gr); pictureBoxAircraftCarrier.Image = bmp; } - /// - /// Обработка нажатия кнопки "Создать" - /// - /// - /// - private void buttonCreate_Click(object sender, EventArgs e) + private void CreateObject(string type) { Random random = new(); - _drawningAircraftCarrier = new DrawningAircraftCarrier(); - _drawningAircraftCarrier.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))); - _drawningAircraftCarrier.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); - _drawningAircraftCarrier.SetPosition(random.Next(10, 100), random.Next(10, 100)); + switch (type) + { + case nameof(DrawningWarship): + _drawningWarship = new DrawningWarship(random.Next(100, 300), random.Next(1000, 3000), + Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256))); + break; + case nameof(DrawningAircraftCarrier): + _drawningWarship = new DrawningAircraftCarrier(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))); + break; + default: + return; + } + + _drawningWarship.SetPictureSize(pictureBoxAircraftCarrier.Width, pictureBoxAircraftCarrier.Height); + _drawningWarship.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } + /// + /// Обработка нажатия кнопки "Создать авианосец" + /// + /// + /// + private void ButtonCreateAircraftCarrier_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraftCarrier)); + + /// + /// Обработка нажатия кнопки "Создать военный корабль" + /// + /// + /// + private void ButtonCreateWarship_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarship)); + /// /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// - private void buttonMove_Click(object sender, EventArgs e) + private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawningAircraftCarrier == null) + if (_drawningWarship == null) { return; } @@ -79,16 +100,16 @@ public partial class FormAircraftCarrier : Form switch (name) { case "buttonUp": - result = _drawningAircraftCarrier.MoveTransport(DirectionType.Up); + result = _drawningWarship.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawningAircraftCarrier.MoveTransport(DirectionType.Down); + result = _drawningWarship.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawningAircraftCarrier.MoveTransport(DirectionType.Left); + result = _drawningWarship.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawningAircraftCarrier.MoveTransport(DirectionType.Right); + result = _drawningWarship.MoveTransport(DirectionType.Right); break; }