Первая часть Lab02
This commit is contained in:
commit
2ff4ee77d3
@ -1,4 +1,4 @@
|
||||
namespace ProjectSeaplane;
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
@ -7,24 +7,24 @@ public enum DirectionType
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
|
||||
|
||||
Up = 1,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
|
||||
|
||||
Down = 2,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
|
||||
/// Влево
|
||||
/// </summary>
|
||||
|
||||
Left = 3,
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
|
||||
Right = 4,
|
||||
}
|
@ -0,0 +1,261 @@
|
||||
using ProjectSeaplane.Entities;
|
||||
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
|
||||
public class DrawingBasicSeaplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBasicSeaplane? EntityBasicSeaplane { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneWidth = 155;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
EntityBasicSeaplane = new EntityBasicSeaplane(speed, weight, bodyColor);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта, если она была уже установлена
|
||||
|
||||
if (_drawningSeaplaneWidth < width && _drawningSeaplaneHeight < height)
|
||||
{
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
if (_startPosX != null && _startPosY != null)
|
||||
{
|
||||
if (_startPosX + _drawningSeaplaneWidth > width)
|
||||
{
|
||||
_startPosX = width - (_drawningSeaplaneWidth + 1);
|
||||
|
||||
}
|
||||
if (_startPosY + _drawningSeaplaneWidth > height)
|
||||
{
|
||||
_startPosY = height - (_drawningSeaplaneHeight + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка позиции
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (!_pictureHeight.HasValue || !_pictureWidth.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO если при установке объекта в эти координаты, он будет "выходить" за границы формы
|
||||
// то надо изменить координаты, чтобы он оставался в этих границах
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
|
||||
if (_startPosX < 0)
|
||||
{
|
||||
_startPosX = 0;
|
||||
}
|
||||
if (_startPosY < 0)
|
||||
{
|
||||
_startPosY = 0;
|
||||
}
|
||||
if (_startPosX + _drawningSeaplaneWidth > _pictureWidth)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningSeaplaneWidth;
|
||||
}
|
||||
if (_startPosY - _drawningSeaplaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosY = _pictureHeight - _drawningSeaplaneHeight;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBasicSeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBasicSeaplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBasicSeaplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
|
||||
if (_startPosX + (int)EntityBasicSeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
|
||||
if (_startPosY + (int)EntityBasicSeaplane.Step < _pictureHeight - _drawningSeaplaneHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBasicSeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Pen penKraya = new(Color.Black, 2);
|
||||
|
||||
|
||||
|
||||
//Начинаем рисовать
|
||||
|
||||
|
||||
|
||||
//Полигон для хвоста
|
||||
Point point1 = new Point(_startPosX.Value, _startPosY.Value);
|
||||
Point point2 = new Point(_startPosX.Value + 35, _startPosY.Value + 35);
|
||||
Point point3 = new Point(_startPosX.Value, _startPosY.Value + 35);
|
||||
Point point4 = new Point(_startPosX.Value, _startPosY.Value);
|
||||
Point[] Hvost =
|
||||
{
|
||||
point1, point2 , point3 , point4
|
||||
};
|
||||
Point point5 = new Point(_startPosX.Value + 50, _startPosY.Value + 22);
|
||||
Point point6 = new Point(_startPosX.Value + 45, _startPosY.Value + 30);
|
||||
Point point7 = new Point(_startPosX.Value + 55, _startPosY.Value + 30);
|
||||
Point point8 = new Point(_startPosX.Value + 50, _startPosY.Value + 22);
|
||||
Point[] Radar =
|
||||
{
|
||||
point5, point6 , point7 , point8
|
||||
};
|
||||
|
||||
//Кисти для основного цвета и дополнительного
|
||||
Brush brBody = new SolidBrush(EntityBasicSeaplane.BodyColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
Brush brWhity = new SolidBrush(Color.GhostWhite);
|
||||
//Хвост
|
||||
g.FillPolygon(brBody, Hvost);
|
||||
//Тело
|
||||
|
||||
|
||||
g.FillRectangle(brBody, _startPosX.Value + 30, _startPosY.Value + 30, 85, 25);
|
||||
|
||||
|
||||
g.FillEllipse(brBody, _startPosX.Value + 45, _startPosY.Value + 30, 110, 24);
|
||||
|
||||
|
||||
g.FillEllipse(brBody, _startPosX.Value - 5, _startPosY.Value + 30, 100, 24);
|
||||
g.DrawEllipse(penKraya, _startPosX.Value, _startPosY.Value + 27, 17, 6);
|
||||
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 27, 17, 6);
|
||||
|
||||
|
||||
|
||||
//Крыло
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7);
|
||||
|
||||
//Иллюминаторы
|
||||
|
||||
for (int i = 0; i < 80; i += 10)
|
||||
{
|
||||
|
||||
g.FillEllipse(brWhity, _startPosX.Value + 30 + i, _startPosY.Value + 34, 6, 6);
|
||||
|
||||
|
||||
}
|
||||
|
||||
//Пилоты
|
||||
g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8);
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectSeaplane;
|
||||
using ProjectSeaplane.Entities;
|
||||
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
/// <summary>
|
||||
/// Отрисовка и перемещение
|
||||
/// </summary>
|
||||
@ -78,14 +80,14 @@ public class DrawingSeaplane
|
||||
if (_startPosX + _drawningSeaplaneWidth > width)
|
||||
{
|
||||
_startPosX = width - (_drawningSeaplaneWidth + 1);
|
||||
|
||||
|
||||
}
|
||||
if (_startPosY + _drawningSeaplaneWidth > height)
|
||||
{
|
||||
_startPosY = height - (_drawningSeaplaneHeight + 1);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -285,7 +287,7 @@ public class DrawingSeaplane
|
||||
//Пилоты
|
||||
g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -0,0 +1,41 @@
|
||||
namespace ProjectSeaplane.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Простой Гидросамолет"
|
||||
/// </summary>
|
||||
public class EntityBasicSeaplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
/// </summary>
|
||||
public int Speed { get; private set; }
|
||||
/// <summary>
|
||||
/// Вес
|
||||
/// </summary>
|
||||
public double Weight { get; private set; }
|
||||
/// <summary>
|
||||
/// Основной цвет
|
||||
/// </summary>
|
||||
public Color BodyColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Расстояние шага передвижения
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
/// <summary>
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="landingGear">Тип "шасси"</param>
|
||||
/// <param name="radar">При</param>
|
||||
public EntityBasicSeaplane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
namespace ProjectSeaplane;
|
||||
namespace ProjectSeaplane.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность Гидросамолета
|
||||
/// </summary>
|
||||
@ -27,7 +27,7 @@ public class EntitySeaplane
|
||||
/// <summary>
|
||||
/// Признак наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
public bool Radar { get; private set; }
|
||||
/// <summary>
|
||||
/// Расстояние шага передвижения
|
||||
/// </summary>
|
||||
@ -45,10 +45,10 @@ public class EntitySeaplane
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
LandingGear = landingGear;
|
||||
Radar = radar;
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
namespace ProjectSeaplane
|
||||
using ProjectSeaplane.Drawnings;
|
||||
|
||||
namespace ProjectSeaplane
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Гидросамолет"
|
||||
/// </summary>
|
||||
|
Loading…
Reference in New Issue
Block a user