Лабораторная работа 1 - готовый вариант

This commit is contained in:
devil_1nc 2022-09-27 16:31:03 +04:00
parent b66671fd10
commit d8c21ff0a4

View File

@ -36,15 +36,7 @@ namespace ProjectPlane
/// <summary> /// <summary>
/// Высота отрисовки самолета /// Высота отрисовки самолета
/// </summary> /// </summary>
private readonly int _planeHeight = 50; private readonly int _planeHeight = 80;
/// <summary>
/// Левый край
/// </summary>
private readonly int _minX = 5;
/// <summary>
/// Верхний край
/// </summary>
private readonly int _minY = 40;
/// <summary> /// <summary>
/// Инициализация свойств /// Инициализация свойств
/// </summary> /// </summary>
@ -65,15 +57,19 @@ namespace ProjectPlane
/// <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 >= _minX && x <= width && y >= _minY && y <= height) if (x < 0 || x + _planeWidth >= width)
{ {
return;
}
if (y < 0 || y + _planeHeight >= height)
{
return;
}
_startPosX = x; _startPosX = x;
_startPosY = y; _startPosY = y;
_pictureWidth = width; _pictureWidth = width;
_pictureHeight = height; _pictureHeight = height;
} }
else SetPosition(_minX, _minY, width, height);
}
/// <summary> /// <summary>
/// Изменение направления пермещения /// Изменение направления пермещения
/// </summary> /// </summary>
@ -102,12 +98,12 @@ namespace ProjectPlane
break; break;
//вверх //вверх
case Direction.Up: case Direction.Up:
if (_startPosY - Plane.Step > 35) if (_startPosY - Plane.Step > 0)
{ {
_startPosY -= Plane.Step; _startPosY -= Plane.Step;
} }
break; break;
break;
//вниз //вниз
case Direction.Down: case Direction.Down:
if (_startPosY + _planeHeight + Plane.Step < _pictureHeight) if (_startPosY + _planeHeight + Plane.Step < _pictureHeight)
@ -131,46 +127,46 @@ namespace ProjectPlane
//границы самолета //границы самолета
Pen pen = new(Color.Black); Pen pen = new(Color.Black);
g.DrawEllipse(pen, _startPosX, _startPosY, 20, 20); g.DrawEllipse(pen, _startPosX, _startPosY + 20, 20, 20);
g.DrawRectangle(pen, _startPosX + 8, _startPosY, 100, 20); g.DrawRectangle(pen, _startPosX + 8, _startPosY + 20, 100, 20);
Point[] Triangle0 = new Point[3]; Point[] Triangle0 = new Point[3];
Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY - 2); Triangle0[0].X = Convert.ToInt32(_startPosX + 108); Triangle0[0].Y = Convert.ToInt32(_startPosY + 18);
Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 10); Triangle0[1].X = Convert.ToInt32(_startPosX + 125); Triangle0[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 10); Triangle0[2].X = Convert.ToInt32(_startPosX + 108); Triangle0[2].Y = Convert.ToInt32(_startPosY + 30);
g.DrawPolygon(pen, Triangle0); g.DrawPolygon(pen, Triangle0);
Point[] Triangle1 = new Point[3]; Point[] Triangle1 = new Point[3];
Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 10); Triangle1[0].X = Convert.ToInt32(_startPosX + 108); Triangle1[0].Y = Convert.ToInt32(_startPosY + 30);
Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 10); Triangle1[1].X = Convert.ToInt32(_startPosX + 125); Triangle1[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 22); Triangle1[2].X = Convert.ToInt32(_startPosX + 108); Triangle1[2].Y = Convert.ToInt32(_startPosY + 42);
g.DrawPolygon(pen, Triangle1); g.DrawPolygon(pen, Triangle1);
Point[] Triangle = new Point[3]; Point[] Triangle = new Point[3];
Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY); Triangle[0].X = Convert.ToInt32(_startPosX + 5); Triangle[0].Y = Convert.ToInt32(_startPosY + 20);
Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY - 20); Triangle[1].X = Convert.ToInt32(_startPosX + 5); Triangle[1].Y = Convert.ToInt32(_startPosY);
Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY); Triangle[2].X = Convert.ToInt32(_startPosX + 35); Triangle[2].Y = Convert.ToInt32(_startPosY + 20);
g.DrawPolygon(pen, Triangle); g.DrawPolygon(pen, Triangle);
////корпус ////корпус
Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black); Brush br = new SolidBrush(Plane?.BodyColor ?? Color.Black);
g.FillEllipse(br, _startPosX, _startPosY, 20, 20); g.FillEllipse(br, _startPosX, _startPosY + 20, 20, 20);
g.FillRectangle(br, _startPosX + 8, _startPosY, 100, 20); g.FillRectangle(br, _startPosX + 8, _startPosY + 20, 100, 20);
Point[] Triangle2 = new Point[3]; Point[] Triangle2 = new Point[3];
Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY); Triangle2[0].X = Convert.ToInt32(_startPosX + 5); Triangle2[0].Y = Convert.ToInt32(_startPosY + 20);
Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY - 20); Triangle2[1].X = Convert.ToInt32(_startPosX + 5); Triangle2[1].Y = Convert.ToInt32(_startPosY); //the highest point
Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY); Triangle2[2].X = Convert.ToInt32(_startPosX + 35); Triangle2[2].Y = Convert.ToInt32(_startPosY + 20);
g.FillPolygon(br, Triangle2); g.FillPolygon(br, Triangle2);
Point[] Triangle4 = new Point[3]; Point[] Triangle4 = new Point[3];
Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 10); Triangle4[0].X = Convert.ToInt32(_startPosX + 108); Triangle4[0].Y = Convert.ToInt32(_startPosY + 30);
Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 10); Triangle4[1].X = Convert.ToInt32(_startPosX + 125); Triangle4[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 22); Triangle4[2].X = Convert.ToInt32(_startPosX + 108); Triangle4[2].Y = Convert.ToInt32(_startPosY + 42);
g.FillPolygon(br, Triangle4); g.FillPolygon(br, Triangle4);
// window // window
@ -179,26 +175,26 @@ namespace ProjectPlane
Brush brBlack = new SolidBrush(Color.Black); Brush brBlack = new SolidBrush(Color.Black);
Point[] Triangle3 = new Point[3]; Point[] Triangle3 = new Point[3];
Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY - 2); Triangle3[0].X = Convert.ToInt32(_startPosX + 108); Triangle3[0].Y = Convert.ToInt32(_startPosY + 18);
Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 10); Triangle3[1].X = Convert.ToInt32(_startPosX + 125); Triangle3[1].Y = Convert.ToInt32(_startPosY + 30);
Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 10); Triangle3[2].X = Convert.ToInt32(_startPosX + 108); Triangle3[2].Y = Convert.ToInt32(_startPosY + 30);
g.FillPolygon(brBlue, Triangle3); g.FillPolygon(brBlue, Triangle3);
g.DrawLine(pen, _startPosX + 37, _startPosY + 20, _startPosX + 37, _startPosY + 25); g.DrawLine(pen, _startPosX + 37, _startPosY + 40, _startPosX + 37, _startPosY + 45);
g.DrawLine(pen, _startPosX + 32, _startPosY + 25, _startPosX + 40, _startPosY + 25); g.DrawLine(pen, _startPosX + 32, _startPosY + 45, _startPosX + 40, _startPosY + 45);
g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 32, _startPosY + 45, 3, 3);
g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 39, _startPosY + 45, 3, 3);
g.DrawLine(pen, _startPosX + 102, _startPosY + 20, _startPosX + 102, _startPosY + 25); g.DrawLine(pen, _startPosX + 102, _startPosY + 40, _startPosX + 102, _startPosY + 45);
g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 25, 3, 3); g.FillRectangle(brBlack, _startPosX + 101, _startPosY + 45, 3, 3);
g.FillRectangle(brBlack, _startPosX + 5, _startPosY - 2, 18, 7); g.FillRectangle(brBlack, _startPosX + 5, _startPosY + 18, 18, 7);
g.FillEllipse(brBlack, _startPosX, _startPosY - 2, 7, 7); g.FillEllipse(brBlack, _startPosX, _startPosY + 18, 7, 7);
g.FillEllipse(brBlack, _startPosX + 20, _startPosY - 2, 7, 7); g.FillEllipse(brBlack, _startPosX + 20, _startPosY + 18, 7, 7);
g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 8, 42, 4); g.FillRectangle(brBlack, _startPosX + 41, _startPosY + 28, 42, 4);
g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 8, 4, 4); g.FillEllipse(brBlack, _startPosX + 39, _startPosY + 28, 4, 4);
g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 8, 4, 4); g.FillEllipse(brBlack, _startPosX + 81, _startPosY + 28, 4, 4);
} }
/// <summary> /// <summary>
/// Смена границ формы отрисовки /// Смена границ формы отрисовки