Правки
This commit is contained in:
parent
0a2b26ea0e
commit
f0e50f2758
@ -45,10 +45,9 @@ namespace AirFighter
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
public void Init(EntityAirFighter _entityAirFighter)
|
||||
{
|
||||
AirFighter = new EntityAirFighter();
|
||||
AirFighter.Init(speed, weight, bodyColor);
|
||||
AirFighter = _entityAirFighter;
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
@ -59,32 +58,25 @@ namespace AirFighter
|
||||
/// <param name="height">Высота картинки</param>
|
||||
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;
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
|
@ -12,10 +12,6 @@ namespace AirFighter
|
||||
/// </summary>
|
||||
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}";
|
||||
|
Loading…
Reference in New Issue
Block a user