LabWork01
This commit is contained in:
parent
f81a857f68
commit
dd086e5c0b
@ -11,7 +11,7 @@ namespace Airbus
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityPlane Airbus { get; private set; }
|
||||
public EntityPlane Plane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата отрисовки самолета
|
||||
@ -34,20 +34,21 @@ namespace Airbus
|
||||
/// <summary>
|
||||
/// Ширина отрисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _AirbusWidth = 130;
|
||||
private readonly int _PlaneWidth = 130;
|
||||
/// <summary>
|
||||
/// Высота отрисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _AirbusHeight = 70;
|
||||
private readonly int _PlaneHeight = 70;
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес самолета</param>
|
||||
/// <param name="bodyColor">Цвет кузова</param>
|
||||
public void Init(EntityPlane Airbus)
|
||||
public void Init(int speed, float weight, Color bodyColor)
|
||||
{
|
||||
this.Airbus = Airbus;
|
||||
Plane = new EntityPlane();
|
||||
Plane.Init(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Установка позиции самолета
|
||||
@ -58,7 +59,7 @@ namespace Airbus
|
||||
/// <param name="height">Высота картинки</param>
|
||||
public void SetPosition(int x, int y, int width, int height)
|
||||
{
|
||||
if (x >= 0 && x + _AirbusWidth <= width && y >= 0 && y + _AirbusHeight <= height)
|
||||
if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height)
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
@ -81,30 +82,30 @@ namespace Airbus
|
||||
{
|
||||
// вправо
|
||||
case Direction.Right:
|
||||
if (_startPosX + _AirbusWidth + Airbus.Step < _pictureWidth)
|
||||
if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth)
|
||||
{
|
||||
_startPosX += Airbus.Step;
|
||||
_startPosX += Plane.Step;
|
||||
}
|
||||
break;
|
||||
//влево
|
||||
case Direction.Left:
|
||||
if (_startPosX - Airbus.Step > 0)
|
||||
if (_startPosX - Plane.Step > 0)
|
||||
{
|
||||
_startPosX -= Airbus.Step;
|
||||
_startPosX -= Plane.Step;
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Direction.Up:
|
||||
if (_startPosY - Airbus.Step > 0)
|
||||
if (_startPosY - Plane.Step > 0)
|
||||
{
|
||||
_startPosY -= Airbus.Step;
|
||||
_startPosY -= Plane.Step;
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Direction.Down:
|
||||
if (_startPosY + _AirbusHeight + Airbus.Step < _pictureHeight)
|
||||
if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight)
|
||||
{
|
||||
_startPosY += Airbus.Step;
|
||||
_startPosY += Plane.Step;
|
||||
}
|
||||
break;
|
||||
}
|
||||
@ -140,7 +141,7 @@ namespace Airbus
|
||||
g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10);
|
||||
g.DrawEllipse(pen, _startPosX + 41, _startPosY + 55, 10, 10);
|
||||
|
||||
Brush br = new SolidBrush(Airbus?.BodyColor ?? Color.Black);
|
||||
Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black);
|
||||
g.FillEllipse(br, _startPosX, _startPosY + 31, 20, 19);
|
||||
g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19);
|
||||
|
||||
@ -158,19 +159,19 @@ namespace Airbus
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_pictureWidth <= _AirbusWidth || _pictureHeight <= _AirbusHeight)
|
||||
if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight)
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
return;
|
||||
}
|
||||
if (_startPosX + _AirbusWidth > _pictureWidth)
|
||||
if (_startPosX + _PlaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth.Value - _AirbusWidth;
|
||||
_startPosX = _pictureWidth.Value - _PlaneWidth;
|
||||
}
|
||||
if (_startPosY + _AirbusHeight > _pictureHeight)
|
||||
if (_startPosY + _PlaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight.Value - _AirbusHeight;
|
||||
_startPosY = _pictureHeight.Value - _PlaneHeight;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,7 @@ namespace Airbus
|
||||
{
|
||||
public partial class FormPlane : Form
|
||||
{
|
||||
private DrawningPlane _airbus;
|
||||
private DrawningPlane _plane;
|
||||
|
||||
public FormPlane()
|
||||
{
|
||||
@ -25,7 +25,7 @@ namespace Airbus
|
||||
{
|
||||
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_airbus?.DrawTransport(gr);
|
||||
_plane?.DrawTransport(gr);
|
||||
pictureBoxAirbus.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
@ -35,15 +35,14 @@ namespace Airbus
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
Random rnd = new();
|
||||
_airbus = new DrawningPlane();
|
||||
EntityPlane Airbus = new EntityPlane();
|
||||
Airbus.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_airbus.Init(Airbus);
|
||||
_airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_airbus.Airbus.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_airbus.Airbus.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_airbus.Airbus.BodyColor.Name}";
|
||||
_plane = new DrawningPlane();
|
||||
_plane.Init(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
|
||||
_plane.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
|
||||
toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
|
||||
toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
@ -58,16 +57,16 @@ namespace Airbus
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
_airbus?.MoveTransport(Direction.Up);
|
||||
_plane?.MoveTransport(Direction.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
_airbus?.MoveTransport(Direction.Down);
|
||||
_plane?.MoveTransport(Direction.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
_airbus?.MoveTransport(Direction.Left);
|
||||
_plane?.MoveTransport(Direction.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
_airbus?.MoveTransport(Direction.Right);
|
||||
_plane?.MoveTransport(Direction.Right);
|
||||
break;
|
||||
}
|
||||
Draw();
|
||||
@ -79,7 +78,7 @@ namespace Airbus
|
||||
/// <param name="e"></param>
|
||||
private void PictureBoxAirbus_Resize(object sender, EventArgs e)
|
||||
{
|
||||
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
_plane?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
|
||||
Draw();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user