Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
685e9b403d | |||
02951365a9 | |||
7f0d75e12e |
@ -0,0 +1,115 @@
|
||||
using ProjectPlane.Drawnings;
|
||||
|
||||
namespace ProjectPlane.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 180;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 70;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция автомобилей
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningPlane>? _collection = null;
|
||||
|
||||
/// <summary>
|
||||
/// Вычисление максимального количества элементов, который можно разместить в окне
|
||||
/// </summary>
|
||||
private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth">Ширина окна</param>
|
||||
/// <param name="picHeight">Высота окна</param>
|
||||
/// <param name="collection">Коллекция автомобилей</param>
|
||||
public AbstractCompany(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawningPlane> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="сruiser">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningPlane сruiser)
|
||||
{
|
||||
return company._collection.Insert(сruiser);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningPlane operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningPlane? GetRandomObject()
|
||||
{
|
||||
Random rnd = new();
|
||||
return _collection?.Get(rnd.Next(GetMaxCount));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Вывод всей коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public Bitmap? Show()
|
||||
{
|
||||
Bitmap bitmap = new(_pictureWidth, _pictureHeight);
|
||||
Graphics graphics = Graphics.FromImage(bitmap);
|
||||
DrawBackgound(graphics);
|
||||
SetObjectsPosition();
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); ++i)
|
||||
{
|
||||
DrawningPlane? obj = _collection?.Get(i);
|
||||
obj?.DrawTransport(graphics);
|
||||
}
|
||||
return bitmap;
|
||||
}
|
||||
/// <summary>
|
||||
/// Вывод заднего фона
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
protected abstract void DrawBackgound(Graphics g);
|
||||
|
||||
/// <summary>
|
||||
/// Расстановка объектов
|
||||
/// </summary>
|
||||
protected abstract void SetObjectsPosition();
|
||||
}
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
namespace ProjectPlane.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс описания действий для набора хранимых объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public interface ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Количество объектов в коллекции
|
||||
/// </summary>
|
||||
int Count { get; }
|
||||
/// <summary>
|
||||
/// Установка максимального количества элементов
|
||||
/// </summary>
|
||||
int SetMaxCount { set; }
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj);
|
||||
/// <summary>
|
||||
/// Добавление объекта в коллекцию на конкретную позицию
|
||||
/// </summary>
|
||||
/// <param name="obj">Добавляемый объект</param>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - вставка прошла удачно, false - вставка не удалась</returns>
|
||||
int Insert(T obj, int position);
|
||||
/// <summary>
|
||||
/// Удаление объекта из коллекции с конкретной позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>true - удаление прошло удачно, false - удаление не удалось</returns>
|
||||
T? Remove(int position);
|
||||
/// <summary>
|
||||
/// Получение объекта по позиции
|
||||
/// </summary>
|
||||
/// <param name="position">Позиция</param>
|
||||
/// <returns>Объект</returns>
|
||||
T? Get(int position);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,97 @@
|
||||
using ProjectPlane.Drawnings;
|
||||
|
||||
namespace ProjectPlane.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметризованный набор объектов
|
||||
/// </summary>
|
||||
/// <typeparam name="T">Параметр: ограничение - ссылочный тип</typeparam>
|
||||
public class MassiveGenericObjects<T> : ICollectionGenericObjects<T>
|
||||
where T : class
|
||||
{
|
||||
/// <summary>
|
||||
/// Массив объектов, которые храним
|
||||
/// </summary>
|
||||
private T?[] _collection;
|
||||
public int Count => _collection.Length;
|
||||
public int SetMaxCount { set { if (value > 0) { _collection = new T?[value]; } } }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public MassiveGenericObjects()
|
||||
{
|
||||
_collection = Array.Empty<T?>();
|
||||
}
|
||||
public T? Get(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _collection[position];
|
||||
}
|
||||
public int Insert(T obj)
|
||||
{
|
||||
// TODO вставка в свободное место набора
|
||||
int index = 0;
|
||||
while (index < _collection.Length)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[index] = obj;
|
||||
return index;
|
||||
}
|
||||
index++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
// ищется свободное место после этой позиции и идет вставка туда
|
||||
// если нет после, ищем до
|
||||
// TODO вставка
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return -1; }
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
int index;
|
||||
|
||||
for (index = position + 1; index < _collection.Length; ++index)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
|
||||
for (index = position - 1; index >= 0; --index)
|
||||
{
|
||||
if (_collection[index] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
public T Remove(int position)
|
||||
{
|
||||
// TODO проверка позиции
|
||||
// TODO удаление объекта из массива, присвоив элементу массива значение null
|
||||
if (position >= _collection.Length || position < 0)
|
||||
{ return null; }
|
||||
T drawningPlane = _collection[position];
|
||||
_collection[position] = null;
|
||||
return drawningPlane;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,65 @@
|
||||
using ProjectPlane.Drawnings;
|
||||
|
||||
namespace ProjectPlane.CollectionGenericObjects
|
||||
{
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - каршеринг
|
||||
/// </summary>
|
||||
public class PlaneDockingService : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public PlaneDockingService(int picWidth, int picHeight,
|
||||
ICollectionGenericObjects<DrawningPlane> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
Pen pen = new(Color.Black, 2);
|
||||
for (int i = 0; i < width; i++)
|
||||
{
|
||||
for (int j = 0; j < height + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight);
|
||||
g.DrawLine(pen, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 20, j * _placeSizeHeight + _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
int width = _pictureWidth / _placeSizeWidth;
|
||||
int height = _pictureHeight / _placeSizeHeight;
|
||||
|
||||
int curWidth = 0;
|
||||
int curHeight = 0;
|
||||
|
||||
for (int i = 0; i < (_collection?.Count ?? 0); i++)
|
||||
{
|
||||
if (_collection.Get(i) != null)
|
||||
{
|
||||
_collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 10, curHeight * _placeSizeHeight + 10);
|
||||
}
|
||||
|
||||
if (curWidth < width - 1)
|
||||
curWidth++;
|
||||
else
|
||||
{
|
||||
curWidth = 0;
|
||||
curHeight ++;
|
||||
}
|
||||
|
||||
if (curHeight >= height)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
27
ProjectPlane/ProjectPlane/Drawnings/DirectionType.cs
Normal file
27
ProjectPlane/ProjectPlane/Drawnings/DirectionType.cs
Normal file
@ -0,0 +1,27 @@
|
||||
namespace ProjectPlane.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknow = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
255
ProjectPlane/ProjectPlane/Drawnings/DrawningPlane.cs
Normal file
255
ProjectPlane/ProjectPlane/Drawnings/DrawningPlane.cs
Normal file
@ -0,0 +1,255 @@
|
||||
using ProjectPlane.Entities;
|
||||
using System.Drawing.Drawing2D;
|
||||
|
||||
namespace ProjectPlane.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityPlane? EntityPlane { get; protected set; }
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
private int? _pictureWidth;
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
private int? _pictureHeight;
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningPlaneWidth = 150;
|
||||
/// <summary>
|
||||
/// Высота прорисовки самолета
|
||||
/// </summary>
|
||||
private readonly int _drawningPlaneHeight = 50;
|
||||
private readonly int _drawningEnginesWidth = 3;
|
||||
|
||||
/// <summary>
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
public int? GetPosX => _startPosX;
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningPlaneWidth;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningPlaneHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Пустой онструктор
|
||||
/// </summary>
|
||||
private DrawningPlane()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningPlane(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityPlane = new EntityPlane(speed, weight, bodyColor);
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningCarWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="drawningCarHeight">Высота прорисовки автомобиля</param>
|
||||
protected DrawningPlane(int drawningCarWidth, int drawningCarHeight) : this()
|
||||
{
|
||||
_drawningPlaneWidth = drawningCarWidth;
|
||||
_pictureHeight = drawningCarHeight;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
/// </summary>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
/// <returns>true - границы заданы, false - проверка не пройдена, нельзя разместить объект в этих размерах</returns>
|
||||
public bool SetPictureSize(int width, int height)
|
||||
{
|
||||
// TODO проверка, что объект "влезает" в размеры поля
|
||||
// если влезает, сохраняем границы и корректируем позицию объекта,если она была уже установлена
|
||||
|
||||
if (_drawningPlaneHeight > height || _drawningPlaneWidth > width)
|
||||
{
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
|
||||
if (_startPosX.HasValue && _startPosY.HasValue)
|
||||
{
|
||||
SetPosition(_startPosX.Value, _startPosY.Value);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
/// <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;
|
||||
}
|
||||
|
||||
if (x < 0 || x + _drawningPlaneWidth > _pictureWidth || y < 0 || y + _drawningPlaneHeight > _pictureHeight)
|
||||
{
|
||||
_startPosX = _pictureWidth - _drawningPlaneWidth;
|
||||
_startPosY = _pictureHeight - _drawningPlaneHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
_startPosX = x;
|
||||
_startPosY = y;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Изменение направления перемещения
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityPlane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
switch (direction)
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityPlane.Step - _drawningEnginesWidth > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityPlane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
//TODO прописать логику сдвига в право
|
||||
if (_startPosX.Value + EntityPlane.Step + _drawningPlaneWidth < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityPlane.Step + _drawningPlaneHeight < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)EntityPlane.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane == null || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Pen pen3 = new(EntityPlane.BodyColor, 2);
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Pen pen5 = new(Color.Black, 4);
|
||||
Pen pen2 = new(Color.Black, 6);
|
||||
Pen pen4 = new(Color.White, 4);
|
||||
Pen pen6 = new(Color.Black, 1);
|
||||
Brush Brush = new SolidBrush(EntityPlane.BodyColor);
|
||||
Brush Brush2 = new SolidBrush(Color.Black);
|
||||
Brush glassBrush = new SolidBrush(Color.SkyBlue);
|
||||
//Brush glassBrush2 = new SolidBrush(EntityPlane.AdditionalColor);
|
||||
//Brush boatBrush = new HatchBrush(HatchStyle.ZigZag, EntityPlane.AdditionalColor, Color.FromArgb(163, 163, 163));
|
||||
//Brush additionalBrush = new SolidBrush(EntityPlane.AdditionalColor);
|
||||
|
||||
//границы самолета
|
||||
|
||||
Point[] points = { new Point(_startPosX.Value + 5, _startPosY.Value + 20), new Point(_startPosX.Value + 20, _startPosY.Value + 15), new Point(_startPosX.Value + 35, _startPosY.Value + 15), new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 70, _startPosY.Value), new Point(_startPosX.Value + 80, _startPosY.Value + 10), new Point(_startPosX.Value + 135, _startPosY.Value + 20), new Point(_startPosX.Value + 143, _startPosY.Value), new Point(_startPosX.Value + 150, _startPosY.Value), new Point(_startPosX.Value + 150, _startPosY.Value + 25), new Point(_startPosX.Value + 90, _startPosY.Value + 30), new Point(_startPosX.Value + 15, _startPosY.Value + 30), new Point(_startPosX.Value + 10, _startPosY.Value + 25) };
|
||||
g.FillPolygon(Brush, points);
|
||||
g.DrawPolygon(pen, points);
|
||||
|
||||
//стёкла
|
||||
Point[] glass1 = { new Point(_startPosX.Value + 35, _startPosY.Value + 15), new Point(_startPosX.Value + 50, _startPosY.Value), new Point(_startPosX.Value + 42, _startPosY.Value + 15) };
|
||||
g.FillPolygon(glassBrush, glass1);
|
||||
g.DrawPolygon(pen, glass1);
|
||||
|
||||
Point[] glass2 = { new Point(_startPosX.Value + 47, _startPosY.Value + 15), new Point(_startPosX.Value + 55, _startPosY.Value), new Point(_startPosX.Value + 55, _startPosY.Value + 15) };
|
||||
g.FillPolygon(glassBrush, glass2);
|
||||
g.DrawPolygon(pen, glass2);
|
||||
|
||||
Point[] glass3 = { new Point(_startPosX.Value + 60, _startPosY.Value + 15), new Point(_startPosX.Value + 65, _startPosY.Value + 7), new Point(_startPosX.Value + 70, _startPosY.Value + 7), new Point(_startPosX.Value + 75, _startPosY.Value + 15) };
|
||||
g.FillPolygon(glassBrush, glass3);
|
||||
g.DrawPolygon(pen, glass3);
|
||||
|
||||
//крылья
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 47, _startPosY.Value - 2, 32, 7);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value, _startPosX.Value + 60, _startPosY.Value + 20);
|
||||
g.DrawLine(pen4, _startPosX.Value + 40, _startPosY.Value - 3, _startPosX.Value + 80, _startPosY.Value - 3);
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 137, _startPosY.Value + 17, 15, 5);
|
||||
|
||||
|
||||
//пропелер
|
||||
Point[] points2 = { new Point(_startPosX.Value + 10, _startPosY.Value + 20), new Point(_startPosX.Value + 10, _startPosY.Value + 25), new Point(_startPosX.Value + 3, _startPosY.Value + 22) };
|
||||
g.DrawPolygon(pen, points2);
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 1, _startPosY.Value + 10, 5, 13);
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 1, _startPosY.Value + 21, 5, 13);
|
||||
|
||||
//колёса
|
||||
g.DrawLine(pen, _startPosX.Value + 20, _startPosY.Value + 30, _startPosX.Value + 30, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 50, _startPosY.Value + 30, _startPosX.Value + 40, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 60, _startPosY.Value + 30, _startPosX.Value + 70, _startPosY.Value + 40);
|
||||
g.DrawLine(pen, _startPosX.Value + 80, _startPosY.Value + 30, _startPosX.Value + 90, _startPosY.Value + 40);
|
||||
g.DrawLine(pen5, _startPosX.Value + 10, _startPosY.Value + 41, _startPosX.Value + 90, _startPosY.Value + 41);
|
||||
g.DrawLine(pen, _startPosX.Value + 10, _startPosY.Value + 40, _startPosX.Value + 5, _startPosY.Value + 45);
|
||||
g.DrawLine(pen, _startPosX.Value + 5, _startPosY.Value + 45, _startPosX.Value + 10, _startPosY.Value + 47);
|
||||
g.DrawLine(pen, _startPosX.Value + 90, _startPosY.Value + 40, _startPosX.Value + 90, _startPosY.Value + 50);
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 7, _startPosY.Value + 43, 8, 8);
|
||||
g.FillEllipse(Brush2, _startPosX.Value + 85, _startPosY.Value + 43, 8, 8);
|
||||
}
|
||||
}
|
87
ProjectPlane/ProjectPlane/Drawnings/DrawningSeaPlane.cs
Normal file
87
ProjectPlane/ProjectPlane/Drawnings/DrawningSeaPlane.cs
Normal file
@ -0,0 +1,87 @@
|
||||
using System.Drawing.Drawing2D;
|
||||
using ProjectPlane.Entities;
|
||||
|
||||
namespace ProjectPlane.Drawnings
|
||||
{
|
||||
public class DrawningSeaPlane : DrawningPlane
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="line">Признак наличия вертолетной площадки</param>
|
||||
/// <param name="boat">Признак наличия шлюпок</param>
|
||||
/// <param name="floats">Признак наличия пушки</param>
|
||||
|
||||
public DrawningSeaPlane(int speed, double weight, Color bodyColor, Color additionalColor, bool line, bool boat, bool floats)
|
||||
: base(150, 50)
|
||||
{
|
||||
EntityPlane = new EntitySeaPlane(speed, weight, bodyColor, additionalColor, line, boat, floats);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityPlane == null || EntityPlane is not EntitySeaPlane entitySeaPlane || !_startPosX.HasValue ||
|
||||
!_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen3 = new(EntityPlane.BodyColor, 2);
|
||||
Pen pen = new(Color.Black, 2);
|
||||
Pen pen5 = new(Color.Black, 4);
|
||||
Pen pen2 = new(Color.Black, 6);
|
||||
Pen pen4 = new(Color.White, 4);
|
||||
Pen pen6 = new(Color.Black, 1);
|
||||
Brush Brush = new SolidBrush(EntityPlane.BodyColor);
|
||||
Brush Brush2 = new SolidBrush(Color.Black);
|
||||
Brush glassBrush = new SolidBrush(Color.SkyBlue);
|
||||
Brush glassBrush2 = new SolidBrush(entitySeaPlane.AdditionalColor);
|
||||
Brush boatBrush = new HatchBrush(HatchStyle.ZigZag, entitySeaPlane.AdditionalColor, Color.FromArgb(163, 163, 163));
|
||||
Brush additionalBrush = new SolidBrush(entitySeaPlane.AdditionalColor);
|
||||
|
||||
base.DrawTransport(g);
|
||||
|
||||
//внутренности самолета
|
||||
|
||||
//g.DrawRectangle(pen, _startPosX.Value + 25, _startPosY.Value + 10, 80, 30);
|
||||
//g.FillRectangle(additionalBrush, _startPosX.Value + 25, _startPosY.Value + 10, 80, 30);
|
||||
|
||||
|
||||
|
||||
|
||||
if (entitySeaPlane.Line)
|
||||
{
|
||||
Point[] points3 = { new Point(_startPosX.Value + 35, _startPosY.Value + 15), new Point(_startPosX.Value + 20, _startPosY.Value + 15), new Point(_startPosX.Value + 10, _startPosY.Value + 20), new Point(_startPosX.Value + 10, _startPosY.Value + 25), new Point(_startPosX.Value + 15, _startPosY.Value + 30), new Point(_startPosX.Value + 145, _startPosY.Value + 20), new Point(_startPosX.Value + 140, _startPosY.Value + 20), new Point(_startPosX.Value + 140, _startPosY.Value + 10), new Point(_startPosX.Value + 135, _startPosY.Value + 20), new Point(_startPosX.Value + 30, _startPosY.Value + 20) };
|
||||
g.FillPolygon(additionalBrush, points3);
|
||||
g.DrawPolygon(pen6, points3);
|
||||
|
||||
}
|
||||
|
||||
if (entitySeaPlane.Floats)
|
||||
{
|
||||
Point[] points4 = { new Point(_startPosX.Value + 10, _startPosY.Value + 40), new Point(_startPosX.Value + 110, _startPosY.Value + 40), new Point(_startPosX.Value + 110, _startPosY.Value + 41), new Point(_startPosX.Value + 70, _startPosY.Value + 50), new Point(_startPosX.Value + 30, _startPosY.Value + 50) };
|
||||
g.FillPolygon(additionalBrush, points4);
|
||||
g.DrawPolygon(pen, points4);
|
||||
g.DrawLine(pen, _startPosX.Value + 30, _startPosY.Value + 45, _startPosX.Value + 80, _startPosY.Value + 45);
|
||||
}
|
||||
|
||||
if (entitySeaPlane.Boat)
|
||||
{
|
||||
g.DrawRectangle(pen, _startPosX.Value + 85, _startPosY.Value + 15, 25, 10);
|
||||
g.FillRectangle(boatBrush, _startPosX.Value + 85, _startPosY.Value + 15, 25, 10);
|
||||
Point[] points5 = { new Point(_startPosX.Value + 80, _startPosY.Value + 15), new Point(_startPosX.Value + 85, _startPosY.Value + 10), new Point(_startPosX.Value + 115, _startPosY.Value + 10), new Point(_startPosX.Value + 115, _startPosY.Value + 15), new Point(_startPosX.Value + 85, _startPosY.Value + 15), new Point(_startPosX.Value + 85, _startPosY.Value + 25), new Point(_startPosX.Value + 115, _startPosY.Value + 25), new Point(_startPosX.Value + 115, _startPosY.Value + 30), new Point(_startPosX.Value + 85, _startPosY.Value + 30), new Point(_startPosX.Value + 80, _startPosY.Value + 25) };
|
||||
g.FillPolygon(additionalBrush, points5);
|
||||
g.DrawPolygon(pen, points5);
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
38
ProjectPlane/ProjectPlane/Entities/EntityPlane.cs
Normal file
38
ProjectPlane/ProjectPlane/Entities/EntityPlane.cs
Normal file
@ -0,0 +1,38 @@
|
||||
namespace ProjectPlane.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "самолет"
|
||||
/// </summary>
|
||||
public class EntityPlane
|
||||
{
|
||||
//свойства
|
||||
/// <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>
|
||||
public EntityPlane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
30
ProjectPlane/ProjectPlane/Entities/EntitySeaPlane.cs
Normal file
30
ProjectPlane/ProjectPlane/Entities/EntitySeaPlane.cs
Normal file
@ -0,0 +1,30 @@
|
||||
namespace ProjectPlane.Entities
|
||||
{
|
||||
internal class EntitySeaPlane : EntityPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие линии
|
||||
/// </summary>
|
||||
public bool Line { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие шлюпки
|
||||
/// </summary>
|
||||
public bool Boat { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак (опция) наличие поплавков
|
||||
/// </summary>
|
||||
public bool Floats { get; private set; }
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
|
||||
public EntitySeaPlane(int speed, double weight, Color bodyColor, Color additionalColor, bool line, bool boat, bool floats) : base(speed, weight, bodyColor)
|
||||
{
|
||||
AdditionalColor = additionalColor;
|
||||
Line = line;
|
||||
Boat = boat;
|
||||
Floats = floats;
|
||||
}
|
||||
}
|
||||
}
|
39
ProjectPlane/ProjectPlane/Form1.Designer.cs
generated
39
ProjectPlane/ProjectPlane/Form1.Designer.cs
generated
@ -1,39 +0,0 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
partial class Form1
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
this.components = new System.ComponentModel.Container();
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.ClientSize = new System.Drawing.Size(800, 450);
|
||||
this.Text = "Form1";
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -1,10 +0,0 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
public partial class Form1 : Form
|
||||
{
|
||||
public Form1()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
}
|
||||
}
|
151
ProjectPlane/ProjectPlane/FormPlane.Designer.cs
generated
Normal file
151
ProjectPlane/ProjectPlane/FormPlane.Designer.cs
generated
Normal file
@ -0,0 +1,151 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
partial class FormPlane
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FormPlane));
|
||||
pictureBoxPlane = new PictureBox();
|
||||
buttonUp = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonRight = new Button();
|
||||
buttonLeft = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxPlane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// pictureBoxPlane
|
||||
//
|
||||
pictureBoxPlane.Dock = DockStyle.Fill;
|
||||
pictureBoxPlane.Location = new Point(0, 0);
|
||||
pictureBoxPlane.Name = "pictureBoxPlane";
|
||||
pictureBoxPlane.Size = new Size(800, 450);
|
||||
pictureBoxPlane.SizeMode = PictureBoxSizeMode.AutoSize;
|
||||
pictureBoxPlane.TabIndex = 0;
|
||||
pictureBoxPlane.TabStop = false;
|
||||
//
|
||||
// buttonUp
|
||||
//
|
||||
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonUp.BackgroundImage = (Image)resources.GetObject("buttonUp.BackgroundImage");
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonUp.Location = new Point(722, 373);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(30, 30);
|
||||
buttonUp.TabIndex = 2;
|
||||
buttonUp.UseVisualStyleBackColor = true;
|
||||
buttonUp.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonDown
|
||||
//
|
||||
buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonDown.BackgroundImage = (Image)resources.GetObject("buttonDown.BackgroundImage");
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonDown.Location = new Point(722, 409);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(30, 30);
|
||||
buttonDown.TabIndex = 3;
|
||||
buttonDown.UseVisualStyleBackColor = true;
|
||||
buttonDown.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonRight
|
||||
//
|
||||
buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRight.BackgroundImage = (Image)resources.GetObject("buttonRight.BackgroundImage");
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonRight.Location = new Point(758, 409);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(30, 30);
|
||||
buttonRight.TabIndex = 4;
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackgroundImage = (Image)resources.GetObject("buttonLeft.BackgroundImage");
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Zoom;
|
||||
buttonLeft.Location = new Point(686, 409);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(30, 30);
|
||||
buttonLeft.TabIndex = 5;
|
||||
buttonLeft.UseVisualStyleBackColor = true;
|
||||
buttonLeft.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "к центру", "к краю" });
|
||||
comboBoxStrategy.Location = new Point(637, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(151, 28);
|
||||
comboBoxStrategy.TabIndex = 6;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(694, 46);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(94, 29);
|
||||
buttonStrategyStep.TabIndex = 8;
|
||||
buttonStrategyStep.Text = "шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += ButtonStrategyStep_Click;
|
||||
//
|
||||
// FormPlane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(800, 450);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(pictureBoxPlane);
|
||||
Name = "FormPlane";
|
||||
Text = "FormPlane";
|
||||
Click += ButtonMove_Click;
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxPlane).EndInit();
|
||||
ResumeLayout(false);
|
||||
PerformLayout();
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxPlane;
|
||||
private Button buttonUp;
|
||||
private Button buttonDown;
|
||||
private Button buttonRight;
|
||||
private Button buttonLeft;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
139
ProjectPlane/ProjectPlane/FormPlane.cs
Normal file
139
ProjectPlane/ProjectPlane/FormPlane.cs
Normal file
@ -0,0 +1,139 @@
|
||||
using ProjectPlane.Drawnings;
|
||||
using ProjectPlane.MovementStrategy;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
public partial class FormPlane : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningPlane? _drawningPlane;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningPlane SetPlane
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningPlane = value;
|
||||
_drawningPlane.SetPictureSize(pictureBoxPlane.Width,
|
||||
pictureBoxPlane.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
public FormPlane()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Метод прорисовки круисера
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Bitmap bmp = new(pictureBoxPlane.Width,
|
||||
pictureBoxPlane.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningPlane.DrawTransport(gr);
|
||||
pictureBoxPlane.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
string name = ((Button)sender)?.Name ?? string.Empty;
|
||||
bool result = false;
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningPlane.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result =
|
||||
_drawningPlane.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
if (result)
|
||||
{
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// обработка нажатия кнопки шаг
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningPlane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveablePlane(_drawningPlane), pictureBoxPlane.Width, pictureBoxPlane.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
1540
ProjectPlane/ProjectPlane/FormPlane.resx
Normal file
1540
ProjectPlane/ProjectPlane/FormPlane.resx
Normal file
File diff suppressed because it is too large
Load Diff
184
ProjectPlane/ProjectPlane/FormPlanesCollection.Designer.cs
generated
Normal file
184
ProjectPlane/ProjectPlane/FormPlanesCollection.Designer.cs
generated
Normal file
@ -0,0 +1,184 @@
|
||||
namespace ProjectPlane
|
||||
{
|
||||
partial class FormPlanesCollection
|
||||
{
|
||||
/// <summary>
|
||||
/// Required designer variable.
|
||||
/// </summary>
|
||||
private System.ComponentModel.IContainer components = null;
|
||||
|
||||
/// <summary>
|
||||
/// Clean up any resources being used.
|
||||
/// </summary>
|
||||
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (disposing && (components != null))
|
||||
{
|
||||
components.Dispose();
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
}
|
||||
|
||||
#region Windows Form Designer generated code
|
||||
|
||||
/// <summary>
|
||||
/// Required method for Designer support - do not modify
|
||||
/// the contents of this method with the code editor.
|
||||
/// </summary>
|
||||
private void InitializeComponent()
|
||||
{
|
||||
groupBoxTools = new GroupBox();
|
||||
maskedTextBoxPosision = new MaskedTextBox();
|
||||
buttonRefresh = new Button();
|
||||
buttonGetToTest = new Button();
|
||||
ButtonRemovePlane = new Button();
|
||||
ButtonAddSeaPlane = new Button();
|
||||
ButtonAddPlane = new Button();
|
||||
comboBoxSelectorCompany = new ComboBox();
|
||||
pictureBoxPlane = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxPlane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(maskedTextBoxPosision);
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGetToTest);
|
||||
groupBoxTools.Controls.Add(ButtonRemovePlane);
|
||||
groupBoxTools.Controls.Add(ButtonAddSeaPlane);
|
||||
groupBoxTools.Controls.Add(ButtonAddPlane);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(541, 0);
|
||||
groupBoxTools.Margin = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Padding = new Padding(3, 2, 3, 2);
|
||||
groupBoxTools.Size = new Size(194, 430);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "инструменты";
|
||||
//
|
||||
// maskedTextBoxPosision
|
||||
//
|
||||
maskedTextBoxPosision.Location = new Point(18, 172);
|
||||
maskedTextBoxPosision.Margin = new Padding(3, 2, 3, 2);
|
||||
maskedTextBoxPosision.Mask = "00";
|
||||
maskedTextBoxPosision.Name = "maskedTextBoxPosision";
|
||||
maskedTextBoxPosision.Size = new Size(163, 23);
|
||||
maskedTextBoxPosision.TabIndex = 2;
|
||||
maskedTextBoxPosision.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonRefresh.Location = new Point(18, 359);
|
||||
buttonRefresh.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(163, 30);
|
||||
buttonRefresh.TabIndex = 5;
|
||||
buttonRefresh.Text = "обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGetToTest
|
||||
//
|
||||
buttonGetToTest.Anchor = AnchorStyles.Right;
|
||||
buttonGetToTest.Location = new Point(18, 274);
|
||||
buttonGetToTest.Margin = new Padding(3, 2, 3, 2);
|
||||
buttonGetToTest.Name = "buttonGetToTest";
|
||||
buttonGetToTest.Size = new Size(163, 30);
|
||||
buttonGetToTest.TabIndex = 4;
|
||||
buttonGetToTest.Text = "передать на тесты";
|
||||
buttonGetToTest.UseVisualStyleBackColor = true;
|
||||
buttonGetToTest.Click += ButtonGetToTest_Click;
|
||||
//
|
||||
// ButtonRemovePlane
|
||||
//
|
||||
ButtonRemovePlane.Anchor = AnchorStyles.Right;
|
||||
ButtonRemovePlane.Location = new Point(18, 203);
|
||||
ButtonRemovePlane.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonRemovePlane.Name = "ButtonRemovePlane";
|
||||
ButtonRemovePlane.Size = new Size(163, 30);
|
||||
ButtonRemovePlane.TabIndex = 3;
|
||||
ButtonRemovePlane.Text = "удалить самолет";
|
||||
ButtonRemovePlane.UseVisualStyleBackColor = true;
|
||||
ButtonRemovePlane.Click += ButtonRemovePlane_Click;
|
||||
//
|
||||
// ButtonAddSeaPlane
|
||||
//
|
||||
ButtonAddSeaPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonAddSeaPlane.Location = new Point(18, 114);
|
||||
ButtonAddSeaPlane.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAddSeaPlane.Name = "ButtonAddSeaPlane";
|
||||
ButtonAddSeaPlane.Size = new Size(163, 38);
|
||||
ButtonAddSeaPlane.TabIndex = 2;
|
||||
ButtonAddSeaPlane.Text = "добваление гидроплана";
|
||||
ButtonAddSeaPlane.UseVisualStyleBackColor = true;
|
||||
ButtonAddSeaPlane.Click += ButtonAddSeaPlane_Click;
|
||||
//
|
||||
// ButtonAddPlane
|
||||
//
|
||||
ButtonAddPlane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
ButtonAddPlane.BackgroundImageLayout = ImageLayout.Center;
|
||||
ButtonAddPlane.Location = new Point(18, 80);
|
||||
ButtonAddPlane.Margin = new Padding(3, 2, 3, 2);
|
||||
ButtonAddPlane.Name = "ButtonAddPlane";
|
||||
ButtonAddPlane.Size = new Size(163, 30);
|
||||
ButtonAddPlane.TabIndex = 1;
|
||||
ButtonAddPlane.Text = "добваление самолета";
|
||||
ButtonAddPlane.UseVisualStyleBackColor = true;
|
||||
ButtonAddPlane.Click += ButtonAddPlane_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(18, 20);
|
||||
comboBoxSelectorCompany.Margin = new Padding(3, 2, 3, 2);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(163, 23);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged_1;
|
||||
//
|
||||
// pictureBoxPlane
|
||||
//
|
||||
pictureBoxPlane.Dock = DockStyle.Fill;
|
||||
pictureBoxPlane.Location = new Point(0, 0);
|
||||
pictureBoxPlane.Margin = new Padding(3, 2, 3, 2);
|
||||
pictureBoxPlane.Name = "pictureBoxPlane";
|
||||
pictureBoxPlane.Size = new Size(541, 430);
|
||||
pictureBoxPlane.TabIndex = 1;
|
||||
pictureBoxPlane.TabStop = false;
|
||||
//
|
||||
// FormPlanesCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(735, 430);
|
||||
Controls.Add(pictureBoxPlane);
|
||||
Controls.Add(groupBoxTools);
|
||||
Margin = new Padding(3, 2, 3, 2);
|
||||
Name = "FormPlanesCollection";
|
||||
Text = "FormPlanesCollection";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxPlane).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button ButtonAddSeaPlane;
|
||||
private Button ButtonAddPlane;
|
||||
private Button ButtonRemovePlane;
|
||||
private Button buttonRefresh;
|
||||
private Button buttonGetToTest;
|
||||
private PictureBox pictureBoxPlane;
|
||||
private MaskedTextBox maskedTextBoxPosision;
|
||||
}
|
||||
}
|
169
ProjectPlane/ProjectPlane/FormPlanesCollection.cs
Normal file
169
ProjectPlane/ProjectPlane/FormPlanesCollection.cs
Normal file
@ -0,0 +1,169 @@
|
||||
using ProjectPlane.CollectionGenericObjects;
|
||||
using ProjectPlane.Drawnings;
|
||||
|
||||
namespace ProjectPlane
|
||||
{
|
||||
public partial class FormPlanesCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlanesCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void comboBoxSelectorCompany_SelectedIndexChanged_1(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "хранилище":
|
||||
_company = new PlaneDockingService(pictureBoxPlane.Width,
|
||||
pictureBoxPlane.Height, new MassiveGenericObjects<DrawningPlane>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Random random = new();
|
||||
DrawningPlane drawningPlane;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningPlane):
|
||||
drawningPlane = new DrawningPlane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningSeaPlane):
|
||||
drawningPlane = new DrawningSeaPlane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random),
|
||||
GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
if (_company + drawningPlane != -1)
|
||||
{
|
||||
MessageBox.Show("объект добавлен");
|
||||
pictureBoxPlane.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("не удалось добавить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение цвета
|
||||
/// </summary>
|
||||
/// <param name="random">Генератор случайных чисел</param>
|
||||
/// <returns></returns>
|
||||
private static Color GetColor(Random random)
|
||||
{
|
||||
Color color = Color.FromArgb(random.Next(0, 256), random.Next(0,
|
||||
256), random.Next(0, 256));
|
||||
ColorDialog dialog = new();
|
||||
if (dialog.ShowDialog() == DialogResult.OK)
|
||||
{
|
||||
color = dialog.Color;
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
//private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningPlane));
|
||||
|
||||
//private void ButtonAddSeaPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningSeaPlane));
|
||||
private void ButtonAddPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningPlane));
|
||||
}
|
||||
|
||||
private void ButtonAddSeaPlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
CreateObject(nameof(DrawningSeaPlane));
|
||||
}
|
||||
|
||||
private void ButtonRemovePlane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosision.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("удалить объект?", "удаление",
|
||||
MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosision.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("объект удален");
|
||||
pictureBoxPlane.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
private void ButtonGetToTest_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawningPlane? plane = null;
|
||||
int counter = 100;
|
||||
while (plane == null)
|
||||
{
|
||||
plane = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (plane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FormPlane form = new()
|
||||
{
|
||||
SetPlane = plane
|
||||
};
|
||||
form.ShowDialog();
|
||||
|
||||
}
|
||||
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBoxPlane.Image = _company.Show();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
123
ProjectPlane/ProjectPlane/MovementStrategy/AbstractStrategy.cs
Normal file
123
ProjectPlane/ProjectPlane/MovementStrategy/AbstractStrategy.cs
Normal file
@ -0,0 +1,123 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-стратегия перемещения объекта
|
||||
/// </summary>
|
||||
public abstract class AbstractStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Перемещаемый объект
|
||||
/// </summary>
|
||||
private IMoveableObject? _moveableObject;
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
private StrategyStatus _state = StrategyStatus.NotInit;
|
||||
/// <summary>
|
||||
/// Ширина поля
|
||||
/// </summary>
|
||||
protected int FieldWidth { get; private set; }
|
||||
/// <summary>
|
||||
/// Высота поля
|
||||
/// </summary>
|
||||
protected int FieldHeight { get; private set; }
|
||||
/// <summary>
|
||||
/// Статус перемещения
|
||||
/// </summary>
|
||||
public StrategyStatus GetStatus() { return _state; }
|
||||
/// <summary>
|
||||
/// Установка данных
|
||||
/// </summary>
|
||||
/// <param name="moveableObject">Перемещаемый объект</param>
|
||||
/// <param name="width">Ширина поля</param>
|
||||
/// <param name="height">Высота поля</param>
|
||||
public void SetData(IMoveableObject moveableObject, int width, int height)
|
||||
{
|
||||
if (moveableObject == null)
|
||||
{
|
||||
_state = StrategyStatus.NotInit;
|
||||
return;
|
||||
}
|
||||
_state = StrategyStatus.InProgress;
|
||||
_moveableObject = moveableObject;
|
||||
FieldWidth = width;
|
||||
FieldHeight = height;
|
||||
}
|
||||
/// <summary>
|
||||
/// Шаг перемещения
|
||||
/// </summary>
|
||||
public void MakeStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (IsTargetDestinaion())
|
||||
{
|
||||
_state = StrategyStatus.Finish;
|
||||
return;
|
||||
}
|
||||
MoveToTarget();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение влево
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveLeft() => MoveTo(MovementDirection.Left);
|
||||
/// <summary>
|
||||
/// Перемещение вправо
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveRight() => MoveTo(MovementDirection.Right);
|
||||
/// <summary>
|
||||
/// Перемещение вверх
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveUp() => MoveTo(MovementDirection.Up);
|
||||
/// <summary>
|
||||
/// Перемещение вниз
|
||||
/// </summary>
|
||||
/// <returns>Результат перемещения (true - удалось переместиться, false - неудача)</returns>
|
||||
protected bool MoveDown() => MoveTo(MovementDirection.Down);
|
||||
/// <summary>
|
||||
/// Параметры объекта
|
||||
/// </summary>
|
||||
protected ObjectParameters? GetObjectParameters =>
|
||||
_moveableObject?.GetObjectPosition;
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected int? GetStep()
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return _moveableObject?.GetStep;
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение к цели
|
||||
/// </summary>
|
||||
protected abstract void MoveToTarget();
|
||||
/// <summary>
|
||||
/// Достигнута ли цель
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
protected abstract bool IsTargetDestinaion();
|
||||
/// <summary>
|
||||
/// Попытка перемещения в требуемом направлении
|
||||
/// </summary>
|
||||
/// <param name="movementDirection">Направление</param>
|
||||
/// <returns>Результат попытки (true - удалось переместиться, false - неудача)</returns>
|
||||
private bool MoveTo(MovementDirection movementDirection)
|
||||
{
|
||||
if (_state != StrategyStatus.InProgress)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _moveableObject?.TryMoveObject(movementDirection) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Интерфейс для работы с перемещаемым объектом
|
||||
/// </summary>
|
||||
public interface IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Получение координаты объекта
|
||||
/// </summary>
|
||||
ObjectParameters? GetObjectPosition { get; }
|
||||
/// <summary>
|
||||
/// Шаг объекта
|
||||
/// </summary>
|
||||
int GetStep { get; }
|
||||
/// <summary>
|
||||
/// Попытка переместить объект в указанном направлении
|
||||
/// </summary>
|
||||
/// <param name="direction">Направление</param>
|
||||
/// <returns>true - объект перемещен, false - перемещение невозможно</returns>
|
||||
bool TryMoveObject(MovementDirection direction);
|
||||
}
|
||||
|
||||
}
|
53
ProjectPlane/ProjectPlane/MovementStrategy/MoveToBorder.cs
Normal file
53
ProjectPlane/ProjectPlane/MovementStrategy/MoveToBorder.cs
Normal file
@ -0,0 +1,53 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта к краю экрана
|
||||
/// </summary>
|
||||
internal class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder - GetStep() <= FieldWidth
|
||||
&& objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder - GetStep() <= FieldHeight
|
||||
&& objParams.DownBorder + GetStep() >= FieldHeight;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.RightBorder - FieldWidth;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder - FieldHeight;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
53
ProjectPlane/ProjectPlane/MovementStrategy/MoveToCenter.cs
Normal file
53
ProjectPlane/ProjectPlane/MovementStrategy/MoveToCenter.cs
Normal file
@ -0,0 +1,53 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Стратегия перемещения объекта в центр экрана
|
||||
/// </summary>
|
||||
public class MoveToCenter : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.ObjectMiddleHorizontal - GetStep() <= FieldWidth / 2
|
||||
&& objParams.ObjectMiddleHorizontal + GetStep() >= FieldWidth / 2 &&
|
||||
objParams.ObjectMiddleVertical - GetStep() <= FieldHeight / 2
|
||||
&& objParams.ObjectMiddleVertical + GetStep() >= FieldHeight / 2;
|
||||
}
|
||||
protected override void MoveToTarget()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int diffX = objParams.ObjectMiddleHorizontal - FieldWidth / 2;
|
||||
if (Math.Abs(diffX) > GetStep())
|
||||
{
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveLeft();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.ObjectMiddleVertical - FieldHeight / 2;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
if (diffY > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
else
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
62
ProjectPlane/ProjectPlane/MovementStrategy/MoveablePlane.cs
Normal file
62
ProjectPlane/ProjectPlane/MovementStrategy/MoveablePlane.cs
Normal file
@ -0,0 +1,62 @@
|
||||
using ProjectPlane.Drawnings;
|
||||
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// класс реалтзация для IMoveableObject с использованием DrawningPlane
|
||||
/// </summary>
|
||||
public class MoveablePlane : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningPlane или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningPlane? _plane = null;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="plane">Объект класса DrawningPlane</param>
|
||||
public MoveablePlane(DrawningPlane plane)
|
||||
{
|
||||
_plane = plane;
|
||||
}
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_plane == null || _plane.EntityPlane == null ||
|
||||
!_plane.GetPosX.HasValue || !_plane.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_plane.GetPosX.Value,
|
||||
_plane.GetPosY.Value, _plane.GetWidth, _plane.GetHeight);
|
||||
}
|
||||
}
|
||||
public int GetStep => (int)(_plane?.EntityPlane?.Step ?? 0);
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_plane == null || _plane.EntityPlane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return _plane.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
/// <summary>
|
||||
/// Конвертация из MovementDirection в DirectionType
|
||||
/// </summary>
|
||||
/// <param name="direction">MovementDirection</param>
|
||||
/// <returns>DirectionType</returns>
|
||||
private static DirectionType GetDirectionType(MovementDirection direction)
|
||||
{
|
||||
return direction switch
|
||||
{
|
||||
MovementDirection.Left => DirectionType.Left,
|
||||
MovementDirection.Right => DirectionType.Right,
|
||||
MovementDirection.Up => DirectionType.Up,
|
||||
MovementDirection.Down => DirectionType.Down,
|
||||
_ => DirectionType.Unknow,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,26 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
Up = 1,
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
Down = 2,
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
Left = 3,
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
Right = 4
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,64 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Параметры-координаты объекта
|
||||
/// </summary>
|
||||
public class ObjectParameters
|
||||
{
|
||||
/// <summary>
|
||||
/// Координата X
|
||||
/// </summary>
|
||||
private readonly int _x;
|
||||
/// <summary>
|
||||
/// Координата Y
|
||||
/// </summary>
|
||||
private readonly int _y;
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
private readonly int _width;
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
private readonly int _height;
|
||||
/// <summary>
|
||||
/// Левая граница
|
||||
/// </summary>
|
||||
public int LeftBorder => _x;
|
||||
/// <summary>
|
||||
/// Верхняя граница
|
||||
/// </summary>
|
||||
public int TopBorder => _y;
|
||||
/// <summary>
|
||||
/// Правая граница
|
||||
/// </summary>
|
||||
public int RightBorder => _x + _width;
|
||||
/// <summary>
|
||||
/// Нижняя граница
|
||||
/// </summary>
|
||||
public int DownBorder => _y + _height;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleHorizontal => _x + _width / 2;
|
||||
/// <summary>
|
||||
/// Середина объекта
|
||||
/// </summary>
|
||||
public int ObjectMiddleVertical => _y + _height / 2;
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="x">Координата X</param>
|
||||
/// <param name="y">Координата Y</param>
|
||||
/// <param name="width">Ширина объекта</param>
|
||||
/// <param name="height">Высота объекта</param>
|
||||
public ObjectParameters(int x, int y, int width, int height)
|
||||
{
|
||||
_x = x;
|
||||
_y = y;
|
||||
_width = width;
|
||||
_height = height;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
22
ProjectPlane/ProjectPlane/MovementStrategy/StrategyStatus.cs
Normal file
22
ProjectPlane/ProjectPlane/MovementStrategy/StrategyStatus.cs
Normal file
@ -0,0 +1,22 @@
|
||||
namespace ProjectPlane.MovementStrategy
|
||||
{
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
|
||||
}
|
@ -8,10 +8,9 @@ namespace ProjectPlane
|
||||
[STAThread]
|
||||
static void Main()
|
||||
{
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
// To customize application configuration such as set high DPI settings or default font, see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new Form1());
|
||||
Application.Run(new FormPlanesCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user