diff --git a/DumpTruck/DumpTruck/DrawningDumpTruck.cs b/DumpTruck/DumpTruck/DrawningDumpTruck.cs
index 13e6de5..64e5158 100644
--- a/DumpTruck/DumpTruck/DrawningDumpTruck.cs
+++ b/DumpTruck/DumpTruck/DrawningDumpTruck.cs
@@ -8,7 +8,7 @@ using DumpTruck.Entities;
namespace DumpTruck.DrawningObjects
{
- public class DrawningDumpTruck : DrawningTruck
+ public class DrawningDumpTruck: DrawningTruck
{
///
/// Конструктор
diff --git a/DumpTruck/DumpTruck/DrawningTruck.cs b/DumpTruck/DumpTruck/DrawningTruck.cs
index 46b29e2..985b916 100644
--- a/DumpTruck/DumpTruck/DrawningTruck.cs
+++ b/DumpTruck/DumpTruck/DrawningTruck.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using DumpTruck.Entities;
+using DumpTruck.MovementStrategy;
namespace DumpTruck.DrawningObjects
{
@@ -14,6 +15,10 @@ namespace DumpTruck.DrawningObjects
///
public EntityTruck? EntityTruck { get; protected set; }
///
+ /// Получение объекта IMoveableObject из объекта DrawningCar
+ ///
+ public IMoveableObject GetMoveableObject => new DrawningObjectTruck(this);
+ ///
/// Ширина окна
///
private int _pictureWidth;
diff --git a/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs b/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
index 5090c0d..95ed775 100644
--- a/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
+++ b/DumpTruck/DumpTruck/FormDumpTruck.Designer.cs
@@ -37,6 +37,7 @@
buttonCreateDumpTruck = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
+ buttonSelectTruck = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxDumpTruck).BeginInit();
SuspendLayout();
//
@@ -142,11 +143,22 @@
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
+ // buttonSelectTruck
+ //
+ buttonSelectTruck.Location = new Point(12, 357);
+ buttonSelectTruck.Name = "buttonSelectTruck";
+ buttonSelectTruck.Size = new Size(231, 43);
+ buttonSelectTruck.TabIndex = 9;
+ buttonSelectTruck.Text = "Выбрать";
+ buttonSelectTruck.UseVisualStyleBackColor = true;
+ buttonSelectTruck.Click += buttonSelectTruck_Click;
+ //
// FormDumpTruck
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(884, 461);
+ Controls.Add(buttonSelectTruck);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateDumpTruck);
@@ -175,5 +187,6 @@
private Button buttonCreateDumpTruck;
private ComboBox comboBoxStrategy;
private Button buttonStep;
+ private Button buttonSelectTruck;
}
}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormDumpTruck.cs b/DumpTruck/DumpTruck/FormDumpTruck.cs
index 6daad08..6cb0b9e 100644
--- a/DumpTruck/DumpTruck/FormDumpTruck.cs
+++ b/DumpTruck/DumpTruck/FormDumpTruck.cs
@@ -12,12 +12,20 @@ namespace DumpTruck
private AbstractStrategy? _abstractStrategy;
+ ///
+ /// Выбранный автомобиль
+ ///
+ public DrawningTruck? selectedTruck { get; private set; }
+
+
///
/// Инициализация формы
///
public FormDumpTruck()
{
InitializeComponent();
+ _abstractStrategy = null;
+ selectedTruck = null;
}
///
@@ -41,8 +49,13 @@ namespace DumpTruck
private void buttonCreateTruck_Click(object sender, EventArgs e)
{
Random random = new();
- _drawningTruck = new DrawningTruck(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;
+ }
+ _drawningTruck = new DrawningTruck(random.Next(100, 300), random.Next(1000, 3000), color,
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
@@ -82,9 +95,20 @@ namespace DumpTruck
private void buttonCreateDumpTruck_Click(object sender, EventArgs e)
{
Random random = new();
+ 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;
+ }
+ Color dopColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialog.Color;
+ }
_drawningTruck = new DrawningDumpTruck(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)),
+ color, dopColor,
Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)),
pictureBoxDumpTruck.Width, pictureBoxDumpTruck.Height);
_drawningTruck.SetPosition(random.Next(10, 100), random.Next(10, 100));
@@ -127,5 +151,11 @@ namespace DumpTruck
_abstractStrategy = null;
}
}
+
+ private void buttonSelectTruck_Click(object sender, EventArgs e)
+ {
+ selectedTruck = _drawningTruck;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs b/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
new file mode 100644
index 0000000..a41becd
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.Designer.cs
@@ -0,0 +1,124 @@
+namespace DumpTruck
+{
+ partial class FormTruckCollection
+ {
+ ///
+ /// 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()
+ {
+ groupBox1 = new GroupBox();
+ maskedTextBoxNumber = new MaskedTextBox();
+ buttonRefreshCollection = new Button();
+ buttonRemoveTruck = new Button();
+ buttonAddTruck = new Button();
+ pictureBoxCollection = new PictureBox();
+ groupBox1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // groupBox1
+ //
+ groupBox1.Controls.Add(maskedTextBoxNumber);
+ groupBox1.Controls.Add(buttonRefreshCollection);
+ groupBox1.Controls.Add(buttonRemoveTruck);
+ groupBox1.Controls.Add(buttonAddTruck);
+ groupBox1.Location = new Point(588, 12);
+ groupBox1.Name = "groupBox1";
+ groupBox1.Size = new Size(200, 426);
+ groupBox1.TabIndex = 0;
+ groupBox1.TabStop = false;
+ groupBox1.Text = "Инструменты";
+ groupBox1.Enter += groupBox1_Enter;
+ //
+ // maskedTextBoxNumber
+ //
+ maskedTextBoxNumber.Location = new Point(52, 166);
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(100, 23);
+ maskedTextBoxNumber.TabIndex = 4;
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(6, 382);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(188, 33);
+ buttonRefreshCollection.TabIndex = 3;
+ buttonRefreshCollection.Text = "Обновить коллекцию";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // buttonRemoveTruck
+ //
+ buttonRemoveTruck.Location = new Point(6, 195);
+ buttonRemoveTruck.Name = "buttonRemoveTruck";
+ buttonRemoveTruck.Size = new Size(188, 34);
+ buttonRemoveTruck.TabIndex = 2;
+ buttonRemoveTruck.Text = "Удалить грузовик";
+ buttonRemoveTruck.UseVisualStyleBackColor = true;
+ buttonRemoveTruck.Click += buttonRemoveTruck_Click;
+ //
+ // buttonAddTruck
+ //
+ buttonAddTruck.Location = new Point(6, 22);
+ buttonAddTruck.Name = "buttonAddTruck";
+ buttonAddTruck.Size = new Size(188, 31);
+ buttonAddTruck.TabIndex = 1;
+ buttonAddTruck.Text = "Добавить грузовик";
+ buttonAddTruck.UseVisualStyleBackColor = true;
+ buttonAddTruck.Click += buttonAddTruck_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Location = new Point(12, 12);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(570, 426);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormTruckCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(pictureBoxCollection);
+ Controls.Add(groupBox1);
+ Name = "FormTruckCollection";
+ Text = "Набор грузовиков";
+ groupBox1.ResumeLayout(false);
+ groupBox1.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBox1;
+ private Button buttonAddTruck;
+ private Button buttonRemoveTruck;
+ private Button buttonRefreshCollection;
+ private PictureBox pictureBoxCollection;
+ private MaskedTextBox maskedTextBoxNumber;
+ }
+}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.cs b/DumpTruck/DumpTruck/FormTruckCollection.cs
new file mode 100644
index 0000000..918e530
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.cs
@@ -0,0 +1,77 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Data;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+using DumpTruck.DrawningObjects;
+using DumpTruck.Generics;
+using DumpTruck.MovementStrategy;
+
+
+namespace DumpTruck
+{
+ public partial class FormTruckCollection : Form
+ {
+ ///
+ /// Набор объектов
+ ///
+ private readonly TrucksGenericCollection _trucks;
+
+ public FormTruckCollection()
+ {
+ InitializeComponent();
+ _trucks = new TrucksGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void buttonAddTruck_Click(object sender, EventArgs e)
+ {
+ FormDumpTruck form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_trucks + form.selectedTruck != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ }
+
+ private void buttonRemoveTruck_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_trucks - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+
+ }
+
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _trucks.ShowTrucks();
+ }
+
+ private void groupBox1_Enter(object sender, EventArgs e)
+ {
+
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/FormTruckCollection.resx b/DumpTruck/DumpTruck/FormTruckCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/DumpTruck/DumpTruck/FormTruckCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/DumpTruck/DumpTruck/Program.cs b/DumpTruck/DumpTruck/Program.cs
index b619d5a..b645567 100644
--- a/DumpTruck/DumpTruck/Program.cs
+++ b/DumpTruck/DumpTruck/Program.cs
@@ -11,7 +11,7 @@ namespace DumpTruck
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormDumpTruck());
+ Application.Run(new FormTruckCollection());
}
}
}
\ No newline at end of file
diff --git a/DumpTruck/DumpTruck/SetGeneric.cs b/DumpTruck/DumpTruck/SetGeneric.cs
new file mode 100644
index 0000000..cdfe2c4
--- /dev/null
+++ b/DumpTruck/DumpTruck/SetGeneric.cs
@@ -0,0 +1,110 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Numerics;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.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 truck)
+ {
+ return Insert(truck, 0);
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый автомобиль
+ /// Позиция
+ ///
+ public int Insert(T truck, int position)
+ {
+ // TODO проверка позиции
+ if (position < 0 || position > Count)
+ {
+ return -1;
+ }
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ if (_places[position] != null)
+ {
+ // проверка, что после вставляемого элемента в массиве есть пустой элемент
+ int nullIndex = -1;
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ nullIndex = i;
+ break;
+ }
+ }
+ // Если пустого элемента нет, то выходим
+ if (nullIndex < 0)
+ {
+ return -1;
+ }
+ // сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ int j = nullIndex - 1;
+ while (j >= position)
+ {
+ _places[j + 1] = _places[j];
+ j--;
+ }
+ }
+ // TODO вставка по позиции
+ _places[position] = truck;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ // TODO проверка позиции
+ if ((position < 0) || (position > Count)) return false;
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ _places[position] = null;
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ // TODO проверка позиции
+ if ((position < 0) || (position > Count)) return null;
+ return _places[position];
+ }
+ }
+}
diff --git a/DumpTruck/DumpTruck/TrucksGenericCollection.cs b/DumpTruck/DumpTruck/TrucksGenericCollection.cs
new file mode 100644
index 0000000..5ed60fe
--- /dev/null
+++ b/DumpTruck/DumpTruck/TrucksGenericCollection.cs
@@ -0,0 +1,140 @@
+using DumpTruck.DrawningObjects;
+using DumpTruck.MovementStrategy;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DumpTruck.Generics
+{
+ internal class TrucksGenericCollection
+ where T : DrawningTruck
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 110;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 70;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public TrucksGenericCollection(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 +(TrucksGenericCollection collect, T?
+ obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect._collection.Insert(obj);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static bool operator -(TrucksGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ return collect._collection.Remove(pos);
+ }
+ return false;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowTrucks()
+ {
+ 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 / 2, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ // TODO получение объекта
+ // TODO установка позиции
+ // TODO прорисовка объекта
+ DrawningTruck? truck = _collection.Get(i);
+ if (truck == null)
+ continue;
+ truck.SetPosition(i % width * _placeSizeWidth, i / width * _placeSizeHeight);
+ truck.DrawTransport(g);
+ }
+ }
+ }
+}