Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 49024c4c17 | |||
| 58cd3ac83e | |||
| 987cd86208 | |||
| a8847944db | |||
| 2ff4ee77d3 | |||
| 5b27838a9d |
@@ -0,0 +1,115 @@
|
||||
using ProjectSeaplane.Drawnings;
|
||||
namespace ProjectSeaplane.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию автомобилей
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 180;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 100;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция cамолетов
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawingBasicSeaplane>? _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<DrawingBasicSeaplane> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="seaplane">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawingBasicSeaplane seaplane)
|
||||
{
|
||||
return company._collection.Insert(seaplane);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawingBasicSeaplane operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection?.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawingBasicSeaplane? 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)
|
||||
{
|
||||
DrawingBasicSeaplane? 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,48 @@
|
||||
namespace ProjectSeaplane.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,120 @@
|
||||
namespace ProjectSeaplane.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)
|
||||
{
|
||||
if (_collection.Length > 0)
|
||||
{
|
||||
Array.Resize(ref _collection, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
_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 obj = _collection[position];
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
using ProjectSeaplane.Drawnings;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace ProjectSeaplane.CollectionGenericObjects;
|
||||
|
||||
public class PlanePark : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public PlanePark(int picWidth, int picHeight, ICollectionGenericObjects<DrawingBasicSeaplane> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
int width = _pictureWidth - 1;
|
||||
int height = _pictureHeight / 2;
|
||||
Pen pen = new(Color.RosyBrown, 3);
|
||||
|
||||
g.DrawLine(pen, width, height, 5, height);
|
||||
g.DrawLine(pen, width, height - 100, 5, height - 100);
|
||||
Pen pen2 = new(Color.Black, 3);
|
||||
for (int i = 0; i < _pictureWidth; i+=50)
|
||||
{
|
||||
g.DrawLine(pen2, width-i, height - 50, width - (i+30), height -50);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
|
||||
int count = 0;
|
||||
int megacount = 0;
|
||||
for (int y = _pictureHeight - 100; y - 50 > 0; y -= 100)
|
||||
{
|
||||
megacount++;
|
||||
if (y < _pictureHeight / 2 && y > (_pictureHeight / 2) - 100)
|
||||
{
|
||||
y -= 200;
|
||||
}
|
||||
for (int x = _pictureWidth - 200; x - 120 > 0; x -= _placeSizeHeight + 75)
|
||||
{
|
||||
_collection?.Get(count)?.SetPictureSize(_pictureWidth, _pictureHeight);
|
||||
_collection?.Get(count)?.SetPosition(x, y);
|
||||
count++;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
34
ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs
Normal file
34
ProjectSeaplane/ProjectSeaplane/Drawnings/DirectionType.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
{
|
||||
/// <summary>
|
||||
/// Неизвестное направление
|
||||
/// </summary>
|
||||
Unknown = -1,
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
/// </summary>
|
||||
|
||||
Up = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Вниз
|
||||
/// </summary>
|
||||
|
||||
Down = 2,
|
||||
|
||||
/// <summary>
|
||||
/// Влево
|
||||
/// </summary>
|
||||
|
||||
Left = 3,
|
||||
|
||||
/// <summary>
|
||||
/// Вправо
|
||||
/// </summary>
|
||||
|
||||
Right = 4,
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Отрисовка и перемещение
|
||||
/// </summary>
|
||||
public class DrawingSeaplane
|
||||
using ProjectSeaplane.Entities;
|
||||
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
|
||||
public class DrawingBasicSeaplane
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntitySeaplane? EntitySeaplane { get; private set; }
|
||||
public EntityBasicSeaplane? EntityBasicSeaplane { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@@ -22,41 +22,77 @@ public class DrawingSeaplane
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosX;
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки автомобиля
|
||||
/// </summary>
|
||||
private int? _startPosY;
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneWidth = 155;
|
||||
private readonly int _drawningSeaplaneWidth = 170;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneHeight = 70;
|
||||
private readonly int _drawningSeaplaneHeight = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Инициализация свойств
|
||||
/// Координата X объекта
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="landingGear">Тип "шасси" (0 - поплавки, 1 - лодочный тип)</param>
|
||||
/// <param name="radar">Признак наличия радара </param>
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
|
||||
public int? GetPosX => _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Координата Y объекта
|
||||
/// </summary>
|
||||
public int? GetPosY => _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина объекта
|
||||
/// </summary>
|
||||
public int GetWidth => _drawningSeaplaneWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота объекта
|
||||
/// </summary>
|
||||
public int GetHeight => _drawningSeaplaneHeight;
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawingBasicSeaplane()
|
||||
{
|
||||
EntitySeaplane = new EntitySeaplane();
|
||||
EntitySeaplane.Init(speed, weight, bodyColor, additionalColor, landingGear, radar);
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public DrawingBasicSeaplane(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBasicSeaplane = new EntityBasicSeaplane(speed, weight, bodyColor);
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningSeaplaneWidth">Ширина прорисовки автомобиля</param>
|
||||
/// <param name="drawningSeaplaneHeight">Высота прорисовки автомобиля</param>
|
||||
|
||||
|
||||
protected DrawingBasicSeaplane(int drawningSeaplaneWidth, int drawningSeaplaneHeight) : this()
|
||||
{
|
||||
_drawningSeaplaneWidth = drawningSeaplaneWidth;
|
||||
_drawningSeaplaneHeight = drawningSeaplaneHeight;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Установка границ поля
|
||||
@@ -142,7 +178,7 @@ public class DrawingSeaplane
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBasicSeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -151,32 +187,32 @@ public class DrawingSeaplane
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntitySeaplane.Step > 0)
|
||||
if (_startPosX.Value - EntityBasicSeaplane.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntitySeaplane.Step;
|
||||
_startPosX -= (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntitySeaplane.Step > 0)
|
||||
if (_startPosY.Value - EntityBasicSeaplane.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntitySeaplane.Step;
|
||||
_startPosY -= (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
|
||||
if (_startPosX + (int)EntitySeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
|
||||
if (_startPosX + (int)EntityBasicSeaplane.Step < _pictureWidth - _drawningSeaplaneWidth)
|
||||
{
|
||||
_startPosX += (int)EntitySeaplane.Step;
|
||||
_startPosX += (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
|
||||
if (_startPosY + (int)EntitySeaplane.Step < _pictureHeight - _drawningSeaplaneHeight)
|
||||
if (_startPosY + (int)EntityBasicSeaplane.Step < _pictureHeight - _drawningSeaplaneHeight)
|
||||
{
|
||||
_startPosY += (int)EntitySeaplane.Step;
|
||||
_startPosY += (int)EntityBasicSeaplane.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@@ -188,16 +224,16 @@ public class DrawingSeaplane
|
||||
/// Прорисовка объекта
|
||||
/// </summary>
|
||||
/// <param name="g"></param>
|
||||
public void DrawTransport(Graphics g)
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntitySeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityBasicSeaplane == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Pen pen = new(Color.Black);
|
||||
Pen penKraya = new(Color.Black, 2);
|
||||
Brush additionalBrush = new SolidBrush(EntitySeaplane.AdditionalColor);
|
||||
|
||||
|
||||
|
||||
//Начинаем рисовать
|
||||
@@ -217,14 +253,11 @@ public class DrawingSeaplane
|
||||
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(EntitySeaplane.BodyColor);
|
||||
Brush brAdditional = new SolidBrush(EntitySeaplane.AdditionalColor);
|
||||
|
||||
//Кисти для основного цвета
|
||||
Brush brBody = new SolidBrush(EntityBasicSeaplane.BodyColor);
|
||||
Brush brBlack = new SolidBrush(Color.Black);
|
||||
Brush brWhity = new SolidBrush(Color.GhostWhite);
|
||||
//Хвост
|
||||
g.FillPolygon(brBody, Hvost);
|
||||
@@ -239,12 +272,12 @@ public class DrawingSeaplane
|
||||
|
||||
g.FillEllipse(brBody, _startPosX.Value - 5, _startPosY.Value + 30, 100, 24);
|
||||
g.DrawEllipse(penKraya, _startPosX.Value, _startPosY.Value + 27, 17, 6);
|
||||
g.FillEllipse(brAdditional, _startPosX.Value, _startPosY.Value + 27, 17, 6);
|
||||
g.FillEllipse(brBlack, _startPosX.Value, _startPosY.Value + 27, 17, 6);
|
||||
|
||||
|
||||
|
||||
//Крыло
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7);
|
||||
g.FillEllipse(brBlack, _startPosX.Value + 45, _startPosY.Value + 43, 50, 7);
|
||||
|
||||
//Иллюминаторы
|
||||
|
||||
@@ -256,41 +289,9 @@ public class DrawingSeaplane
|
||||
|
||||
}
|
||||
|
||||
|
||||
//Поплавки
|
||||
|
||||
if (EntitySeaplane.LandingGear)
|
||||
{
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 60, _startPosY.Value + 50, 20, 7);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 70, _startPosY.Value + 48, _startPosX.Value + 70, _startPosY.Value + 52);
|
||||
}
|
||||
else
|
||||
{
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 60, _startPosY.Value + 60, 70, 10);
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 10, _startPosY.Value + 60, 20, 10);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 20, _startPosY.Value + 53, _startPosX.Value + 20, _startPosY.Value + 63);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 110, _startPosY.Value + 53, _startPosX.Value + 90, _startPosY.Value + 63);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 70, _startPosY.Value + 53, _startPosX.Value + 90, _startPosY.Value + 63);
|
||||
}
|
||||
|
||||
if (EntitySeaplane.Radar)
|
||||
{
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 30, _startPosY.Value + 12, 40, 15);
|
||||
g.FillPolygon(brAdditional, Radar);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
//Пилоты
|
||||
g.FillEllipse(brWhity, _startPosX.Value + 115, _startPosY.Value + 34, 20, 8);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
71
ProjectSeaplane/ProjectSeaplane/Drawnings/DrawingSeaplane.cs
Normal file
71
ProjectSeaplane/ProjectSeaplane/Drawnings/DrawingSeaplane.cs
Normal file
@@ -0,0 +1,71 @@
|
||||
using ProjectSeaplane.Entities;
|
||||
|
||||
namespace ProjectSeaplane.Drawnings;
|
||||
/// <summary>
|
||||
/// Отрисовка и перемещение
|
||||
/// </summary>
|
||||
public class DrawingSeaplane : DrawingBasicSeaplane
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneWidth = 170;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки автомобиля
|
||||
/// </summary>
|
||||
private readonly int _drawningSeaplaneHeight = 90;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="landingGear">Тип "шасси" (0 - поплавки, 1 - лодочный тип)</param>
|
||||
/// <param name="radar">Признак наличия радара </param>
|
||||
public DrawingSeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(155, 70)
|
||||
{
|
||||
EntityBasicSeaplane = new EntitySeaplane(speed, weight, bodyColor, additionalColor, landingGear, radar);
|
||||
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBasicSeaplane == null || EntityBasicSeaplane is not EntitySeaplane seaplane || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
Brush brAdditional = new SolidBrush(seaplane.AdditionalColor);
|
||||
Pen penKraya = new(Color.Black, 2);
|
||||
if (seaplane.LandingGear)
|
||||
{
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 60, _startPosY.Value + 60, 70, 10);
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 10, _startPosY.Value + 60, 20, 10);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 20, _startPosY.Value + 53, _startPosX.Value + 20, _startPosY.Value + 63);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 110, _startPosY.Value + 53, _startPosX.Value + 90, _startPosY.Value + 63);
|
||||
g.DrawLine(penKraya, _startPosX.Value + 70, _startPosY.Value + 53, _startPosX.Value + 90, _startPosY.Value + 63);
|
||||
}
|
||||
|
||||
//Чет надо но не понял
|
||||
base.DrawTransport(g);
|
||||
//also
|
||||
if (seaplane.Radar)
|
||||
{
|
||||
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
|
||||
};
|
||||
g.FillEllipse(brAdditional, _startPosX.Value + 30, _startPosY.Value + 12, 40, 15);
|
||||
g.FillPolygon(brAdditional, Radar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,37 @@
|
||||
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>
|
||||
|
||||
public EntityBasicSeaplane(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
||||
|
||||
37
ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs
Normal file
37
ProjectSeaplane/ProjectSeaplane/Entities/EntitySeaplane.cs
Normal file
@@ -0,0 +1,37 @@
|
||||
|
||||
namespace ProjectSeaplane.Entities;
|
||||
/// <summary>
|
||||
/// Класс-сущность "Гидросамолет"
|
||||
/// </summary>
|
||||
public class EntitySeaplane : EntityBasicSeaplane
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Дополнительный (для опциональных частей)
|
||||
/// </summary>
|
||||
public Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Тип "шасси" (0 - лодочный, 1 - поплавковый)
|
||||
/// </summary>
|
||||
public bool LandingGear { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="additionalColor">Дополнительный цвет</param>
|
||||
/// <param name="landingGear">Тип "шасси"</param>
|
||||
/// <param name="radar">При</param>
|
||||
|
||||
public EntitySeaplane(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar) : base(speed, weight, bodyColor)
|
||||
{
|
||||
|
||||
AdditionalColor = additionalColor;
|
||||
LandingGear = landingGear;
|
||||
Radar = radar;
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,54 +0,0 @@
|
||||
namespace ProjectSeaplane;
|
||||
/// <summary>
|
||||
/// Класс-сущность Гидросамолета
|
||||
/// </summary>
|
||||
public class EntitySeaplane
|
||||
{
|
||||
/// <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 Color AdditionalColor { get; private set; }
|
||||
/// <summary>
|
||||
/// Тип "шасси" (0 - лодочный, 1 - поплавковый)
|
||||
/// </summary>
|
||||
public bool LandingGear { get; private set; }
|
||||
/// <summary>
|
||||
/// Признак наличия радара
|
||||
/// </summary>
|
||||
public bool Radar { 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 void Init(int speed, double weight, Color bodyColor, Color additionalColor, bool landingGear, bool radar)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
AdditionalColor = additionalColor;
|
||||
LandingGear = landingGear;
|
||||
Radar = radar;
|
||||
|
||||
}
|
||||
}
|
||||
178
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
generated
Normal file
178
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.Designer.cs
generated
Normal file
@@ -0,0 +1,178 @@
|
||||
namespace ProjectSeaplane
|
||||
{
|
||||
partial class FormPlaneCollection
|
||||
{
|
||||
/// <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();
|
||||
buttonRefresh = new Button();
|
||||
buttonGoToCheck = new Button();
|
||||
buttonDelSeaplane = new Button();
|
||||
maskedTextBox = new MaskedTextBox();
|
||||
buttonAddSeaplane = new Button();
|
||||
buttonAddBasicSeaplane = new Button();
|
||||
СomboBoxSelectorCompany = new ComboBox();
|
||||
pictureBox = new PictureBox();
|
||||
groupBoxTools.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
// groupBoxTools
|
||||
//
|
||||
groupBoxTools.Controls.Add(buttonRefresh);
|
||||
groupBoxTools.Controls.Add(buttonGoToCheck);
|
||||
groupBoxTools.Controls.Add(buttonDelSeaplane);
|
||||
groupBoxTools.Controls.Add(maskedTextBox);
|
||||
groupBoxTools.Controls.Add(buttonAddSeaplane);
|
||||
groupBoxTools.Controls.Add(buttonAddBasicSeaplane);
|
||||
groupBoxTools.Controls.Add(СomboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(854, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(180, 398);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonRefresh.FlatStyle = FlatStyle.Flat;
|
||||
buttonRefresh.Location = new Point(6, 474);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(168, 43);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonGoToCheck.FlatStyle = FlatStyle.Flat;
|
||||
buttonGoToCheck.Location = new Point(6, 353);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(168, 43);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// buttonDelSeaplane
|
||||
//
|
||||
buttonDelSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonDelSeaplane.FlatStyle = FlatStyle.Flat;
|
||||
buttonDelSeaplane.Location = new Point(6, 249);
|
||||
buttonDelSeaplane.Name = "buttonDelSeaplane";
|
||||
buttonDelSeaplane.Size = new Size(168, 43);
|
||||
buttonDelSeaplane.TabIndex = 4;
|
||||
buttonDelSeaplane.Text = "Удалить самолет";
|
||||
buttonDelSeaplane.UseVisualStyleBackColor = true;
|
||||
buttonDelSeaplane.Click += ButtonnDelSeaplane_Click;
|
||||
//
|
||||
// maskedTextBox
|
||||
//
|
||||
maskedTextBox.Location = new Point(6, 220);
|
||||
maskedTextBox.Mask = "00";
|
||||
maskedTextBox.Name = "maskedTextBox";
|
||||
maskedTextBox.Size = new Size(168, 23);
|
||||
maskedTextBox.TabIndex = 3;
|
||||
maskedTextBox.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddSeaplane
|
||||
//
|
||||
buttonAddSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddSeaplane.FlatStyle = FlatStyle.Flat;
|
||||
buttonAddSeaplane.Location = new Point(6, 135);
|
||||
buttonAddSeaplane.Name = "buttonAddSeaplane";
|
||||
buttonAddSeaplane.Size = new Size(168, 43);
|
||||
buttonAddSeaplane.TabIndex = 2;
|
||||
buttonAddSeaplane.Text = "Добавление гидросамолета";
|
||||
buttonAddSeaplane.UseVisualStyleBackColor = true;
|
||||
buttonAddSeaplane.Click += ButtonAddSeaplane_Click;
|
||||
//
|
||||
// buttonAddBasicSeaplane
|
||||
//
|
||||
buttonAddBasicSeaplane.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
buttonAddBasicSeaplane.FlatStyle = FlatStyle.Flat;
|
||||
buttonAddBasicSeaplane.Location = new Point(6, 86);
|
||||
buttonAddBasicSeaplane.Name = "buttonAddBasicSeaplane";
|
||||
buttonAddBasicSeaplane.Size = new Size(168, 43);
|
||||
buttonAddBasicSeaplane.TabIndex = 1;
|
||||
buttonAddBasicSeaplane.Text = "Добавление самолета";
|
||||
buttonAddBasicSeaplane.UseVisualStyleBackColor = true;
|
||||
buttonAddBasicSeaplane.Click += ButtonAddBasicSeaplane_Click;
|
||||
//
|
||||
// СomboBoxSelectorCompany
|
||||
//
|
||||
СomboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
СomboBoxSelectorCompany.FormattingEnabled = true;
|
||||
СomboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
СomboBoxSelectorCompany.Location = new Point(6, 22);
|
||||
СomboBoxSelectorCompany.Name = "СomboBoxSelectorCompany";
|
||||
СomboBoxSelectorCompany.Size = new Size(168, 23);
|
||||
СomboBoxSelectorCompany.TabIndex = 0;
|
||||
СomboBoxSelectorCompany.SelectedIndexChanged += СomboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(854, 398);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormPlaneCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1034, 398);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormPlaneCollection";
|
||||
Text = "Коллекция самолетов";
|
||||
Load += FormPlaneCollection_Load;
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private Button buttonAddBasicSeaplane;
|
||||
private ComboBox СomboBoxSelectorCompany;
|
||||
private Button buttonAddSeaplane;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonDelSeaplane;
|
||||
private MaskedTextBox maskedTextBox;
|
||||
private PictureBox pictureBox;
|
||||
private Button buttonRefresh;
|
||||
}
|
||||
}
|
||||
193
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
Normal file
193
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.cs
Normal file
@@ -0,0 +1,193 @@
|
||||
using ProjectSeaplane.CollectionGenericObjects;
|
||||
using ProjectSeaplane.Drawnings;
|
||||
namespace ProjectSeaplane;
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormPlaneCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormPlaneCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void СomboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (СomboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new PlanePark(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawingBasicSeaplane>());
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление обычного самолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddBasicSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBasicSeaplane));
|
||||
|
||||
/// <summary>
|
||||
/// Добавление гидросамолета
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddSeaplane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingSeaplane));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new();
|
||||
DrawingBasicSeaplane drawingBasicSeaplane;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawingBasicSeaplane):
|
||||
drawingBasicSeaplane = new DrawingBasicSeaplane(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawingSeaplane):
|
||||
// TODO вызов диалогового окна для выбора цвета
|
||||
drawingBasicSeaplane = new DrawingSeaplane(random.Next(100, 300), random.Next(1000, 3000),
|
||||
GetColor(random), GetColor(random),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawingBasicSeaplane != -1)
|
||||
{
|
||||
MessageBox.Show("Объект добавлен");
|
||||
pictureBox.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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Удаление объекта
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonnDelSeaplane_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int pos = Convert.ToInt32(maskedTextBox.Text);
|
||||
if (_company - pos != null)
|
||||
{
|
||||
MessageBox.Show("Объект удален");
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
else
|
||||
{
|
||||
MessageBox.Show("Не удалось удалить объект");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Передача объекта в другую форму
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonGoToCheck_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DrawingBasicSeaplane? seaplane = null;
|
||||
int counter = 100;
|
||||
while (seaplane == null)
|
||||
{
|
||||
seaplane = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (seaplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormSeaplane form = new()
|
||||
{
|
||||
SetSeaplane = seaplane
|
||||
};
|
||||
form.ShowDialog();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перерисовка коллекции
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonRefresh_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
pictureBox.Image = _company.Show();
|
||||
}
|
||||
|
||||
private void FormPlaneCollection_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
120
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx
Normal file
120
ProjectSeaplane/ProjectSeaplane/FormPlaneCollection.resx
Normal file
@@ -0,0 +1,120 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" use="required" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
<xsd:attribute ref="xml:space" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
||||
@@ -29,11 +29,12 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxSeaplane = new PictureBox();
|
||||
buttonCreate = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxSeaplane).BeginInit();
|
||||
SuspendLayout();
|
||||
//
|
||||
@@ -42,28 +43,17 @@
|
||||
pictureBoxSeaplane.Dock = DockStyle.Fill;
|
||||
pictureBoxSeaplane.Location = new Point(0, 0);
|
||||
pictureBoxSeaplane.Name = "pictureBoxSeaplane";
|
||||
pictureBoxSeaplane.Size = new Size(590, 379);
|
||||
pictureBoxSeaplane.Size = new Size(757, 379);
|
||||
pictureBoxSeaplane.TabIndex = 0;
|
||||
pictureBoxSeaplane.TabStop = false;
|
||||
//
|
||||
// buttonCreate
|
||||
//
|
||||
buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreate.Location = new Point(12, 349);
|
||||
buttonCreate.Name = "buttonCreate";
|
||||
buttonCreate.Size = new Size(75, 23);
|
||||
buttonCreate.TabIndex = 1;
|
||||
buttonCreate.Text = "Создать";
|
||||
buttonCreate.UseVisualStyleBackColor = true;
|
||||
buttonCreate.Click += ButtonCreate_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
buttonLeft.BackColor = Color.Snow;
|
||||
buttonLeft.BackgroundImage = Properties.Resources.arrow11;
|
||||
buttonLeft.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonLeft.Location = new Point(465, 337);
|
||||
buttonLeft.Location = new Point(632, 337);
|
||||
buttonLeft.Name = "buttonLeft";
|
||||
buttonLeft.Size = new Size(35, 35);
|
||||
buttonLeft.TabIndex = 2;
|
||||
@@ -76,7 +66,7 @@
|
||||
buttonDown.BackColor = Color.Snow;
|
||||
buttonDown.BackgroundImage = Properties.Resources.arrow4;
|
||||
buttonDown.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonDown.Location = new Point(506, 337);
|
||||
buttonDown.Location = new Point(673, 337);
|
||||
buttonDown.Name = "buttonDown";
|
||||
buttonDown.Size = new Size(35, 35);
|
||||
buttonDown.TabIndex = 4;
|
||||
@@ -89,7 +79,7 @@
|
||||
buttonUp.BackColor = Color.Snow;
|
||||
buttonUp.BackgroundImage = Properties.Resources.arrow2;
|
||||
buttonUp.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonUp.Location = new Point(506, 297);
|
||||
buttonUp.Location = new Point(673, 297);
|
||||
buttonUp.Name = "buttonUp";
|
||||
buttonUp.Size = new Size(35, 35);
|
||||
buttonUp.TabIndex = 5;
|
||||
@@ -102,23 +92,44 @@
|
||||
buttonRight.BackColor = Color.Snow;
|
||||
buttonRight.BackgroundImage = Properties.Resources.arrow3;
|
||||
buttonRight.BackgroundImageLayout = ImageLayout.Stretch;
|
||||
buttonRight.Location = new Point(547, 337);
|
||||
buttonRight.Location = new Point(714, 337);
|
||||
buttonRight.Name = "buttonRight";
|
||||
buttonRight.Size = new Size(35, 35);
|
||||
buttonRight.TabIndex = 7;
|
||||
buttonRight.UseVisualStyleBackColor = false;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxStrategy.FormattingEnabled = true;
|
||||
comboBoxStrategy.Items.AddRange(new object[] { "К центру", "К краю" });
|
||||
comboBoxStrategy.Location = new Point(632, 12);
|
||||
comboBoxStrategy.Name = "comboBoxStrategy";
|
||||
comboBoxStrategy.Size = new Size(113, 23);
|
||||
comboBoxStrategy.TabIndex = 9;
|
||||
//
|
||||
// buttonStrategyStep
|
||||
//
|
||||
buttonStrategyStep.Location = new Point(673, 41);
|
||||
buttonStrategyStep.Name = "buttonStrategyStep";
|
||||
buttonStrategyStep.Size = new Size(72, 27);
|
||||
buttonStrategyStep.TabIndex = 10;
|
||||
buttonStrategyStep.Text = "Шаг";
|
||||
buttonStrategyStep.UseVisualStyleBackColor = true;
|
||||
buttonStrategyStep.Click += buttonStrategyStep_Click;
|
||||
//
|
||||
// FormSeaplane
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(7F, 15F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(590, 379);
|
||||
ClientSize = new Size(757, 379);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreate);
|
||||
Controls.Add(pictureBoxSeaplane);
|
||||
Name = "FormSeaplane";
|
||||
Text = "Гидросамолет";
|
||||
@@ -129,10 +140,11 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxSeaplane;
|
||||
private Button buttonCreate;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,7 @@
|
||||
namespace ProjectSeaplane
|
||||
using ProjectSeaplane.Drawnings;
|
||||
using ProjectSeaplane.MovementStrategy;
|
||||
|
||||
namespace ProjectSeaplane
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Гидросамолет"
|
||||
/// </summary>
|
||||
@@ -11,14 +14,30 @@
|
||||
public FormSeaplane()
|
||||
{
|
||||
InitializeComponent();
|
||||
_strategy = null;
|
||||
}
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawingSeaplane? _drawingSeaplane;
|
||||
private DrawingBasicSeaplane? _drawingSeaplane;
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
/// <summary>
|
||||
/// Метод прорисовки самолета
|
||||
/// </summary>
|
||||
public DrawingBasicSeaplane SetSeaplane
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawingSeaplane = value;
|
||||
_drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawingSeaplane == null)
|
||||
@@ -31,24 +50,7 @@
|
||||
_drawingSeaplane.DrawTransport(gr);
|
||||
pictureBoxSeaplane.Image = bmp;
|
||||
}
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreate_Click(object sender, EventArgs e)
|
||||
{
|
||||
Random random = new();
|
||||
_drawingSeaplane = new DrawingSeaplane();
|
||||
_drawingSeaplane.Init(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
|
||||
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
|
||||
_drawingSeaplane.SetPictureSize(pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
_drawingSeaplane.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
|
||||
Draw();
|
||||
}
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@@ -84,7 +86,48 @@
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void buttonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawingSeaplane == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (comboBoxStrategy.Enabled)
|
||||
{
|
||||
_strategy = comboBoxStrategy.SelectedIndex switch
|
||||
{
|
||||
0 => new MoveToCenter(),
|
||||
1 => new MoveToBorder(),
|
||||
_ => null,
|
||||
};
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableSeaplane(_drawingSeaplane), pictureBoxSeaplane.Width, pictureBoxSeaplane.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
comboBoxStrategy.Enabled = false;
|
||||
_strategy.MakeStep();
|
||||
Draw();
|
||||
|
||||
if (_strategy.GetStatus() == StrategyStatus.Finish)
|
||||
{
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,141 @@
|
||||
|
||||
|
||||
namespace ProjectSeaplane.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 ProjectSeaplane.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);
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
namespace ProjectSeaplane.MovementStrategy;
|
||||
|
||||
public class MoveToBorder : AbstractStrategy
|
||||
{
|
||||
protected override bool IsTargetDestinaion()
|
||||
{
|
||||
ObjectParameters? objParams = GetObjectParameters;
|
||||
if (objParams == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return objParams.RightBorder <= FieldWidth &&
|
||||
objParams.RightBorder + GetStep() >= FieldWidth &&
|
||||
objParams.DownBorder <= 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();
|
||||
}
|
||||
if (diffX < 0)
|
||||
{
|
||||
MoveRight();
|
||||
}
|
||||
}
|
||||
int diffY = objParams.DownBorder - FieldWidth;
|
||||
if (Math.Abs(diffY) > GetStep())
|
||||
{
|
||||
|
||||
if (diffX > 0)
|
||||
{
|
||||
MoveUp();
|
||||
}
|
||||
if (diffY < 0)
|
||||
{
|
||||
MoveDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
namespace ProjectSeaplane.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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
using ProjectSeaplane.Drawnings;
|
||||
|
||||
|
||||
|
||||
namespace ProjectSeaplane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием Seaplane
|
||||
/// </summary>
|
||||
public class MoveableSeaplane : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса Seaplane или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawingBasicSeaplane? _seaplane = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="seaplane">Объект класса Seaplane</param>
|
||||
public MoveableSeaplane(DrawingBasicSeaplane Seaplane)
|
||||
{
|
||||
_seaplane = Seaplane;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_seaplane == null || _seaplane.EntityBasicSeaplane == null || !_seaplane.GetPosX.HasValue || !_seaplane.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_seaplane.GetPosX.Value, _seaplane.GetPosY.Value, _seaplane.GetWidth, _seaplane.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_seaplane?.EntityBasicSeaplane?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_seaplane == null || _seaplane.EntityBasicSeaplane == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _seaplane.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.Unknown,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
namespace ProjectSeaplane;
|
||||
|
||||
namespace ProjectSeaplane.MovementStrategy;
|
||||
/// <summary>
|
||||
/// Направление перемещения
|
||||
/// </summary>
|
||||
public enum DirectionType
|
||||
public enum MovementDirection
|
||||
{
|
||||
/// <summary>
|
||||
/// Вверх
|
||||
@@ -0,0 +1,72 @@
|
||||
namespace ProjectSeaplane.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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
namespace ProjectSeaplane.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Статус выполнения операции перемещения
|
||||
/// </summary>
|
||||
public enum StrategyStatus
|
||||
{
|
||||
/// <summary>
|
||||
/// Все готово к началу
|
||||
/// </summary>
|
||||
NotInit,
|
||||
|
||||
/// <summary>
|
||||
/// Выполняется
|
||||
/// </summary>
|
||||
InProgress,
|
||||
|
||||
/// <summary>
|
||||
/// Завершено
|
||||
/// </summary>
|
||||
Finish
|
||||
}
|
||||
@@ -11,7 +11,7 @@ namespace ProjectSeaplane
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormSeaplane());
|
||||
Application.Run(new FormPlaneCollection());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user