From 08b6b36d26426ad91287c986c90933bdf0604808 Mon Sep 17 00:00:00 2001 From: "A.Novopoltsev" Date: Mon, 21 Nov 2022 20:08:48 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4=20?= =?UTF-8?q?=D0=BD=D0=B0=20=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D1=83=D0=BA?= =?UTF-8?q?=D1=82=D0=BE=D1=80=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Warship/Warship/DrawningShip.cs | 36 ++++++++++++++++++++++++--------- Warship/Warship/EntityShip.cs | 4 ++-- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/Warship/Warship/DrawningShip.cs b/Warship/Warship/DrawningShip.cs index e20169c..541f7bb 100644 --- a/Warship/Warship/DrawningShip.cs +++ b/Warship/Warship/DrawningShip.cs @@ -7,20 +7,20 @@ using System.Threading.Tasks; namespace Warship { - internal class DrawningShip + public class DrawningShip { /// /// Класс-сущность /// - public EntityShip Ship { private set; get; } + public EntityShip Ship { protected set; get; } /// /// Левая координата отрисовки лодки /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки лодки /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -32,7 +32,7 @@ namespace Warship /// /// Ширина отрисовки лодки /// - private readonly int _shipWidth = 120; + private readonly int _shipWidth = 125; /// /// Высота отрисовки лодки /// @@ -43,10 +43,14 @@ namespace Warship /// Скорость /// Вес лодки /// Цвет кузова - public void Init(int speed, float weight, Color bodyColor) + public DrawningShip(int speed, float weight, Color bodyColor) { - Ship = new EntityShip(); - Ship.Init(speed, weight, bodyColor); + Ship = new EntityShip(speed, weight, bodyColor); + } + protected DrawningShip(int speed, float weight, Color bodyColor, int shipWight, int shipHeight) : this(speed, weight, bodyColor) + { + _shipWidth = shipWight; + _shipHeight = shipHeight; } /// /// Установка позиции корабля @@ -111,8 +115,17 @@ namespace Warship break; } } + + public bool DrawCheck() + { + if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) + { + return false; + } + return true; + } /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -165,5 +178,10 @@ namespace Warship _startPosY = _pictureHeight.Value - _shipHeight; } } + + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _shipWidth, _startPosY + _shipHeight); + } } } diff --git a/Warship/Warship/EntityShip.cs b/Warship/Warship/EntityShip.cs index ca5df94..4f04bc3 100644 --- a/Warship/Warship/EntityShip.cs +++ b/Warship/Warship/EntityShip.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace Warship { - internal class EntityShip + public class EntityShip { /// @@ -32,7 +32,7 @@ namespace Warship /// /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityShip(int speed, float weight, Color bodyColor) { Random rnd = new(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed;