LabWork01

This commit is contained in:
ArtemEmelyanov 2022-10-15 18:37:59 +04:00
parent f81a857f68
commit dd086e5c0b
2 changed files with 35 additions and 35 deletions

View File

@ -11,7 +11,7 @@ namespace Airbus
/// <summary> /// <summary>
/// Класс-сущность /// Класс-сущность
/// </summary> /// </summary>
public EntityPlane Airbus { get; private set; } public EntityPlane Plane { get; private set; }
/// <summary> /// <summary>
/// Левая координата отрисовки самолета /// Левая координата отрисовки самолета
@ -34,20 +34,21 @@ namespace Airbus
/// <summary> /// <summary>
/// Ширина отрисовки самолета /// Ширина отрисовки самолета
/// </summary> /// </summary>
private readonly int _AirbusWidth = 130; private readonly int _PlaneWidth = 130;
/// <summary> /// <summary>
/// Высота отрисовки самолета /// Высота отрисовки самолета
/// </summary> /// </summary>
private readonly int _AirbusHeight = 70; private readonly int _PlaneHeight = 70;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
/// <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(EntityPlane Airbus) public void Init(int speed, float weight, Color bodyColor)
{ {
this.Airbus = Airbus; Plane = new EntityPlane();
Plane.Init(speed, weight, bodyColor);
} }
/// <summary> /// <summary>
/// Установка позиции самолета /// Установка позиции самолета
@ -58,7 +59,7 @@ namespace Airbus
/// <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 && x + _AirbusWidth <= width && y >= 0 && y + _AirbusHeight <= height) if (x >= 0 && x + _PlaneWidth <= width && y >= 0 && y + _PlaneHeight <= height)
{ {
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
@ -81,30 +82,30 @@ namespace Airbus
{ {
// вправо // вправо
case Direction.Right: case Direction.Right:
if (_startPosX + _AirbusWidth + Airbus.Step < _pictureWidth) if (_startPosX + _PlaneWidth + Plane.Step < _pictureWidth)
{ {
_startPosX += Airbus.Step; _startPosX += Plane.Step;
} }
break; break;
//влево //влево
case Direction.Left: case Direction.Left:
if (_startPosX - Airbus.Step > 0) if (_startPosX - Plane.Step > 0)
{ {
_startPosX -= Airbus.Step; _startPosX -= Plane.Step;
} }
break; break;
//вверх //вверх
case Direction.Up: case Direction.Up:
if (_startPosY - Airbus.Step > 0) if (_startPosY - Plane.Step > 0)
{ {
_startPosY -= Airbus.Step; _startPosY -= Plane.Step;
} }
break; break;
//вниз //вниз
case Direction.Down: case Direction.Down:
if (_startPosY + _AirbusHeight + Airbus.Step < _pictureHeight) if (_startPosY + _PlaneHeight + Plane.Step < _pictureHeight)
{ {
_startPosY += Airbus.Step; _startPosY += Plane.Step;
} }
break; break;
} }
@ -140,7 +141,7 @@ namespace Airbus
g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10); g.DrawEllipse(pen, _startPosX + 29, _startPosY + 55, 10, 10);
g.DrawEllipse(pen, _startPosX + 41, _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.FillEllipse(br, _startPosX, _startPosY + 31, 20, 19);
g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19); g.FillRectangle(br, _startPosX + 10, _startPosY + 31, 100, 19);
@ -158,19 +159,19 @@ namespace Airbus
{ {
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
if (_pictureWidth <= _AirbusWidth || _pictureHeight <= _AirbusHeight) if (_pictureWidth <= _PlaneWidth || _pictureHeight <= _PlaneHeight)
{ {
_pictureWidth = null; _pictureWidth = null;
_pictureHeight = null; _pictureHeight = null;
return; 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;
} }
} }
} }

View File

@ -12,7 +12,7 @@ namespace Airbus
{ {
public partial class FormPlane : Form public partial class FormPlane : Form
{ {
private DrawningPlane _airbus; private DrawningPlane _plane;
public FormPlane() public FormPlane()
{ {
@ -25,7 +25,7 @@ namespace Airbus
{ {
Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height); Bitmap bmp = new(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
Graphics gr = Graphics.FromImage(bmp); Graphics gr = Graphics.FromImage(bmp);
_airbus?.DrawTransport(gr); _plane?.DrawTransport(gr);
pictureBoxAirbus.Image = bmp; pictureBoxAirbus.Image = bmp;
} }
/// <summary> /// <summary>
@ -35,15 +35,14 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void ButtonCreate_Click(object sender, EventArgs e) private void ButtonCreate_Click(object sender, EventArgs e)
{ {
Random rnd = new(); Random rnd = new();
_airbus = new DrawningPlane(); _plane = new DrawningPlane();
EntityPlane Airbus = new EntityPlane(); _plane.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(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);
_airbus.Init(Airbus); toolStripStatusLabelSpeed.Text = $"Скорость: {_plane.Plane.Speed}";
_airbus.SetPosition(rnd.Next(10, 100), rnd.Next(10, 100), pictureBoxAirbus.Width, pictureBoxAirbus.Height); toolStripStatusLabelWeight.Text = $"Вес: {_plane.Plane.Weight}";
toolStripStatusLabelSpeed.Text = $"Скорость: {_airbus.Airbus.Speed}"; toolStripStatusLabelBodyColor.Text = $"Цвет: {_plane.Plane.BodyColor.Name}";
toolStripStatusLabelWeight.Text = $"Вес: {_airbus.Airbus.Weight}";
toolStripStatusLabelBodyColor.Text = $"Цвет: {_airbus.Airbus.BodyColor.Name}";
Draw(); Draw();
} }
/// <summary> /// <summary>
@ -58,16 +57,16 @@ namespace Airbus
switch (name) switch (name)
{ {
case "buttonUp": case "buttonUp":
_airbus?.MoveTransport(Direction.Up); _plane?.MoveTransport(Direction.Up);
break; break;
case "buttonDown": case "buttonDown":
_airbus?.MoveTransport(Direction.Down); _plane?.MoveTransport(Direction.Down);
break; break;
case "buttonLeft": case "buttonLeft":
_airbus?.MoveTransport(Direction.Left); _plane?.MoveTransport(Direction.Left);
break; break;
case "buttonRight": case "buttonRight":
_airbus?.MoveTransport(Direction.Right); _plane?.MoveTransport(Direction.Right);
break; break;
} }
Draw(); Draw();
@ -79,7 +78,7 @@ namespace Airbus
/// <param name="e"></param> /// <param name="e"></param>
private void PictureBoxAirbus_Resize(object sender, EventArgs e) private void PictureBoxAirbus_Resize(object sender, EventArgs e)
{ {
_airbus?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height); _plane?.ChangeBorders(pictureBoxAirbus.Width, pictureBoxAirbus.Height);
Draw(); Draw();
} }