Pi-12_Kukushkina_E.O._LabWork03_Simple #3
@ -0,0 +1,116 @@
|
||||
using ProjectExcavator.Drawnings;
|
||||
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Абстракция компании, хранящий коллекцию экскаваторов/Гусеничных машин
|
||||
/// </summary>
|
||||
public abstract class AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Размер места (ширина)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeWidth = 180;
|
||||
|
||||
/// <summary>
|
||||
/// Размер места (высота)
|
||||
/// </summary>
|
||||
protected readonly int _placeSizeHeight = 60;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureWidth;
|
||||
|
||||
/// <summary>
|
||||
/// Высота окна
|
||||
/// </summary>
|
||||
protected readonly int _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Коллекция экскаваторов/Гусеничных машин
|
||||
/// </summary>
|
||||
protected ICollectionGenericObjects<DrawningTrackedVehicle>? _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<DrawningTrackedVehicle> collection)
|
||||
{
|
||||
_pictureWidth = picWidth;
|
||||
_pictureHeight = picHeight;
|
||||
_collection = collection;
|
||||
_collection.SetMaxCount = GetMaxCount;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора сложения для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="excavator">Добавляемый объект</param>
|
||||
/// <returns></returns>
|
||||
public static int operator +(AbstractCompany company, DrawningTrackedVehicle excavator)
|
||||
{
|
||||
return company._collection.Insert(excavator);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Перегрузка оператора удаления для класса
|
||||
/// </summary>
|
||||
/// <param name="company">Компания</param>
|
||||
/// <param name="position">Номер удаляемого объекта</param>
|
||||
/// <returns></returns>
|
||||
public static DrawningTrackedVehicle operator -(AbstractCompany company, int position)
|
||||
{
|
||||
return company._collection.Remove(position);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Получение случайного объекта из коллекции
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public DrawningTrackedVehicle? 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)
|
||||
{
|
||||
DrawningTrackedVehicle? 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,68 @@
|
||||
using ProjectExcavator.Drawnings;
|
||||
|
||||
namespace ProjectExcavator.CollectionGenericObjects;
|
||||
|
||||
/// <summary>
|
||||
/// Реализация абстрактной компании - Гараж
|
||||
/// </summary>
|
||||
internal class GarageService : AbstractCompany
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="picWidth"></param>
|
||||
/// <param name="picHeight"></param>
|
||||
/// <param name="collection"></param>
|
||||
public GarageService(int picWidth, int picHeight, ICollectionGenericObjects<DrawningTrackedVehicle> collection) : base(picWidth, picHeight, collection)
|
||||
{
|
||||
}
|
||||
|
||||
protected override void DrawBackgound(Graphics g)
|
||||
{
|
||||
Pen pen = new Pen(Color.Black, 3f);
|
||||
|
||||
|
||||
int PlaceWidth = _pictureWidth / _placeSizeWidth;
|
||||
int PlaceHeight = _pictureHeight / _placeSizeHeight;
|
||||
int Indent = 20;
|
||||
|
||||
|
||||
for (int i = 0; i < PlaceHeight / 2; i++)
|
||||
{
|
||||
g.DrawLine(pen, Indent , i * _placeSizeHeight * 2, PlaceWidth * _placeSizeWidth + Indent, i * _placeSizeHeight * 2);
|
||||
for (int j = 0; j < PlaceWidth + 1; ++j)
|
||||
{
|
||||
g.DrawLine(pen, j * _placeSizeWidth + Indent, i * _placeSizeHeight * 2, j * _placeSizeWidth + Indent, i * _placeSizeHeight * 2 + _placeSizeHeight);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void SetObjectsPosition()
|
||||
{
|
||||
|
||||
int col = _collection?.Count ?? 0;
|
||||
|
||||
int LevelWidth = 0;
|
||||
int LevelHeight = 0;
|
||||
|
||||
for (int i = 0; i < col; i++)
|
||||
{
|
||||
if (LevelHeight + 1 > _pictureHeight/ (_placeSizeHeight + 60))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_collection?.Get(i)?.SetPosition((_pictureWidth - 190) - _placeSizeWidth * LevelWidth, 20 + (_placeSizeHeight + 60) * LevelHeight );
|
||||
|
||||
if (LevelWidth + 1 < _pictureWidth / _placeSizeWidth)
|
||||
{
|
||||
LevelWidth++;
|
||||
}
|
||||
else
|
||||
{
|
||||
LevelWidth = 0;
|
||||
LevelHeight++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,48 @@
|
||||
namespace ProjectExcavator.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,133 @@
|
||||
namespace ProjectExcavator.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)
|
||||
{
|
||||
//Проверка позиции
|
||||
|
||||
if (position < 0 || position > Count-1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
return _collection[position];
|
||||
}
|
||||
}
|
||||
|
||||
public int Insert(T obj)
|
||||
{
|
||||
//Вставка в свободное место набора
|
||||
|
||||
for (int i = 0; i < Count -1; i++)
|
||||
|
||||
{
|
||||
if (_collection[i] == null)
|
||||
{
|
||||
_collection[i] = obj;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public int Insert(T obj, int position)
|
||||
{
|
||||
//Проверка позиции
|
||||
//Проверка, что элемент массива по этой позиции пустой, если нет, то
|
||||
//Ищется свободное место после этой позиции и идет вставка туда
|
||||
//если нет после, ищем до вставка
|
||||
|
||||
if (position >= Count || position < 0) return -1;
|
||||
|
||||
if (_collection[position] == null)
|
||||
{
|
||||
_collection[position] = obj;
|
||||
return position;
|
||||
}
|
||||
else
|
||||
{
|
||||
int after_position = position + 1;
|
||||
while (after_position < Count)
|
||||
{
|
||||
if (_collection[after_position] == null)
|
||||
{
|
||||
_collection[after_position] = obj;
|
||||
return after_position;
|
||||
}
|
||||
after_position ++;
|
||||
}
|
||||
|
||||
int behind_position = position - 1;
|
||||
while (behind_position >= 0)
|
||||
{
|
||||
if (_collection[behind_position] == null)
|
||||
{
|
||||
_collection[behind_position] = obj;
|
||||
return behind_position;
|
||||
}
|
||||
behind_position --;
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public T? Remove(int position)
|
||||
{
|
||||
// Проверка позиции
|
||||
// Удаление объекта из массива, присвоив элементу массива значение null
|
||||
|
||||
T? obj = _collection[position];
|
||||
if (position < 0 || _collection[position] == null || position > Count -1)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
_collection[position] = null;
|
||||
return obj;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -5,7 +5,7 @@ namespace ProjectExcavator.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningExcavator : DrawningBaseExcavator
|
||||
public class DrawningExcavator : DrawningTrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
@ -18,12 +18,12 @@ public class DrawningExcavator : DrawningBaseExcavator
|
||||
/// <param name="supports">Признак наличия поддержки</param>
|
||||
public DrawningExcavator(int speed, double weight, Color bodyColor, Color additionalColor, bool bucket, bool supports) : base(135, 82)
|
||||
{
|
||||
EntityBaseExcavator = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
|
||||
EntityTrackedVehicle = new EntityExcavator(speed, weight, bodyColor, additionalColor, bucket, supports);
|
||||
}
|
||||
|
||||
public override void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBaseExcavator == null|| EntityBaseExcavator is not EntityExcavator excavator || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTrackedVehicle == null|| EntityTrackedVehicle is not EntityExcavator excavator || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -5,12 +5,12 @@ namespace ProjectExcavator.Drawnings;
|
||||
/// <summary>
|
||||
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
||||
/// </summary>
|
||||
public class DrawningBaseExcavator
|
||||
public class DrawningTrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Класс-сущность
|
||||
/// </summary>
|
||||
public EntityBaseExcavator? EntityBaseExcavator { get; protected set; }
|
||||
public TrackedVehicle? EntityTrackedVehicle { get; protected set; }
|
||||
|
||||
/// <summary>
|
||||
/// Ширина окна
|
||||
@ -23,22 +23,22 @@ public class DrawningBaseExcavator
|
||||
private int? _pictureHeight;
|
||||
|
||||
/// <summary>
|
||||
/// Левая координата прорисовки Экскаватора
|
||||
/// Левая координата прорисовки Гусеничной машины
|
||||
/// </summary>
|
||||
protected int? _startPosX;
|
||||
|
||||
/// <summary>
|
||||
/// Верхняя кооридната прорисовки Экскаватора
|
||||
/// Верхняя кооридната прорисовки гусеничной машины
|
||||
/// </summary>
|
||||
protected int? _startPosY;
|
||||
|
||||
/// <summary>
|
||||
/// Ширина прорисовки Экскаватора
|
||||
/// Ширина прорисовки гусеничной машины
|
||||
/// </summary>
|
||||
private readonly int _drawningExcavatorWidth = 78;
|
||||
|
||||
/// <summary>
|
||||
/// Высота прорисовки Экскаватора
|
||||
/// Высота прорисовки гусеничной машины
|
||||
/// </summary>
|
||||
private readonly int _drawningExcavatorHeight = 63;
|
||||
|
||||
@ -65,7 +65,7 @@ public class DrawningBaseExcavator
|
||||
/// <summary>
|
||||
/// Пустой конструктор
|
||||
/// </summary>
|
||||
private DrawningBaseExcavator()
|
||||
private DrawningTrackedVehicle()
|
||||
{
|
||||
_pictureWidth = null;
|
||||
_pictureHeight = null;
|
||||
@ -79,17 +79,17 @@ public class DrawningBaseExcavator
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
public DrawningBaseExcavator(int speed, double weight, Color bodyColor) : this()
|
||||
public DrawningTrackedVehicle(int speed, double weight, Color bodyColor) : this()
|
||||
{
|
||||
EntityBaseExcavator = new EntityBaseExcavator(speed, weight, bodyColor);
|
||||
EntityTrackedVehicle = new TrackedVehicle(speed, weight, bodyColor);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор для наследников
|
||||
/// </summary>
|
||||
/// <param name="drawningExcavatorWidth">Ширина прорисовки Экскаватора</param>
|
||||
/// <param name="drawningExcavatorHeight">Высота прорисовки Экскаватора</param>
|
||||
protected DrawningBaseExcavator(int drawningExcavatorWidth, int drawningExcavatorHeight) : this()
|
||||
/// <param name="drawningExcavatorWidth">Ширина прорисовки гусеничной машины</param>
|
||||
/// <param name="drawningExcavatorHeight">Высота прорисовки гусеничной машины</param>
|
||||
protected DrawningTrackedVehicle(int drawningExcavatorWidth, int drawningExcavatorHeight) : this()
|
||||
{
|
||||
_drawningExcavatorWidth = drawningExcavatorWidth;
|
||||
_drawningExcavatorHeight = drawningExcavatorHeight;
|
||||
@ -106,7 +106,7 @@ public class DrawningBaseExcavator
|
||||
//проверка, что объект "влезает" в размеры поля
|
||||
if (_drawningExcavatorWidth > width || _drawningExcavatorHeight > height)
|
||||
{
|
||||
EntityBaseExcavator = null;
|
||||
EntityTrackedVehicle = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -169,7 +169,7 @@ public class DrawningBaseExcavator
|
||||
/// <returns>true - перемещене выполнено, false - перемещение невозможно</returns>
|
||||
public bool MoveTransport(DirectionType direction)
|
||||
{
|
||||
if (EntityBaseExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -178,30 +178,30 @@ public class DrawningBaseExcavator
|
||||
{
|
||||
//влево
|
||||
case DirectionType.Left:
|
||||
if (_startPosX.Value - EntityBaseExcavator.Step > 0)
|
||||
if (_startPosX.Value - EntityTrackedVehicle.Step > 0)
|
||||
{
|
||||
_startPosX -= (int)EntityBaseExcavator.Step;
|
||||
_startPosX -= (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
//вверх
|
||||
case DirectionType.Up:
|
||||
if (_startPosY.Value - EntityBaseExcavator.Step > 0)
|
||||
if (_startPosY.Value - EntityTrackedVehicle.Step > 0)
|
||||
{
|
||||
_startPosY -= (int)EntityBaseExcavator.Step;
|
||||
_startPosY -= (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
// вправо
|
||||
case DirectionType.Right:
|
||||
if (_startPosX.Value + EntityBaseExcavator.Step < _pictureWidth - _drawningExcavatorWidth)
|
||||
if (_startPosX.Value + EntityTrackedVehicle.Step < _pictureWidth - _drawningExcavatorWidth)
|
||||
{
|
||||
_startPosX += (int)EntityBaseExcavator.Step;
|
||||
_startPosX += (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
//вниз
|
||||
case DirectionType.Down:
|
||||
if (_startPosY.Value + EntityBaseExcavator.Step < _pictureHeight - _drawningExcavatorHeight)
|
||||
if (_startPosY.Value + EntityTrackedVehicle.Step < _pictureHeight - _drawningExcavatorHeight)
|
||||
{
|
||||
_startPosY += (int)EntityBaseExcavator.Step;
|
||||
_startPosY += (int)EntityTrackedVehicle.Step;
|
||||
}
|
||||
return true;
|
||||
default:
|
||||
@ -215,7 +215,7 @@ public class DrawningBaseExcavator
|
||||
/// <param name="g"></param>
|
||||
public virtual void DrawTransport(Graphics g)
|
||||
{
|
||||
if (EntityBaseExcavator == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
if (EntityTrackedVehicle == null || !_startPosX.HasValue || !_startPosY.HasValue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -225,7 +225,7 @@ public class DrawningBaseExcavator
|
||||
Brush brBrown = new SolidBrush(Color.DarkSlateGray);
|
||||
|
||||
//контур и заливка основы
|
||||
Brush br = new SolidBrush(EntityBaseExcavator.BodyColor);
|
||||
Brush br = new SolidBrush(EntityTrackedVehicle.BodyColor);
|
||||
g.FillRectangle(br, _startPosX.Value + 51, _startPosY.Value, 25, 25);//кабина
|
||||
g.DrawRectangle(pen, _startPosX.Value + 51, _startPosY.Value, 25, 25);
|
||||
|
@ -3,7 +3,7 @@
|
||||
/// <summary>
|
||||
/// Класс-сущность "Экскаватор"
|
||||
/// </summary>
|
||||
public class EntityExcavator : EntityBaseExcavator
|
||||
public class EntityExcavator : TrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Дополнительный цвет (для опциональных элементов)
|
||||
|
@ -1,9 +1,9 @@
|
||||
namespace ProjectExcavator.Entities;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-сущность "Базовый Экскаватор"
|
||||
/// Класс-сущность "Гусеничная Машина"
|
||||
/// </summary>
|
||||
public class EntityBaseExcavator
|
||||
public class TrackedVehicle
|
||||
{
|
||||
/// <summary>
|
||||
/// Скорость
|
||||
@ -21,7 +21,7 @@ public class EntityBaseExcavator
|
||||
public Color BodyColor { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Шаг перемещения Экскаватора
|
||||
/// Шаг перемещения Экскаватора/Гусеничной машины
|
||||
/// </summary>
|
||||
public double Step => Speed * 100 / Weight;
|
||||
|
||||
@ -29,10 +29,10 @@ public class EntityBaseExcavator
|
||||
/// Конструктор сущности
|
||||
/// </summary>
|
||||
/// <param name="speed">Скорость</param>
|
||||
/// <param name="weight">Вес Экскаватора</param>
|
||||
/// <param name="weight">Вес</param>
|
||||
/// <param name="bodyColor">Основной цвет</param>
|
||||
|
||||
public EntityBaseExcavator(int speed, double weight, Color bodyColor)
|
||||
public TrackedVehicle(int speed, double weight, Color bodyColor)
|
||||
{
|
||||
Speed = speed;
|
||||
Weight = weight;
|
@ -29,12 +29,10 @@
|
||||
private void InitializeComponent()
|
||||
{
|
||||
pictureBoxExcavator = new PictureBox();
|
||||
buttonCreateExcavator = new Button();
|
||||
buttonLeft = new Button();
|
||||
buttonDown = new Button();
|
||||
buttonUp = new Button();
|
||||
buttonRight = new Button();
|
||||
ButtonCreateBaseExcavator = new Button();
|
||||
comboBoxStrategy = new ComboBox();
|
||||
buttonStrategyStep = new Button();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBoxExcavator).BeginInit();
|
||||
@ -49,16 +47,6 @@
|
||||
pictureBoxExcavator.TabIndex = 0;
|
||||
pictureBoxExcavator.TabStop = false;
|
||||
//
|
||||
// buttonCreateExcavator
|
||||
//
|
||||
buttonCreateExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
buttonCreateExcavator.Location = new Point(12, 540);
|
||||
buttonCreateExcavator.Name = "buttonCreateExcavator";
|
||||
buttonCreateExcavator.Size = new Size(250, 45);
|
||||
buttonCreateExcavator.TabIndex = 0;
|
||||
buttonCreateExcavator.Text = "Создать усиленный экскаватор";
|
||||
buttonCreateExcavator.Click += ButtonCreateExcavator_Click;
|
||||
//
|
||||
// buttonLeft
|
||||
//
|
||||
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
|
||||
@ -107,16 +95,6 @@
|
||||
buttonRight.UseVisualStyleBackColor = true;
|
||||
buttonRight.Click += ButtonMove_Click;
|
||||
//
|
||||
// ButtonCreateBaseExcavator
|
||||
//
|
||||
ButtonCreateBaseExcavator.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
|
||||
ButtonCreateBaseExcavator.Location = new Point(265, 540);
|
||||
ButtonCreateBaseExcavator.Name = "ButtonCreateBaseExcavator";
|
||||
ButtonCreateBaseExcavator.Size = new Size(250, 45);
|
||||
ButtonCreateBaseExcavator.TabIndex = 5;
|
||||
ButtonCreateBaseExcavator.Text = "Создать обычный экскаватор";
|
||||
ButtonCreateBaseExcavator.Click += ButtonCreateBaseExcavator_Click;
|
||||
//
|
||||
// comboBoxStrategy
|
||||
//
|
||||
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
|
||||
@ -146,12 +124,10 @@
|
||||
ClientSize = new Size(905, 597);
|
||||
Controls.Add(buttonStrategyStep);
|
||||
Controls.Add(comboBoxStrategy);
|
||||
Controls.Add(ButtonCreateBaseExcavator);
|
||||
Controls.Add(buttonRight);
|
||||
Controls.Add(buttonUp);
|
||||
Controls.Add(buttonDown);
|
||||
Controls.Add(buttonLeft);
|
||||
Controls.Add(buttonCreateExcavator);
|
||||
Controls.Add(pictureBoxExcavator);
|
||||
Name = "FormExcavator";
|
||||
Text = "Экскаватор";
|
||||
@ -162,12 +138,10 @@
|
||||
#endregion
|
||||
|
||||
private PictureBox pictureBoxExcavator;
|
||||
private Button buttonCreateExcavator;
|
||||
private Button buttonLeft;
|
||||
private Button buttonDown;
|
||||
private Button buttonUp;
|
||||
private Button buttonRight;
|
||||
private Button ButtonCreateBaseExcavator;
|
||||
private ComboBox comboBoxStrategy;
|
||||
private Button buttonStrategyStep;
|
||||
}
|
||||
|
@ -5,20 +5,35 @@ namespace ProjectExcavator;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Форма работы с объектом "Усиленный экскаватор"
|
||||
/// Форма работы с объектом "Экскаватор"
|
||||
/// </summary>
|
||||
public partial class FormExcavator : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект для прорисовки объекта
|
||||
/// </summary>
|
||||
private DrawningBaseExcavator? _drawningBaseExcavator;
|
||||
private DrawningTrackedVehicle? _drawningTrackedVehicle;
|
||||
|
||||
/// <summary>
|
||||
/// Стратегия перемещения
|
||||
/// </summary>
|
||||
private AbstractStrategy? _strategy;
|
||||
|
||||
/// <summary>
|
||||
/// Получение объекта
|
||||
/// </summary>
|
||||
public DrawningTrackedVehicle SetTrackedVehicle
|
||||
{
|
||||
set
|
||||
{
|
||||
_drawningTrackedVehicle = value;
|
||||
_drawningTrackedVehicle.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
comboBoxStrategy.Enabled = true;
|
||||
_strategy = null;
|
||||
Draw();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор формы
|
||||
/// </summary>
|
||||
@ -33,61 +48,17 @@ public partial class FormExcavator : Form
|
||||
/// </summary>
|
||||
private void Draw()
|
||||
{
|
||||
if (_drawningBaseExcavator == null)
|
||||
if (_drawningTrackedVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Bitmap bmp = new(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
Graphics gr = Graphics.FromImage(bmp);
|
||||
_drawningBaseExcavator.DrawTransport(gr);
|
||||
_drawningTrackedVehicle.DrawTransport(gr);
|
||||
pictureBoxExcavator.Image = bmp;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
Random random = new();
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningBaseExcavator):
|
||||
_drawningBaseExcavator = new DrawningBaseExcavator(random.Next(100, 300), random.Next(1000, 3000),
|
||||
Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
|
||||
break;
|
||||
case nameof(DrawningExcavator):
|
||||
_drawningBaseExcavator = new DrawningExcavator(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)));
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
_drawningBaseExcavator.SetPictureSize(pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_drawningBaseExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
|
||||
_strategy = null;
|
||||
comboBoxStrategy.Enabled = true;
|
||||
Draw();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия кнопки "Создать усиленный экскаватор"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningExcavator));
|
||||
|
||||
/// <summary>
|
||||
/// Обработка нажатия "Создать обычный экскаватор"
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonCreateBaseExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBaseExcavator));
|
||||
|
||||
/// <summary>
|
||||
/// Перемещение объекта по форме (нажатие кнопок навигации)
|
||||
/// </summary>
|
||||
@ -95,7 +66,7 @@ public partial class FormExcavator : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonMove_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBaseExcavator == null)
|
||||
if (_drawningTrackedVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -105,16 +76,16 @@ public partial class FormExcavator : Form
|
||||
switch (name)
|
||||
{
|
||||
case "buttonUp":
|
||||
result = _drawningBaseExcavator.MoveTransport(DirectionType.Up);
|
||||
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Up);
|
||||
break;
|
||||
case "buttonDown":
|
||||
result = _drawningBaseExcavator.MoveTransport(DirectionType.Down);
|
||||
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Down);
|
||||
break;
|
||||
case "buttonLeft":
|
||||
result = _drawningBaseExcavator.MoveTransport(DirectionType.Left);
|
||||
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Left);
|
||||
break;
|
||||
case "buttonRight":
|
||||
result = _drawningBaseExcavator.MoveTransport(DirectionType.Right);
|
||||
result = _drawningTrackedVehicle.MoveTransport(DirectionType.Right);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -132,7 +103,7 @@ public partial class FormExcavator : Form
|
||||
/// <param name="e"></param>
|
||||
private void ButtonStrategyStep_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (_drawningBaseExcavator == null)
|
||||
if (_drawningTrackedVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@ -149,7 +120,7 @@ public partial class FormExcavator : Form
|
||||
{
|
||||
return;
|
||||
}
|
||||
_strategy.SetData(new MoveableBaseExcavator(_drawningBaseExcavator), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
_strategy.SetData(new MoveableTrackedVehicle(_drawningTrackedVehicle), pictureBoxExcavator.Width, pictureBoxExcavator.Height);
|
||||
}
|
||||
|
||||
if (_strategy == null)
|
||||
|
168
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
168
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
generated
Normal file
@ -0,0 +1,168 @@
|
||||
namespace ProjectExcavator
|
||||
{
|
||||
partial class FormExcavatorCollection
|
||||
{
|
||||
/// <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();
|
||||
ButtonRemoveExcavator = new Button();
|
||||
maskedTextBoxPosition = new MaskedTextBox();
|
||||
buttonAddExcavator = new Button();
|
||||
buttonAddTrackedVehicle = new Button();
|
||||
comboBoxSelectorCompany = 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(ButtonRemoveExcavator);
|
||||
groupBoxTools.Controls.Add(maskedTextBoxPosition);
|
||||
groupBoxTools.Controls.Add(buttonAddExcavator);
|
||||
groupBoxTools.Controls.Add(buttonAddTrackedVehicle);
|
||||
groupBoxTools.Controls.Add(comboBoxSelectorCompany);
|
||||
groupBoxTools.Dock = DockStyle.Right;
|
||||
groupBoxTools.Location = new Point(777, 0);
|
||||
groupBoxTools.Name = "groupBoxTools";
|
||||
groupBoxTools.Size = new Size(225, 639);
|
||||
groupBoxTools.TabIndex = 0;
|
||||
groupBoxTools.TabStop = false;
|
||||
groupBoxTools.Text = "Инструменты";
|
||||
//
|
||||
// buttonRefresh
|
||||
//
|
||||
buttonRefresh.Location = new Point(13, 554);
|
||||
buttonRefresh.Name = "buttonRefresh";
|
||||
buttonRefresh.Size = new Size(200, 60);
|
||||
buttonRefresh.TabIndex = 6;
|
||||
buttonRefresh.Text = "Обновить";
|
||||
buttonRefresh.UseVisualStyleBackColor = true;
|
||||
buttonRefresh.Click += ButtonRefresh_Click;
|
||||
//
|
||||
// buttonGoToCheck
|
||||
//
|
||||
buttonGoToCheck.Location = new Point(13, 469);
|
||||
buttonGoToCheck.Name = "buttonGoToCheck";
|
||||
buttonGoToCheck.Size = new Size(200, 60);
|
||||
buttonGoToCheck.TabIndex = 5;
|
||||
buttonGoToCheck.Text = "Передать на тесты";
|
||||
buttonGoToCheck.UseVisualStyleBackColor = true;
|
||||
buttonGoToCheck.Click += ButtonGoToCheck_Click;
|
||||
//
|
||||
// ButtonRemoveExcavator
|
||||
//
|
||||
ButtonRemoveExcavator.Location = new Point(10, 386);
|
||||
ButtonRemoveExcavator.Name = "ButtonRemoveExcavator";
|
||||
ButtonRemoveExcavator.Size = new Size(200, 60);
|
||||
ButtonRemoveExcavator.TabIndex = 4;
|
||||
ButtonRemoveExcavator.Text = "Удаление транспорта";
|
||||
ButtonRemoveExcavator.UseVisualStyleBackColor = true;
|
||||
ButtonRemoveExcavator.Click += ButtonRemoveExcavator_Click;
|
||||
//
|
||||
// maskedTextBoxPosition
|
||||
//
|
||||
maskedTextBoxPosition.Location = new Point(13, 281);
|
||||
maskedTextBoxPosition.Mask = "00";
|
||||
maskedTextBoxPosition.Name = "maskedTextBoxPosition";
|
||||
maskedTextBoxPosition.Size = new Size(200, 27);
|
||||
maskedTextBoxPosition.TabIndex = 3;
|
||||
maskedTextBoxPosition.ValidatingType = typeof(int);
|
||||
//
|
||||
// buttonAddExcavator
|
||||
//
|
||||
buttonAddExcavator.Location = new Point(13, 164);
|
||||
buttonAddExcavator.Name = "buttonAddExcavator";
|
||||
buttonAddExcavator.Size = new Size(200, 65);
|
||||
buttonAddExcavator.TabIndex = 2;
|
||||
buttonAddExcavator.Text = "Добавление экскаватора";
|
||||
buttonAddExcavator.UseVisualStyleBackColor = true;
|
||||
buttonAddExcavator.Click += ButtonAddExcavator_Click;
|
||||
//
|
||||
// buttonAddTrackedVehicle
|
||||
//
|
||||
buttonAddTrackedVehicle.Location = new Point(10, 93);
|
||||
buttonAddTrackedVehicle.Name = "buttonAddTrackedVehicle";
|
||||
buttonAddTrackedVehicle.Size = new Size(200, 65);
|
||||
buttonAddTrackedVehicle.TabIndex = 1;
|
||||
buttonAddTrackedVehicle.Text = "Добавление гусеничной машины";
|
||||
buttonAddTrackedVehicle.UseVisualStyleBackColor = true;
|
||||
buttonAddTrackedVehicle.Click += ButtonAddTrackedVehicle_Click;
|
||||
//
|
||||
// comboBoxSelectorCompany
|
||||
//
|
||||
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
|
||||
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
|
||||
comboBoxSelectorCompany.FormattingEnabled = true;
|
||||
comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
|
||||
comboBoxSelectorCompany.Location = new Point(10, 26);
|
||||
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
|
||||
comboBoxSelectorCompany.Size = new Size(200, 28);
|
||||
comboBoxSelectorCompany.TabIndex = 0;
|
||||
comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged;
|
||||
//
|
||||
// pictureBox
|
||||
//
|
||||
pictureBox.Dock = DockStyle.Fill;
|
||||
pictureBox.Location = new Point(0, 0);
|
||||
pictureBox.Name = "pictureBox";
|
||||
pictureBox.Size = new Size(777, 639);
|
||||
pictureBox.TabIndex = 1;
|
||||
pictureBox.TabStop = false;
|
||||
//
|
||||
// FormExcavatorCollection
|
||||
//
|
||||
AutoScaleDimensions = new SizeF(8F, 20F);
|
||||
AutoScaleMode = AutoScaleMode.Font;
|
||||
ClientSize = new Size(1002, 639);
|
||||
Controls.Add(pictureBox);
|
||||
Controls.Add(groupBoxTools);
|
||||
Name = "FormExcavatorCollection";
|
||||
Text = "Коллекция экскаваторов";
|
||||
groupBoxTools.ResumeLayout(false);
|
||||
groupBoxTools.PerformLayout();
|
||||
((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
|
||||
ResumeLayout(false);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
private GroupBox groupBoxTools;
|
||||
private ComboBox comboBoxSelectorCompany;
|
||||
private Button buttonAddExcavator;
|
||||
private Button buttonAddTrackedVehicle;
|
||||
private PictureBox pictureBox;
|
||||
private Button ButtonRemoveExcavator;
|
||||
private MaskedTextBox maskedTextBoxPosition;
|
||||
private Button buttonGoToCheck;
|
||||
private Button buttonRefresh;
|
||||
}
|
||||
}
|
184
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
184
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
Normal file
@ -0,0 +1,184 @@
|
||||
using ProjectExcavator.CollectionGenericObjects;
|
||||
using ProjectExcavator.Drawnings;
|
||||
|
||||
namespace ProjectExcavator;
|
||||
/// <summary>
|
||||
/// Форма работы с компанией и ее коллекцией
|
||||
/// </summary>
|
||||
public partial class FormExcavatorCollection : Form
|
||||
{
|
||||
/// <summary>
|
||||
/// Компания
|
||||
/// </summary>
|
||||
private AbstractCompany? _company = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
public FormExcavatorCollection()
|
||||
{
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Выбор компании
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
switch (comboBoxSelectorCompany.Text)
|
||||
{
|
||||
case "Хранилище":
|
||||
_company = new GarageService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects<DrawningTrackedVehicle>());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Добавление гусеничной машины
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddTrackedVehicle_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningTrackedVehicle));
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Добавление экскаватора
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="e"></param>
|
||||
private void ButtonAddExcavator_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningExcavator));
|
||||
|
||||
/// <summary>
|
||||
/// Создание объекта класса-перемещения
|
||||
/// </summary>
|
||||
/// <param name="type">Тип создаваемого объекта</param>
|
||||
private void CreateObject(string type)
|
||||
{
|
||||
if (_company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Random random = new();
|
||||
DrawningTrackedVehicle drawningTrackedVehicle;
|
||||
switch (type)
|
||||
{
|
||||
case nameof(DrawningTrackedVehicle):
|
||||
drawningTrackedVehicle = new DrawningTrackedVehicle(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
|
||||
break;
|
||||
case nameof(DrawningExcavator):
|
||||
drawningTrackedVehicle = new DrawningExcavator(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random), true, true);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
if (_company + drawningTrackedVehicle != -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 ButtonRemoveExcavator_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
|
||||
{
|
||||
return;
|
||||
}
|
||||
int pos = Convert.ToInt32(maskedTextBoxPosition.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;
|
||||
}
|
||||
|
||||
DrawningTrackedVehicle? TrackedVehicle = null;
|
||||
int counter = 100;
|
||||
while (TrackedVehicle == null)
|
||||
{
|
||||
TrackedVehicle = _company.GetRandomObject();
|
||||
counter--;
|
||||
if (counter <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (TrackedVehicle == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
FormExcavator form = new()
|
||||
{
|
||||
SetTrackedVehicle = TrackedVehicle
|
||||
};
|
||||
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();
|
||||
}
|
||||
}
|
120
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
Normal file
120
ProjectExcavator/ProjectExcavator/FormExcavatorCollection.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>
|
@ -3,46 +3,46 @@
|
||||
namespace ProjectExcavator.MovementStrategy;
|
||||
|
||||
/// <summary>
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningBaseExcavator
|
||||
/// Класс-реализация IMoveableObject с использованием DrawningTrackedVehicle
|
||||
/// </summary>
|
||||
public class MoveableBaseExcavator : IMoveableObject
|
||||
public class MoveableTrackedVehicle : IMoveableObject
|
||||
{
|
||||
/// <summary>
|
||||
/// Поле-объект класса DrawningBaseExcavator или его наследника
|
||||
/// Поле-объект класса DrawningTrackedVehicle или его наследника
|
||||
/// </summary>
|
||||
private readonly DrawningBaseExcavator? _baseExcavator = null;
|
||||
private readonly DrawningTrackedVehicle? _TrackedVehicle = null;
|
||||
|
||||
/// <summary>
|
||||
/// Конструктор
|
||||
/// </summary>
|
||||
/// <param name="baseExcavator">Объект класса DrawningBaseExcavator</param>
|
||||
public MoveableBaseExcavator(DrawningBaseExcavator baseExcavator)
|
||||
/// <param name="TrackedVehicle">Объект класса DrawningTrackedVehicle</param>
|
||||
public MoveableTrackedVehicle(DrawningTrackedVehicle TrackedVehicle)
|
||||
{
|
||||
_baseExcavator = baseExcavator;
|
||||
_TrackedVehicle = TrackedVehicle;
|
||||
}
|
||||
|
||||
public ObjectParameters? GetObjectPosition
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_baseExcavator == null || _baseExcavator.EntityBaseExcavator == null || !_baseExcavator.GetPosX.HasValue || !_baseExcavator.GetPosY.HasValue)
|
||||
if (_TrackedVehicle == null || _TrackedVehicle.EntityTrackedVehicle == null || !_TrackedVehicle.GetPosX.HasValue || !_TrackedVehicle.GetPosY.HasValue)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return new ObjectParameters(_baseExcavator.GetPosX.Value, _baseExcavator.GetPosY.Value, _baseExcavator.GetWidth, _baseExcavator.GetHeight);
|
||||
return new ObjectParameters(_TrackedVehicle.GetPosX.Value, _TrackedVehicle.GetPosY.Value, _TrackedVehicle.GetWidth, _TrackedVehicle.GetHeight);
|
||||
}
|
||||
}
|
||||
|
||||
public int GetStep => (int)(_baseExcavator?.EntityBaseExcavator?.Step ?? 0);
|
||||
public int GetStep => (int)(_TrackedVehicle?.EntityTrackedVehicle?.Step ?? 0);
|
||||
|
||||
public bool TryMoveObject(MovementDirection direction)
|
||||
{
|
||||
if (_baseExcavator == null || _baseExcavator.EntityBaseExcavator == null)
|
||||
if (_TrackedVehicle == null || _TrackedVehicle.EntityTrackedVehicle == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return _baseExcavator.MoveTransport(GetDirectionType(direction));
|
||||
return _TrackedVehicle.MoveTransport(GetDirectionType(direction));
|
||||
}
|
||||
|
||||
/// <summary>
|
@ -11,7 +11,7 @@ namespace ProjectExcavator
|
||||
// To customize application configuration such as set high DPI settings or default font,
|
||||
// see https://aka.ms/applicationconfiguration.
|
||||
ApplicationConfiguration.Initialize();
|
||||
Application.Run(new FormExcavator());
|
||||
Application.Run(new FormExcavatorCollection());
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Правильнее было вызвать Insert(T obj, 0);