From b190f9518e3d73af22663e09203d90c744293c3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=94=D0=B0=D1=80=D1=8C=D1=8F=20=D0=90=D0=BD=D1=82=D0=BE?= =?UTF-8?q?=D0=BD=D0=BE=D0=B2=D0=B0?= Date: Fri, 16 Dec 2022 18:06:25 +0400 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 --- AirBomber/AirBomber/DrawningJet.cs | 29 +++++++++++++++++++++-------- AirBomber/AirBomber/EntityJet.cs | 2 +- AirBomber/AirBomber/WarJet.cs | 3 +-- 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/AirBomber/AirBomber/DrawningJet.cs b/AirBomber/AirBomber/DrawningJet.cs index 23f0567..f96ccb1 100644 --- a/AirBomber/AirBomber/DrawningJet.cs +++ b/AirBomber/AirBomber/DrawningJet.cs @@ -14,15 +14,15 @@ namespace AirBomber /// /// Класс-сущность /// - public EntityJet Jet { get; private set; } + public EntityJet Jet { get; protected set; } /// /// Левая координата отрисовки самолета /// - private float _startPosX; + protected float _startPosX; /// /// Верхняя кооридната отрисовки самолета /// - private float _startPosY; + protected float _startPosY; /// /// Ширина окна отрисовки /// @@ -45,10 +45,16 @@ namespace AirBomber /// Скорость /// Вес самолета /// Цвет самолета - public void Init(int speed, float weight, Color bodyColor) + public DrawningJet(int speed, float weight, Color bodyColor) { - Jet = new EntityJet(); - Jet.Init(speed, weight, bodyColor); + Jet = new EntityJet(speed, weight, bodyColor); + } + + protected DrawningJet(int speed, float weight, Color bodyColor, int jetWidth, int jetHeight) : + this(speed, weight, bodyColor) + { + _jetWidth = jetWidth; + _jetHeight = jetHeight; } /// /// Установка позиции самолета @@ -58,7 +64,7 @@ namespace AirBomber /// Ширина картинки /// Высота картинки - public void SetPosition(int x, int y, int width, int height) + public virtual void SetPosition(int x, int y, int width, int height) { if (x < 0 || y < 0 || width < x + _jetWidth || height < y + _jetHeight) { @@ -122,7 +128,7 @@ namespace AirBomber /// Отрисовка самолета /// /// - public void DrawTransport(Graphics g) + public virtual void DrawTransport(Graphics g) { if (_startPosX < 0 || _startPosY < 0 || !_pictureHeight.HasValue || !_pictureWidth.HasValue) @@ -202,5 +208,12 @@ namespace AirBomber _startPosY = _pictureHeight.Value - _jetHeight; } } + /// + /// Получение текущей позиции + /// + public (float Left, float Right, float Top, float Bottom) GetCurrentPosition() + { + return (_startPosX, _startPosY, _startPosX + _jetWidth, _startPosY + _jetHeight); + } } } diff --git a/AirBomber/AirBomber/EntityJet.cs b/AirBomber/AirBomber/EntityJet.cs index 02dd8b6..f713d10 100644 --- a/AirBomber/AirBomber/EntityJet.cs +++ b/AirBomber/AirBomber/EntityJet.cs @@ -35,7 +35,7 @@ namespace AirBomber /// /// - public void Init(int speed, float weight, Color bodyColor) + public EntityJet(int speed, float weight, Color bodyColor) { Random rnd = new Random(); Speed = speed <= 0 ? rnd.Next(50, 150) : speed; diff --git a/AirBomber/AirBomber/WarJet.cs b/AirBomber/AirBomber/WarJet.cs index ca69f50..9f2fd7d 100644 --- a/AirBomber/AirBomber/WarJet.cs +++ b/AirBomber/AirBomber/WarJet.cs @@ -57,8 +57,7 @@ namespace AirBomber private void buttonCreate_Click(object sender, EventArgs e) { Random rnd = new Random(); - _jet = new DrawningJet(); - _jet.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _jet = new DrawningJet(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); _jet.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxCar.Width, pictureBoxCar.Height); toolStripStatusLabelSpeed.Text = $": {_jet.Jet.Speed}"; toolStripStatusLabelWeight.Text = $": {_jet.Jet.Weight}";