Правки

This commit is contained in:
Danil Kargin 2022-10-05 21:13:23 +04:00
parent 0a2b26ea0e
commit f0e50f2758
2 changed files with 20 additions and 30 deletions

View File

@ -45,10 +45,9 @@ namespace AirFighter
/// <param name="speed">Скорость</param> /// <param name="speed">Скорость</param>
/// <param name="weight">Вес самолета</param> /// <param name="weight">Вес самолета</param>
/// <param name="bodyColor">Цвет кузова</param> /// <param name="bodyColor">Цвет кузова</param>
public void Init(int speed, float weight, Color bodyColor) public void Init(EntityAirFighter _entityAirFighter)
{ {
AirFighter = new EntityAirFighter(); AirFighter = _entityAirFighter;
AirFighter.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции самолета /// Установка позиции самолета
@ -59,28 +58,21 @@ namespace AirFighter
/// <param name="height">Высота картинки</param> /// <param name="height">Высота картинки</param>
public void SetPosition(int x, int y, int width, int height) public void SetPosition(int x, int y, int width, int height)
{ {
if (x < 0) if(width < _airFighterWidth || height < _airFighterHeight)
{
x = 10;
}
if (y < 0)
{
y = 10;
}
if (width < 0)
{
width = 700;
}
if (height < 0)
{
height = 400;
}
if (x + _airFighterWidth > width && y + _airFighterHeight > height)
{ {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
return; return;
} }
if(x < 0 || x + _airFighterWidth > width)
{
x = width - _airFighterWidth;
}
if(y < 0 || y + _airFighterHeight > height)
{
y = height - _airFighterHeight;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
_pictureWidth = width; _pictureWidth = width;

View File

@ -12,10 +12,6 @@ namespace AirFighter
/// </summary> /// </summary>
private void Draw() private void Draw()
{ {
if (pictureBoxAirFighter.Height <= 0 || pictureBoxAirFighter.Width <= 0)
{
return;
}
Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height); Bitmap bmp = new(pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
Graphics g = Graphics.FromImage(bmp); Graphics g = Graphics.FromImage(bmp);
_airFighter?.DrawAirFighter(g); _airFighter?.DrawAirFighter(g);
@ -30,7 +26,9 @@ namespace AirFighter
{ {
_airFighter = new DrawningAirFighter(); _airFighter = new DrawningAirFighter();
Random rnd = new Random(); 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); _airFighter.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirFighter.Width, pictureBoxAirFighter.Height);
toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}"; toolStripStatusLabelSpeed.Text = $"Ñêîðîñòü: {_airFighter.AirFighter?.Speed}";
toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}"; toolStripStatusLabelWeight.Text = $"Âåñ: {_airFighter.AirFighter?.Weight}";