From f0e50f2758d6f597ca9af0f15885287c7807a9de Mon Sep 17 00:00:00 2001 From: Danil Kargin Date: Wed, 5 Oct 2022 21:13:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9F=D1=80=D0=B0=D0=B2=D0=BA=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- AirFighter/AirFighter/DrawningAirFighter.cs | 42 +++++++++------------ AirFighter/AirFighter/FormAirFighter.cs | 8 ++-- 2 files changed, 20 insertions(+), 30 deletions(-) diff --git a/AirFighter/AirFighter/DrawningAirFighter.cs b/AirFighter/AirFighter/DrawningAirFighter.cs index f601cda..de9b72e 100644 --- a/AirFighter/AirFighter/DrawningAirFighter.cs +++ b/AirFighter/AirFighter/DrawningAirFighter.cs @@ -45,10 +45,9 @@ namespace AirFighter /// Скорость /// Вес самолета /// Цвет кузова - public void Init(int speed, float weight, Color bodyColor) + public void Init(EntityAirFighter _entityAirFighter) { - AirFighter = new EntityAirFighter(); - AirFighter.Init(speed, weight, bodyColor); + AirFighter = _entityAirFighter; } /// /// Установка позиции самолета @@ -58,33 +57,26 @@ namespace AirFighter /// Ширина картинки /// Высота картинки public void SetPosition(int x, int y, int width, int height) - { - if (x < 0) - { - x = 10; - } - if (y < 0) - { - y = 10; - } - if (width < 0) - { - width = 700; - } - if (height < 0) - { - height = 400; - } - if (x + _airFighterWidth > width && y + _airFighterHeight > height) + { + if(width < _airFighterWidth || height < _airFighterHeight) { _pictureWidth = null; _pictureHeight = null; return; } - _startPosX = x; - _startPosY = y; - _pictureWidth = width; - _pictureHeight = height; + if(x < 0 || x + _airFighterWidth > width) + { + x = width - _airFighterWidth; + } + if(y < 0 || y + _airFighterHeight > height) + { + y = height - _airFighterHeight; + } + + _startPosX = x; + _startPosY = y; + _pictureWidth = width; + _pictureHeight = height; } /// /// Изменение направления перемещения diff --git a/AirFighter/AirFighter/FormAirFighter.cs b/AirFighter/AirFighter/FormAirFighter.cs index 0ac2d98..cc76b1a 100644 --- a/AirFighter/AirFighter/FormAirFighter.cs +++ b/AirFighter/AirFighter/FormAirFighter.cs @@ -12,10 +12,6 @@ namespace AirFighter /// private void Draw() { - if (pictureBoxAirFighter.Height <= 0 || pictureBoxAirFighter.Width <= 0) - { - return; - } Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Graphics g = Graphics.FromImage(bmp); _airFighter?.DrawAirFighter(g); @@ -30,7 +26,9 @@ namespace AirFighter { _airFighter = new DrawningAirFighter(); Random rnd = new Random(); - _airFighter.Init(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + EntityAirFighter entityAirFighter = new EntityAirFighter(); + entityAirFighter?.Init(rnd.Next(200, 500), rnd.Next(2000, 5000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256))); + _airFighter.Init(entityAirFighter); _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); toolStripStatusLabelSpeed.Text = $": {_airFighter.AirFighter?.Speed}"; toolStripStatusLabelWeight.Text = $": {_airFighter.AirFighter?.Weight}";