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}";