diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs b/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..b6dfbf1
--- /dev/null
+++ b/ProjectElectricLocomotive/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,119 @@
+using ProjectElectricLocomotive.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+
+///
+/// Абстракция компании, хранящий коллекцию Локомотивов
+///
+
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 140;
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+ ///
+ /// Коллекция Локомотивов
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального количества элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция Локомотивов
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static bool operator +(AbstractCompany company, DrawningLocomotive locomotive)
+ {
+ return company._collection?.Insert(locomotive) ?? false;
+ }
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static bool operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? false;
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningLocomotive? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackgound(graphics);
+ SetObjectsPosition(_collection);
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+
+ DrawningLocomotive? obj = _collection?.Get(i);
+ if (obj != null)
+ {
+ obj.SetPictureSize(_pictureWidth, _pictureWidth);
+ }
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition(ICollectionGenericObjects collection);
+}
+
diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..50a5239
--- /dev/null
+++ b/ProjectElectricLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,52 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
+
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Количество объектов в коллекции
+ ///
+ int Count { get; }
+ ///
+ /// Установка максимального количества элементов
+ ///
+ int SetMaxCount { set; }
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла удачно, false - вставка не удалась
+bool Insert(T obj);
+
+ ///
+ /// Добавление объекта в коллекцию на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла удачно, false - вставка не удалась
+bool Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло удачно, false - удаление не удалось
+bool Remove(int position);
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+}
diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs b/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs
new file mode 100644
index 0000000..9751592
--- /dev/null
+++ b/ProjectElectricLocomotive/CollectionGenericObjects/LocomotiveDepo.cs
@@ -0,0 +1,52 @@
+using ProjectElectricLocomotive.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects;
+
+public class LocomotiveDepo : AbstractCompany
+{
+ public LocomotiveDepo(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen steel = new Pen(Color.Gray);
+ Pen wood = new Pen(Color.Brown);
+ g.DrawRectangle(steel,0, _pictureHeight - 50,_pictureWidth,40 );
+ for(int i = 0; i < _pictureWidth; i += 20)
+ {
+ g.DrawLine(wood, i, _pictureHeight - 50, i + 10, _pictureHeight - 10);
+ g.DrawLine(wood, i, _pictureHeight - 190, i + 10, _pictureHeight - 150);
+ g.DrawLine(wood, i, _pictureHeight - 325, i + 10, _pictureHeight - 285);
+
+ }
+ g.DrawRectangle(steel, 0, _pictureHeight - 190, _pictureWidth, 40);
+ g.DrawRectangle(steel, 0, _pictureHeight - 325, _pictureWidth, 40);
+
+ //g.DrawRectangle(steel, 0, _pictureHeight - 40, _pictureWidth, 1000);
+
+ }
+
+ protected override void SetObjectsPosition(ICollectionGenericObjects collection)
+ {
+
+ int index = 0;
+ for(int i = _pictureHeight - _placeSizeHeight; i >= 0; i-= _placeSizeHeight)
+ {
+ for(int j = 0; j <= _pictureWidth - _placeSizeWidth; j += _placeSizeWidth)
+ {
+ if (collection.Get(index) != null)
+ {
+ collection.Get(index).SetPosition(j + 10, i + 10);
+ index++;
+ }
+ }
+ }
+
+ }
+}
diff --git a/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..49b14d7
--- /dev/null
+++ b/ProjectElectricLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectElectricLocomotive.CollectionGenericObjects
+{
+ public class MassiveGenericObjects : ICollectionGenericObjects where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ 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];
+ }
+ }
+ }
+ }
+
+ ///
+ /// Конструктор
+ ///
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+ public T? Get(int position)
+ {
+ //TODO проверка позиции
+ if(position < 0)
+ {
+ return null;
+ }
+ return _collection[position];
+ }
+ public bool Insert(T obj)
+ {
+ if(obj == null){ return false; }
+ for(int i = 0; i < _collection.Length; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public bool Insert(T obj, int position)
+ {
+ if(obj == null || position < 0)
+ {
+ return false;
+ }
+ if (_collection[position] != null)
+ {
+ for(int i = position; i < _collection.Length; i++)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return true;
+ }
+ }
+ for(int i = position; i > 0; i--)
+ {
+ if (_collection[i] == null)
+ {
+ _collection[i] = obj;
+ return true;
+ }
+ }
+ }
+
+
+ // TODO проверка позиции
+ // TODO проверка, что элемент массива по этой позиции пустой, если нет, то
+ // ищется свободное место после этой позиции и идет вставка туда
+ // если нет после, ищем до
+ // TODO вставка
+ return false;
+ }
+ public bool Remove(int position)
+ {
+
+ if(position < 0)
+ {
+ return false;
+ }
+ else
+ {
+ _collection[position] = null;
+ }
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ return true;
+ }
+ }
+}
diff --git a/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs b/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs
index 605506c..2f4c8c6 100644
--- a/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs
+++ b/ProjectElectricLocomotive/Drawnings/DrawningLocomotive.cs
@@ -35,10 +35,10 @@ public class DrawningLocomotive
/// Ширина прорисовки Локомотива
///
public readonly int _drawningLocomotiveWidth = 155;
- ///
- /// Высота прорисовки локомотива
- ///
- public readonly int _drawningLocomotiveHeight = 90;
+ ///
+ /// Высота прорисовки локомотива
+ ///
+ public readonly int _drawningLocomotiveHeight = 115;
///
/// Координата X объекта
diff --git a/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs b/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
new file mode 100644
index 0000000..290bdfd
--- /dev/null
+++ b/ProjectElectricLocomotive/FormLocomotiveCollection.Designer.cs
@@ -0,0 +1,168 @@
+namespace ProjectElectricLocomotive
+{
+ partial class FormLocomotiveCollection
+ {
+ ///
+ /// 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()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonDelLocomotive = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddElectricLocomotive = new Button();
+ buttonAddLocomotive = 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(buttonDelLocomotive);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddElectricLocomotive);
+ groupBoxTools.Controls.Add(buttonAddLocomotive);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(574, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(226, 450);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Location = new Point(21, 358);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(193, 39);
+ buttonRefresh.TabIndex = 7;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += buttonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Location = new Point(21, 313);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(193, 39);
+ buttonGoToCheck.TabIndex = 6;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += buttonGoToCheck_Click;
+ //
+ // buttonDelLocomotive
+ //
+ buttonDelLocomotive.Location = new Point(21, 244);
+ buttonDelLocomotive.Name = "buttonDelLocomotive";
+ buttonDelLocomotive.Size = new Size(193, 63);
+ buttonDelLocomotive.TabIndex = 5;
+ buttonDelLocomotive.Text = "Удаление Локомотива";
+ buttonDelLocomotive.UseVisualStyleBackColor = true;
+ buttonDelLocomotive.Click += buttonDelLocomotive_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(21, 207);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(193, 31);
+ maskedTextBox.TabIndex = 4;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddElectricLocomotive
+ //
+ buttonAddElectricLocomotive.Location = new Point(21, 138);
+ buttonAddElectricLocomotive.Name = "buttonAddElectricLocomotive";
+ buttonAddElectricLocomotive.Size = new Size(193, 63);
+ buttonAddElectricLocomotive.TabIndex = 2;
+ buttonAddElectricLocomotive.Text = "Добавление Электро - Локомотива";
+ buttonAddElectricLocomotive.UseVisualStyleBackColor = true;
+ buttonAddElectricLocomotive.Click += buttonAddElectricLocomotive_Click;
+ //
+ // buttonAddLocomotive
+ //
+ buttonAddLocomotive.Location = new Point(21, 69);
+ buttonAddLocomotive.Name = "buttonAddLocomotive";
+ buttonAddLocomotive.Size = new Size(193, 63);
+ buttonAddLocomotive.TabIndex = 1;
+ buttonAddLocomotive.Text = "Добавление Локомотива";
+ buttonAddLocomotive.UseVisualStyleBackColor = true;
+ buttonAddLocomotive.Click += buttonAddLocomotive_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(21, 30);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(193, 33);
+ 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(574, 450);
+ pictureBox.TabIndex = 3;
+ pictureBox.TabStop = false;
+ //
+ // FormLocomotiveCollection
+ //
+ AutoScaleDimensions = new SizeF(10F, 25F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormLocomotiveCollection";
+ Text = "Коллекция Локомотивов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddElectricLocomotive;
+ private Button buttonAddLocomotive;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonDelLocomotive;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/ProjectElectricLocomotive/FormLocomotiveCollection.cs b/ProjectElectricLocomotive/FormLocomotiveCollection.cs
new file mode 100644
index 0000000..9c9ead4
--- /dev/null
+++ b/ProjectElectricLocomotive/FormLocomotiveCollection.cs
@@ -0,0 +1,202 @@
+using ProjectElectricLocomotive.CollectionGenericObjects;
+using ProjectElectricLocomotive.Drawnings;
+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;
+
+namespace ProjectElectricLocomotive;
+
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+public partial class FormLocomotiveCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormLocomotiveCollection()
+ {
+ InitializeComponent();
+ }
+
+
+ ///
+ /// Выбор компании
+ ///
+ ///
+ ///
+ private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Депо":
+ _company = new LocomotiveDepo(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+
+ }
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ ///
+ private void CreateObject(string type)
+ {
+ Random random = new();
+ DrawningLocomotive drawningLocomotive;
+ switch (type)
+ {
+ case nameof(DrawningLocomotive):
+ drawningLocomotive = new DrawningLocomotive(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random));
+
+ break;
+ case nameof(DrawningElectricLocomotive):
+ drawningLocomotive = new DrawningElectricLocomotive(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+
+ break;
+ default:
+ return;
+ }
+ if (_company + drawningLocomotive)
+ {
+ pictureBox.Image = _company.Show();
+ MessageBox.Show("Обьект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ private static Color GetColor(Random random)
+ {
+ Color color = Color.FromArgb(random.Next(0, 256), random.Next(0,
+ 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ return color;
+ }
+
+
+ ///
+ /// Добавление локомотива
+ ///
+ ///
+ ///
+ private void buttonAddLocomotive_Click(object sender, EventArgs e) =>
+ CreateObject(nameof(DrawningLocomotive));
+
+
+ ///
+ /// Добавление электро локомотива
+ ///
+ ///
+ ///
+ private void buttonAddElectricLocomotive_Click(object sender, EventArgs e) =>
+ CreateObject(nameof(DrawningElectricLocomotive));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void buttonDelLocomotive_Click(object sender, EventArgs e)
+ {
+ {
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company ==
+ null)
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBox.Text);
+ if (_company - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void buttonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningLocomotive? locomotive = null;
+ int counter = 100;
+ while (locomotive == null)
+ {
+ locomotive = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (locomotive == null)
+ {
+ return;
+ }
+ FormlectricLocomotive form = new()
+ {
+ SetLocomotive = locomotive
+ };
+ form.ShowDialog();
+ }
+
+ ///
+ /// Передача объекта в другую форму
+ ///
+ ///
+ ///
+ private void buttonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+
+ }
+}
+
diff --git a/ProjectElectricLocomotive/FormLocomotiveCollection.resx b/ProjectElectricLocomotive/FormLocomotiveCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/ProjectElectricLocomotive/FormLocomotiveCollection.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/ProjectElectricLocomotive/FormlectricLocomotive.Designer.cs b/ProjectElectricLocomotive/FormlectricLocomotive.Designer.cs
index 725b4ff..2fb348e 100644
--- a/ProjectElectricLocomotive/FormlectricLocomotive.Designer.cs
+++ b/ProjectElectricLocomotive/FormlectricLocomotive.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxElectricLocomotive = new PictureBox();
- buttonCreate = new Button();
buttonUp = new Button();
buttonLeft = new Button();
buttonRight = new Button();
buttonDown = new Button();
- buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxElectricLocomotive).BeginInit();
@@ -50,17 +48,6 @@
pictureBoxElectricLocomotive.TabIndex = 0;
pictureBoxElectricLocomotive.TabStop = false;
//
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 353);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(263, 34);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать ЭлектроЛокомотив";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += buttonCreate_Click;
- //
// buttonUp
//
buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -109,17 +96,6 @@
buttonDown.UseVisualStyleBackColor = true;
buttonDown.Click += ButtonMove_Click;
//
- // buttonCreateLocomotive
- //
- buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateLocomotive.Location = new Point(281, 353);
- buttonCreateLocomotive.Name = "buttonCreateLocomotive";
- buttonCreateLocomotive.Size = new Size(263, 34);
- buttonCreateLocomotive.TabIndex = 6;
- buttonCreateLocomotive.Text = "Создать Локомотив";
- buttonCreateLocomotive.UseVisualStyleBackColor = true;
- buttonCreateLocomotive.Click += buttonCreateLocomotive_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -147,12 +123,10 @@
ClientSize = new Size(788, 399);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonDown);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonUp);
- Controls.Add(buttonCreate);
Controls.Add(pictureBoxElectricLocomotive);
Name = "FormlectricLocomotive";
Text = "ЭлектроВоз";
@@ -163,12 +137,10 @@
#endregion
private PictureBox pictureBoxElectricLocomotive;
- private Button buttonCreate;
private Button buttonUp;
private Button buttonLeft;
private Button buttonRight;
private Button buttonDown;
- private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/ProjectElectricLocomotive/FormlectricLocomotive.cs b/ProjectElectricLocomotive/FormlectricLocomotive.cs
index 68036f4..c7ad903 100644
--- a/ProjectElectricLocomotive/FormlectricLocomotive.cs
+++ b/ProjectElectricLocomotive/FormlectricLocomotive.cs
@@ -20,7 +20,19 @@ namespace ProjectElectricLocomotive
///
private AbstractStrategy? _strategy;
- public FormlectricLocomotive()
+ public DrawningLocomotive SetLocomotive
+ {
+ set
+ {
+ _drawnningLocomotive = value;
+ _drawnningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
+ public FormlectricLocomotive()
{
InitializeComponent();
_strategy = null;
@@ -39,47 +51,9 @@ namespace ProjectElectricLocomotive
pictureBoxElectricLocomotive.Image = bmp;
}
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningLocomotive):
- _drawnningLocomotive = new DrawningLocomotive(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(DrawningElectricLocomotive):
- _drawnningLocomotive = new DrawningElectricLocomotive(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;
- }
- _drawnningLocomotive.SetPictureSize(pictureBoxElectricLocomotive.Width, pictureBoxElectricLocomotive.Height);
- _drawnningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
private DrawningLocomotive? _drawnningLocomotive;
- ///
- /// Обработка кнопки создать "ЭлектроЛокомотив"
- ///
- ///
- ///
- private void buttonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningElectricLocomotive));
- ///
- /// Обработка нажатия кнопки создать "Локомотив"
- ///
- ///
- ///
- private void buttonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
-
private void ButtonMove_Click(object sender, EventArgs e)
{
if (_drawnningLocomotive == null)
@@ -114,7 +88,7 @@ namespace ProjectElectricLocomotive
}
-
+
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawnningLocomotive == null)
diff --git a/ProjectElectricLocomotive/Program.cs b/ProjectElectricLocomotive/Program.cs
index d71f655..5def1ba 100644
--- a/ProjectElectricLocomotive/Program.cs
+++ b/ProjectElectricLocomotive/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectElectricLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormlectricLocomotive());
+ Application.Run(new FormLocomotiveCollection());
}
}
}
\ No newline at end of file