diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
index 6f0c74e..fda869a 100644
--- a/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/DrawingExcavator.cs
@@ -4,11 +4,17 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectExcavator.Entities;
+using ProjectExcavator.MovementStrategy;
namespace ProjectExcavator.DrawingObjects
{
+
public class DrawingExcavator
{
+ ///
+ /// Получение объекта IMoveableObject из объекта DrawingExcavator
+ ///
+ public IMoveableObject GetMoveableObject => new DrawingObjectExcavator(this);
///
/// Класс-сущность
///
@@ -22,21 +28,21 @@ namespace ProjectExcavator.DrawingObjects
///
private int _pictureHeight;
///
- /// /// Левая координата прорисовки автомобиля
+ /// /// Левая координата прорисовки экскаватора
///
protected int _startPosX;
///
- /// Верхняя кооридната прорисовки автомобиля
+ /// Верхняя координата прорисовки экскаватора
///
protected int _startPosY;
///
- /// Ширина прорисовки автомобиля
+ /// Ширина прорисовки экскаватора
///
- protected readonly int _exWidth = 138;
+ protected readonly int _exWidth = 140;
///
- /// Высота прорисовки автомобиля
+ /// Высота прорисовки экскаватора
///
- protected readonly int _exHeight = 80;
+ protected readonly int _exHeight = 82;
///
/// Инициализация свойств
///
@@ -192,9 +198,7 @@ namespace ProjectExcavator.DrawingObjects
//цвета
Pen pen = new(Color.Black);
- Brush brBlue = new SolidBrush(Color.LightBlue);
- Brush brYellow = new SolidBrush(Color.Yellow);
- Brush brGray = new SolidBrush(Color.Gray);
+ Brush bodyBrush = new SolidBrush(EntityExcavator.BodyColor);
Brush brBlack = new SolidBrush(Color.Black);
//отрисовка экскаватора без ковша
@@ -213,18 +217,18 @@ namespace ProjectExcavator.DrawingObjects
g.DrawEllipse(pen, _startPosX + 92, _startPosY + 68, 6, 6);
//кабина водителя
- g.FillRectangle(brBlue, _startPosX + 96, _startPosY + 11, 29, 24);
+ g.FillRectangle(bodyBrush, _startPosX + 96, _startPosY + 11, 29, 24);
// кузов
- g.FillRectangle(brYellow, _startPosX + 51, _startPosY + 36, 74, 24);
+ g.FillRectangle(bodyBrush, _startPosX + 51, _startPosY + 36, 74, 24);
// труба
- g.FillRectangle(brYellow, _startPosX + 61, _startPosY + 16, 9, 19);
+ g.FillRectangle(bodyBrush, _startPosX + 61, _startPosY + 16, 9, 19);
//гусеница
- g.FillPie(brGray, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
- g.FillPie(brGray, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
- g.FillRectangle(brGray, _startPosX + 44, _startPosY + 65, 86, 20);
+ g.FillPie(bodyBrush, _startPosX + 34, _startPosY + 65, 20, 20, 90, 180);
+ g.FillPie(bodyBrush, _startPosX + 120, _startPosY + 65, 20, 20, 270, 180);
+ g.FillRectangle(bodyBrush, _startPosX + 44, _startPosY + 65, 86, 20);
g.FillEllipse(brBlack, _startPosX + 40, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 120, _startPosY + 68, 15, 15);
g.FillEllipse(brBlack, _startPosX + 60, _startPosY + 76, 8, 8);
diff --git a/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
index 5cbd6f9..56239fa 100644
--- a/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
+++ b/ProjectExcavator/ProjectExcavator/DrawingExcavatorKovsh.cs
@@ -24,7 +24,7 @@ namespace ProjectExcavator.DrawingObjects
/// Ширина картинки
/// Высота картинки
public DrawingExcavatorKovsh(int speed, double weight, Color bodyColor, Color
- additionalColor, bool kovsh, bool katki, int width, int height) : base(speed, weight, bodyColor, width, height, 138, 80)
+ additionalColor, bool kovsh, bool katki, int width, int height) : base(speed, weight, bodyColor, width, height, 140, 82)
{
if (EntityExcavator != null)
{
@@ -38,56 +38,54 @@ namespace ProjectExcavator.DrawingObjects
{
return;
}
+
//цвета
Pen pen = new(Color.Black);
Brush additionalBrush = new
SolidBrush(excavatorKovsh.AdditionalColor);
- Brush brBlack = new SolidBrush(Color.Black);
// ковш
- if (excavatorKovsh.Kovsh)
- {
- g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
- g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
- g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
- g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
- g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
- g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
- g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
- g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
- g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
+ g.DrawLine(pen, _startPosX + 50, _startPosY + 35, _startPosX + 10, _startPosY + 10);
+ g.DrawLine(pen, _startPosX + 58, _startPosY + 35, _startPosX + 12, _startPosY + 5);
+ g.DrawEllipse(pen, _startPosX + 7, _startPosY + 4, 7, 7);
+ g.DrawLine(pen, _startPosX + 10, _startPosY + 10, _startPosX + 10, _startPosY + 45);
+ g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY + 45);
+ g.DrawPie(pen, _startPosX, _startPosY + 44, 28, 30, 90, 180);
+ g.DrawLine(pen, _startPosX + 14, _startPosY + 5, _startPosX + 14, _startPosY);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 7, _startPosY + 10);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 12);
+ g.DrawLine(pen, _startPosX + 14, _startPosY, _startPosX + 50, _startPosY + 16);
+ g.DrawLine(pen, _startPosX + 50, _startPosY + 12, _startPosX + 50, _startPosY + 29);
- g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
- g.FillPie(brBlack, _startPosX, _startPosY + 44, 28, 30, 90, 180);
- Point point1 = new Point(_startPosX + 50, _startPosY + 35);
- Point point2 = new Point(_startPosX + 10, _startPosY + 10);
- Point point3 = new Point(_startPosX + 12, _startPosY + 5);
- Point point4 = new Point(_startPosX + 58, _startPosY + 35);
- Point[] truba_1 = { point1, point2, point3, point4, point1 };
- g.FillPolygon(additionalBrush, truba_1);
+ g.FillEllipse(additionalBrush, _startPosX + 7, _startPosY + 4, 7, 7);
+ g.FillPie(additionalBrush, _startPosX, _startPosY + 44, 28, 30, 90, 180);
+ Point point1 = new Point(_startPosX + 50, _startPosY + 35);
+ Point point2 = new Point(_startPosX + 10, _startPosY + 10);
+ Point point3 = new Point(_startPosX + 12, _startPosY + 5);
+ Point point4 = new Point(_startPosX + 58, _startPosY + 35);
+ Point[] truba_1 = { point1, point2, point3, point4, point1 };
+ g.FillPolygon(additionalBrush, truba_1);
- Point point5 = new Point(_startPosX + 10, _startPosY + 10);
- Point point6 = new Point(_startPosX + 10, _startPosY + 45);
- Point point7 = new Point(_startPosX + 14, _startPosY + 45);
- Point point8 = new Point(_startPosX + 14, _startPosY + 5);
- Point[] truba_2 = { point5, point6, point7, point8, point5 };
- g.FillPolygon(additionalBrush, truba_2);
+ Point point5 = new Point(_startPosX + 10, _startPosY + 10);
+ Point point6 = new Point(_startPosX + 10, _startPosY + 45);
+ Point point7 = new Point(_startPosX + 14, _startPosY + 45);
+ Point point8 = new Point(_startPosX + 14, _startPosY + 5);
+ Point[] truba_2 = { point5, point6, point7, point8, point5 };
+ g.FillPolygon(additionalBrush, truba_2);
- Point point9 = new Point(_startPosX + 14, _startPosY + 5);
- Point point10 = new Point(_startPosX + 14, _startPosY);
- Point point11 = new Point(_startPosX + 7, _startPosY + 10);
- Point[] triangle = { point9, point10, point11, point9 };
- g.FillPolygon(additionalBrush, triangle);
+ Point point9 = new Point(_startPosX + 14, _startPosY + 5);
+ Point point10 = new Point(_startPosX + 14, _startPosY);
+ Point point11 = new Point(_startPosX + 7, _startPosY + 10);
+ Point[] triangle = { point9, point10, point11, point9 };
+ g.FillPolygon(additionalBrush, triangle);
+
+ Point point12 = new Point(_startPosX + 14, _startPosY);
+ Point point13 = new Point(_startPosX + 50, _startPosY + 12);
+ Point point14 = new Point(_startPosX + 50, _startPosY + 16);
+ Point point15 = new Point(_startPosX + 14, _startPosY);
+ Point[] krepl = { point12, point13, point14, point15, point12 };
+ g.FillPolygon(additionalBrush, krepl);
- Point point12 = new Point(_startPosX + 14, _startPosY);
- Point point13 = new Point(_startPosX + 50, _startPosY + 12);
- Point point14 = new Point(_startPosX + 50, _startPosY + 16);
- Point point15 = new Point(_startPosX + 14, _startPosY);
- Point[] krepl = { point12, point13, point14, point15, point12 };
- g.FillPolygon(additionalBrush, krepl);
- }
base.DrawTransport(g);
// катки
diff --git a/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
index 4fc56be..74aa72c 100644
--- a/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/DrawingObjectExcavator.cs
@@ -8,7 +8,7 @@ using ProjectExcavator.DrawingObjects;
namespace ProjectExcavator.MovementStrategy
{
///
- /// Реализация интерфейса IDrawningObject для работы с объектом DrawningCar (паттерн Adapter)
+ /// Реализация интерфейса IDrawningObject для работы с объектом DrawingExcavator (паттерн Adapter)
///
public class DrawingObjectExcavator : IMoveableObject
{
diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
index fccd130..188f112 100644
--- a/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/EntityExcavator.cs
@@ -21,14 +21,14 @@ namespace ProjectExcavator.Entities
///
public Color BodyColor { get; private set; }
///
- /// Шаг перемещения автомобиля
+ /// Шаг перемещения экскаватора
///
public double Step => (double)Speed * 100 / Weight;
///
- /// Инициализация полей объекта-класса спортивного автомобиля
+ /// Инициализация полей объекта-класса экскаватора
///
/// Скорость
- /// Вес автомобиля
+ /// Вес экскаватора
/// Основной цвет
public EntityExcavator(int speed, double weight, Color bodyColor)
{
diff --git a/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
index 4dbd852..18feb4f 100644
--- a/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
+++ b/ProjectExcavator/ProjectExcavator/EntityExcavatorKovsh.cs
@@ -28,7 +28,7 @@ namespace ProjectExcavator.Entities
/// Инициализация полей объекта-класса экскаватора с ковшом
///
/// Скорость
- /// Вес автомобиля
+ /// Вес экскаватора
/// Основной цвет
/// Дополнительный цвет
/// Признак наличия ковша
diff --git a/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
new file mode 100644
index 0000000..12fa8de
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/ExcavatorGenericCollection.cs
@@ -0,0 +1,143 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectExcavator.DrawingObjects;
+using ProjectExcavator.MovementStrategy;
+
+namespace ProjectExcavator.Generics
+{
+ ///
+ /// Параметризованный класс для набора объектов DrawingExcavator
+ ///
+ ///
+ ///
+ internal class ExcavatorGenericCollection
+ where T : DrawingExcavator
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 200;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 90;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public ExcavatorGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(ExcavatorGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect?._collection.Insert(obj) ?? -1;
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static bool operator -(ExcavatorGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ return true;
+ }
+ return false;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowExcavator()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {//линия разметки места
+ g.DrawLine(pen, i * _placeSizeWidth, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ DrawingExcavator? excavator = _collection.Get(i);
+ if (excavator == null)
+ continue;
+ int r = i / width;
+ int s = width - 1 - (i % width);
+ excavator.SetPosition(s * _placeSizeWidth, r * _placeSizeHeight);
+ excavator.DrawTransport(g);
+ }
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
index 9a8922d..55a61ac 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavator.Designer.cs
@@ -37,6 +37,7 @@
this.buttonCreateEx = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
+ this.buttonSelectExcavator = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxExcavator)).BeginInit();
this.SuspendLayout();
//
@@ -140,11 +141,22 @@
this.comboBoxStrategy.Size = new System.Drawing.Size(121, 23);
this.comboBoxStrategy.TabIndex = 9;
//
+ // buttonSelectExcavator
+ //
+ this.buttonSelectExcavator.Location = new System.Drawing.Point(370, 426);
+ this.buttonSelectExcavator.Name = "buttonSelectExcavator";
+ this.buttonSelectExcavator.Size = new System.Drawing.Size(105, 23);
+ this.buttonSelectExcavator.TabIndex = 10;
+ this.buttonSelectExcavator.Text = "Выбрать обьект";
+ this.buttonSelectExcavator.UseVisualStyleBackColor = true;
+ this.buttonSelectExcavator.Click += new System.EventHandler(this.ButtonSelectExcavator_Click);
+ //
// FormExcavator
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(884, 461);
+ this.Controls.Add(this.buttonSelectExcavator);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateEx);
@@ -172,5 +184,6 @@
private Button buttonCreateEx;
private Button buttonStep;
private ComboBox comboBoxStrategy;
+ private Button buttonSelectExcavator;
}
}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavator.cs b/ProjectExcavator/ProjectExcavator/FormExcavator.cs
index 41480d5..62ecdd1 100644
--- a/ProjectExcavator/ProjectExcavator/FormExcavator.cs
+++ b/ProjectExcavator/ProjectExcavator/FormExcavator.cs
@@ -1,5 +1,6 @@
using ProjectExcavator.DrawingObjects;
using ProjectExcavator.MovementStrategy;
+using System.Windows.Forms;
namespace ProjectExcavator
{
@@ -11,9 +12,17 @@ namespace ProjectExcavator
///
///
private AbstractStrategy? _abstractStrategy;
+ ///
+ ///
+ ///
+ public DrawingExcavator? SelectedExcavator { get; private set; }
+
public FormExcavator()
{
- InitializeComponent();
+ InitializeComponent();
+ _abstractStrategy = null;
+ _drawingExcavator = null;
+
}
private void Draw()
@@ -30,11 +39,24 @@ namespace ProjectExcavator
private void buttonCreateExKovsh_Click(object sender, EventArgs e)
{
Random random = new();
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ ColorDialog dialog2 = new();
+ if (dialog2.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialog2.Color;
+ }
+
_drawingExcavator = new DrawingExcavatorKovsh(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)),
+ color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -42,8 +64,14 @@ namespace ProjectExcavator
private void buttonCreateEx_Click(object sender, EventArgs e)
{
Random random = new();
- _drawingExcavator = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)),
+ 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;
+ }
+ _drawingExcavator = new DrawingExcavator(random.Next(100, 300), random.Next(1000, 3000), color,
pictureBoxExcavator.Width, pictureBoxExcavator.Height);
_drawingExcavator.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -113,5 +141,15 @@ namespace ProjectExcavator
_abstractStrategy = null;
}
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonSelectExcavator_Click(object sender, EventArgs e)
+ {
+ SelectedExcavator = _drawingExcavator;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
new file mode 100644
index 0000000..4c94b90
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.Designer.cs
@@ -0,0 +1,122 @@
+namespace ProjectExcavator
+{
+ partial class FormExcavatorCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
+ this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
+ this.buttonAddEx = new System.Windows.Forms.Button();
+ this.buttonRemoveEx = new System.Windows.Forms.Button();
+ this.buttonRefreshCollection = new System.Windows.Forms.Button();
+ this.groupBox1 = new System.Windows.Forms.GroupBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
+ this.groupBox1.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxCollection
+ //
+ this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxCollection.Name = "pictureBoxCollection";
+ this.pictureBoxCollection.Size = new System.Drawing.Size(909, 461);
+ this.pictureBoxCollection.TabIndex = 0;
+ this.pictureBoxCollection.TabStop = false;
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(26, 125);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(100, 23);
+ this.maskedTextBoxNumber.TabIndex = 1;
+ //
+ // buttonAddEx
+ //
+ this.buttonAddEx.Location = new System.Drawing.Point(6, 57);
+ this.buttonAddEx.Name = "buttonAddEx";
+ this.buttonAddEx.Size = new System.Drawing.Size(150, 23);
+ this.buttonAddEx.TabIndex = 2;
+ this.buttonAddEx.Text = "Добавить экскаватор";
+ this.buttonAddEx.UseVisualStyleBackColor = true;
+ this.buttonAddEx.Click += new System.EventHandler(this.ButtonAddEx_Click);
+ //
+ // buttonRemoveEx
+ //
+ this.buttonRemoveEx.Location = new System.Drawing.Point(6, 166);
+ this.buttonRemoveEx.Name = "buttonRemoveEx";
+ this.buttonRemoveEx.Size = new System.Drawing.Size(150, 23);
+ this.buttonRemoveEx.TabIndex = 3;
+ this.buttonRemoveEx.Text = "Удалить экскаватор";
+ this.buttonRemoveEx.UseVisualStyleBackColor = true;
+ this.buttonRemoveEx.Click += new System.EventHandler(this.ButtonRemoveEx_Click);
+ //
+ // buttonRefreshCollection
+ //
+ this.buttonRefreshCollection.Location = new System.Drawing.Point(6, 230);
+ this.buttonRefreshCollection.Name = "buttonRefreshCollection";
+ this.buttonRefreshCollection.Size = new System.Drawing.Size(148, 23);
+ this.buttonRefreshCollection.TabIndex = 4;
+ this.buttonRefreshCollection.Text = "Обновить коллекцию";
+ this.buttonRefreshCollection.UseVisualStyleBackColor = true;
+ this.buttonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // groupBox1
+ //
+ this.groupBox1.Controls.Add(this.buttonAddEx);
+ this.groupBox1.Controls.Add(this.buttonRefreshCollection);
+ this.groupBox1.Controls.Add(this.maskedTextBoxNumber);
+ this.groupBox1.Controls.Add(this.buttonRemoveEx);
+ this.groupBox1.Location = new System.Drawing.Point(749, 0);
+ this.groupBox1.Name = "groupBox1";
+ this.groupBox1.Size = new System.Drawing.Size(160, 461);
+ this.groupBox1.TabIndex = 5;
+ this.groupBox1.TabStop = false;
+ this.groupBox1.Text = "Инструменты";
+ //
+ // FormExcavatorCollection
+ //
+ this.ClientSize = new System.Drawing.Size(909, 461);
+ this.Controls.Add(this.groupBox1);
+ this.Controls.Add(this.pictureBoxCollection);
+ this.Name = "FormExcavatorCollection";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
+ this.groupBox1.ResumeLayout(false);
+ this.groupBox1.PerformLayout();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private PictureBox pictureBoxCollection;
+ private MaskedTextBox maskedTextBoxNumber;
+ private Button buttonAddEx;
+ private Button buttonRemoveEx;
+ private Button buttonRefreshCollection;
+ private GroupBox groupBox1;
+ }
+}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
new file mode 100644
index 0000000..9475e75
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.cs
@@ -0,0 +1,81 @@
+using ProjectExcavator.DrawingObjects;
+using ProjectExcavator.Generics;
+using ProjectExcavator.MovementStrategy;
+
+namespace ProjectExcavator
+{
+ ///
+ /// Форма для работы с набором объектов класса DrawingExcavator
+ ///
+ public partial class FormExcavatorCollection : Form
+ {
+ ///
+ /// Набор объектов
+ ///
+ private readonly ExcavatorGenericCollection _excavator;
+ ///
+ /// Конструктор
+ ///
+ public FormExcavatorCollection()
+ {
+ InitializeComponent();
+ _excavator = new ExcavatorGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ ///
+ ///
+ private void ButtonAddEx_Click(object sender, EventArgs e)
+ {
+ FormExcavator form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ int result = _excavator + form.SelectedExcavator;
+ if (result != -2)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _excavator.ShowExcavator();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
+ private void ButtonRemoveEx_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_excavator - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _excavator.ShowExcavator();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
+ private void ButtonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _excavator.ShowExcavator();
+ }
+ }
+}
diff --git a/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/FormExcavatorCollection.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/IMoveableObject.cs b/ProjectExcavator/ProjectExcavator/IMoveableObject.cs
index 048b833..fc48d19 100644
--- a/ProjectExcavator/ProjectExcavator/IMoveableObject.cs
+++ b/ProjectExcavator/ProjectExcavator/IMoveableObject.cs
@@ -26,7 +26,7 @@ namespace ProjectExcavator.MovementStrategy
///
bool CheckCanMove(DirectionType direction);
///
- /// Изменение направления перемещения объекта
+ /// Изменение направления пермещения объекта
///
/// Направление
void MoveObject(DirectionType direction);
diff --git a/ProjectExcavator/ProjectExcavator/MoveToBorder.cs b/ProjectExcavator/ProjectExcavator/MoveToBorder.cs
index 27cbbfe..e93cb37 100644
--- a/ProjectExcavator/ProjectExcavator/MoveToBorder.cs
+++ b/ProjectExcavator/ProjectExcavator/MoveToBorder.cs
@@ -41,7 +41,6 @@ namespace ProjectExcavator.MovementStrategy
{
MoveRight();
}
-
}
var diffY = objParams.ObjectBorderDown - FieldHeight;
if (Math.Abs(diffY) > GetStep())
diff --git a/ProjectExcavator/ProjectExcavator/ObjectParameters.cs b/ProjectExcavator/ProjectExcavator/ObjectParameters.cs
index 7f05a69..21685b0 100644
--- a/ProjectExcavator/ProjectExcavator/ObjectParameters.cs
+++ b/ProjectExcavator/ProjectExcavator/ObjectParameters.cs
@@ -36,7 +36,13 @@ namespace ProjectExcavator.MovementStrategy
/// Середина объекта
///
public int ObjectMiddleVertical => _y + _height / 2;
+ ///
+ /// Нижний правый угол объекта
+ ///
public int ObjectBorderRight => _x + _width;
+ ///
+ /// Нижний правый угол объекта
+ ///
public int ObjectBorderDown => _y + _height;
///
/// Конструктор
diff --git a/ProjectExcavator/ProjectExcavator/Program.cs b/ProjectExcavator/ProjectExcavator/Program.cs
index 59b8c54..15b7126 100644
--- a/ProjectExcavator/ProjectExcavator/Program.cs
+++ b/ProjectExcavator/ProjectExcavator/Program.cs
@@ -11,7 +11,8 @@ 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());
+
}
}
}
\ No newline at end of file
diff --git a/ProjectExcavator/ProjectExcavator/SetGeneric.cs b/ProjectExcavator/ProjectExcavator/SetGeneric.cs
new file mode 100644
index 0000000..310a7a2
--- /dev/null
+++ b/ProjectExcavator/ProjectExcavator/SetGeneric.cs
@@ -0,0 +1,114 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectExcavator.Generics
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T?[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый экскаватор
+ ///
+ public int Insert(T excavator)
+ {
+ for (int i = _places.Length - 1; i > 0; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[0] = excavator;
+ return Insert(excavator, 0);
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый экскаватор
+ /// Позиция
+ ///
+ public int Insert(T excavator, int position)
+ {
+ if (position < 0 || position >= _places.Length)
+ {
+ return -1;
+ }
+
+ if (_places[position] != null)
+ {
+ return -1;
+ }
+
+ int NullIndex = 0;
+ for (int i = position; i < _places.Length; i++)
+ {
+ if (_places[i] == null)
+ {
+ NullIndex = i;
+ break;
+ }
+ }
+
+ if (NullIndex == 0)
+ {
+ return -1;
+ }
+
+ for (int i = NullIndex; i >= position; i--)
+ {
+ _places[i + 1] = _places[i];
+ }
+ _places[position] = excavator;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ if (position < 0 || position >= _places.Length)
+ {
+ return false;
+ }
+ _places[position] = null;
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ if (position < 0 || position >= _places.Length)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}