diff --git a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/AbstractCompany.cs b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..236a4bb
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,115 @@
+using WarmlyLocomotive.Drawnings;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+namespace WarmlyLocomotive.CollectionGenericObjects;
+
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 80;
+
+ ///
+ /// Ширина окна
+ ///
+ 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 int operator +(AbstractCompany company, DrawningLocomotive locomotive)
+ {
+ return company._collection.Insert(locomotive);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningLocomotive operator -(AbstractCompany company, int position)
+ {
+ return company._collection.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ 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();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawningLocomotive? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
index e6fe871..ab634d3 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -22,7 +22,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -30,14 +30,14 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
diff --git a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/LocomotiveSharingService.cs b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/LocomotiveSharingService.cs
new file mode 100644
index 0000000..80631f1
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/LocomotiveSharingService.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using WarmlyLocomotive.Drawnings;
+
+namespace WarmlyLocomotive.CollectionGenericObjects;
+
+public class LocomotiveSharingService : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public LocomotiveSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new Pen(Color.Black, 2);
+ for (int i = 0; i<_pictureWidth / _placeSizeWidth + 1; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; j++)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth - 40, j * _placeSizeHeight);
+
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ int height = _pictureHeight / _placeSizeHeight;
+ int width = _pictureWidth / _placeSizeWidth;
+ int curheight = 0;
+ int curwidth = width;
+
+ for (int i=0; i<(_collection?.Count ?? 0); i++)
+ {
+ if (curheight > height)
+ {
+ return;
+ }
+ if (_collection.Get(i) != null)
+ {
+ _collection?.Get(i)?.SetPictureSize(_pictureWidth, _pictureHeight);
+
+ _collection?.Get(i)?.SetPosition(_placeSizeWidth * curwidth + 40, curheight * _placeSizeHeight + 20);
+ }
+
+ if (curwidth > 0)
+ {
+ curwidth--;
+ }
+ else
+ {
+ curwidth = width;
+ curheight++;
+ }
+ }
+ }
+}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
index 2a63e64..7d2bf50 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -43,29 +43,76 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
// TODO проверка позиции
+ if (position < 0 || position > _collection.Length) {
+ return null;
+ }
return _collection[position];
}
- public bool Insert(T obj)
+ public int Insert(T obj)
{
// TODO вставка в свободное место набора
- return false;
+ for (int i=0; i < _collection.Length; i++)
+ {
+ if (_collection[i] == null) {
+ _collection[i] = obj;
+ return i;
+ }
+ }
+ return -1;
}
- public bool Insert(T obj, int position)
+ public int Insert(T obj, int position)
{
// TODO проверка позиции
+ if (position > _collection.Length || position < 0)
+ {
+ return -1;
+ }
// TODO проверка, что элемент массива по этой позиции пустой, если нет, то
// ищется свободное место после этой позиции и идет вставка туда
// если нет после, ищем до
- // TODO вставка
- return false;
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return position;
+ }
+
+ for (int tmp = position + 1; tmp < _collection.Length; tmp++)
+ {
+ if (_collection[tmp] == null)
+ {
+ _collection[tmp] = obj;
+ return tmp;
+ }
+ }
+
+ for (int tmp = position - 1; tmp >= 0; tmp--)
+ {
+ if (_collection[tmp] == null)
+ {
+ _collection[tmp] = obj;
+ return tmp;
+ }
+ }
+
+ return -1;
}
- public bool Remove(int position)
+ public T? Remove(int position)
{
// TODO проверка позиции
+ if (position < 0 || position > _collection.Length) {
+ return null;
+ }
+
+ if (_collection[position] == null)
+ {
+ return null;
+ }
+ T? tmp = _collection[position];
+ _collection[position] = null;
// TODO удаление объекта из массива, присвоив элементу массива значение null
- return true;
+ return tmp;
}
}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.Designer.cs
new file mode 100644
index 0000000..893eb54
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.Designer.cs
@@ -0,0 +1,177 @@
+namespace WarmlyLocomotive
+{
+ 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();
+ buttonRemoveLocomotive = new Button();
+ maskedTextBoxPosition = new MaskedTextBox();
+ buttonAddWarmlyLocomotive = 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(buttonRemoveLocomotive);
+ groupBoxTools.Controls.Add(maskedTextBoxPosition);
+ groupBoxTools.Controls.Add(buttonAddWarmlyLocomotive);
+ groupBoxTools.Controls.Add(buttonAddLocomotive);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(808, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(193, 527);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Инструменты";
+ groupBoxTools.Enter += groupBoxTools_Enter;
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 440);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(175, 48);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Обновить";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(6, 348);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(175, 48);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveLocomotive
+ //
+ buttonRemoveLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveLocomotive.Location = new Point(6, 294);
+ buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
+ buttonRemoveLocomotive.Size = new Size(175, 48);
+ buttonRemoveLocomotive.TabIndex = 4;
+ buttonRemoveLocomotive.Text = "Удалить локомотив";
+ buttonRemoveLocomotive.UseVisualStyleBackColor = true;
+ buttonRemoveLocomotive.Click += ButtonRemoveLocomotive_Click;
+ //
+ // maskedTextBoxPosition
+ //
+ maskedTextBoxPosition.Location = new Point(6, 234);
+ maskedTextBoxPosition.Mask = "00";
+ maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ maskedTextBoxPosition.Size = new Size(175, 27);
+ maskedTextBoxPosition.TabIndex = 3;
+ maskedTextBoxPosition.ValidatingType = typeof(int);
+ maskedTextBoxPosition.MaskInputRejected += maskedTextBoxPosition_MaskInputRejected;
+ //
+ // buttonAddWarmlyLocomotive
+ //
+ buttonAddWarmlyLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddWarmlyLocomotive.Location = new Point(6, 142);
+ buttonAddWarmlyLocomotive.Name = "buttonAddWarmlyLocomotive";
+ buttonAddWarmlyLocomotive.Size = new Size(175, 48);
+ buttonAddWarmlyLocomotive.TabIndex = 2;
+ buttonAddWarmlyLocomotive.Text = "Добавление локомотива";
+ buttonAddWarmlyLocomotive.UseVisualStyleBackColor = true;
+ buttonAddWarmlyLocomotive.Click += ButtonAddWarmlyLocomotive_Click;
+ //
+ // buttonAddLocomotive
+ //
+ buttonAddLocomotive.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddLocomotive.Location = new Point(6, 88);
+ buttonAddLocomotive.Name = "buttonAddLocomotive";
+ buttonAddLocomotive.Size = new Size(175, 48);
+ 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(6, 26);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(175, 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(808, 527);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ pictureBox.Click += pictureBox_Click;
+ //
+ // FormLocomotiveCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1001, 527);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormLocomotiveCollection";
+ Text = "Коллекция локомотивов";
+ Load += FormLocomotiveCollection_Load;
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddLocomotive;
+ private Button buttonAddWarmlyLocomotive;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ private Button buttonRemoveLocomotive;
+ private MaskedTextBox maskedTextBoxPosition;
+ }
+}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.cs
new file mode 100644
index 0000000..c30e711
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.cs
@@ -0,0 +1,187 @@
+using WarmlyLocomotive.CollectionGenericObjects;
+using WarmlyLocomotive.Drawnings;
+
+namespace WarmlyLocomotive;
+
+///
+/// Форма работы с компанией и ее коллекцией
+///
+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 LocomotiveSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ 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(DrawningWarmlyLocomotive):
+ drawningLocomotive = new DrawningWarmlyLocomotive(random.Next(100, 300), random.Next(1000, 3000), GetColor(random), GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ if (_company + drawningLocomotive != -1)
+ {
+ 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 pictureBox_Click(object sender, EventArgs e)
+ {
+
+ }
+
+ private void FormLocomotiveCollection_Load(object sender, EventArgs e)
+ {
+
+ }
+
+ private void groupBoxTools_Enter(object sender, EventArgs e)
+ {
+
+ }
+
+ private void ButtonAddWarmlyLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarmlyLocomotive));
+
+ private void ButtonAddLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
+
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_company - pos != null)
+ {
+ 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;
+ }
+ FormWarmlyLocomotive form = new()
+ {
+ SetLocomotive = locomotive
+ };
+ form.ShowDialog();
+
+ }
+
+ ///
+ /// Перерисовка коллекции
+ ///
+ ///
+ ///
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ pictureBox.Image = _company.Show();
+ }
+
+ private void maskedTextBoxPosition_MaskInputRejected(object sender, MaskInputRejectedEventArgs e)
+ {
+
+ }
+}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.resx b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotiveCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/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/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs
index 831d23a..5dca08b 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxWarmlyLocomotive = new PictureBox();
- buttonCreateWarmlyLocomotive = new Button();
buttonLeft = new Button();
buttonDown = new Button();
buttonRight = new Button();
buttonUp = new Button();
- buttonCreateLocomotive = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxWarmlyLocomotive).BeginInit();
@@ -49,17 +47,6 @@
pictureBoxWarmlyLocomotive.TabIndex = 0;
pictureBoxWarmlyLocomotive.TabStop = false;
//
- // buttonCreateWarmlyLocomotive
- //
- buttonCreateWarmlyLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateWarmlyLocomotive.Location = new Point(12, 409);
- buttonCreateWarmlyLocomotive.Name = "buttonCreateWarmlyLocomotive";
- buttonCreateWarmlyLocomotive.Size = new Size(156, 29);
- buttonCreateWarmlyLocomotive.TabIndex = 1;
- buttonCreateWarmlyLocomotive.Text = "создать локомотив";
- buttonCreateWarmlyLocomotive.UseVisualStyleBackColor = true;
- buttonCreateWarmlyLocomotive.Click += ButtonCreateWarmlyLocomotive_Click;
- //
// buttonLeft
//
buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right;
@@ -108,17 +95,6 @@
buttonUp.UseVisualStyleBackColor = true;
buttonUp.Click += ButtonMove_Click;
//
- // buttonCreateLocomotive
- //
- buttonCreateLocomotive.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateLocomotive.Location = new Point(174, 409);
- buttonCreateLocomotive.Name = "buttonCreateLocomotive";
- buttonCreateLocomotive.Size = new Size(156, 29);
- buttonCreateLocomotive.TabIndex = 6;
- buttonCreateLocomotive.Text = "создать паровоз";
- buttonCreateLocomotive.UseVisualStyleBackColor = true;
- buttonCreateLocomotive.Click += ButtonCreateLocomotive_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -146,12 +122,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateLocomotive);
Controls.Add(buttonUp);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateWarmlyLocomotive);
Controls.Add(pictureBoxWarmlyLocomotive);
Name = "FormWarmlyLocomotive";
Text = "тепловоз";
@@ -162,12 +136,10 @@
#endregion
private PictureBox pictureBoxWarmlyLocomotive;
- private Button buttonCreateWarmlyLocomotive;
private Button buttonLeft;
private Button buttonDown;
private Button buttonRight;
private Button buttonUp;
- private Button buttonCreateLocomotive;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.cs
index 9065f4e..84aff19 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormWarmlyLocomotive.cs
@@ -18,6 +18,21 @@ public partial class FormWarmlyLocomotive : Form
///
private AbstractStrategy? _strategy;
+ ///
+ /// Получение объекта
+ ///
+ public DrawningLocomotive SetLocomotive
+ {
+ set
+ {
+ _drawningLocomotive = value;
+ _drawningLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
+
///
/// Конструктор формы
///
@@ -42,49 +57,6 @@ public partial class FormWarmlyLocomotive : Form
pictureBoxWarmlyLocomotive.Image = bmp;
}
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningLocomotive):
- _drawningLocomotive = 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(DrawningWarmlyLocomotive):
- _drawningLocomotive = new DrawningWarmlyLocomotive(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)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
- _drawningLocomotive.SetPictureSize(pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
- _drawningLocomotive.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- ///
- /// Обработка нажатия кнопки "Создать локомотив"
- ///
- ///
- ///
- private void ButtonCreateWarmlyLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningWarmlyLocomotive));
-
- ///
- /// Обработка нажатия кнопки "Создать паровоз"
- ///
- ///
- ///
- private void ButtonCreateLocomotive_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningLocomotive));
-
///
/// Перемещение объекта по форме (нажатие кнопок навигации)
///
diff --git a/WarmlyLocomotive/WarmlyLocomotive/Program.cs b/WarmlyLocomotive/WarmlyLocomotive/Program.cs
index b972d2a..12147e2 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/Program.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/Program.cs
@@ -11,7 +11,7 @@ namespace WarmlyLocomotive
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormWarmlyLocomotive());
+ Application.Run(new FormLocomotiveCollection());
}
}
}
\ No newline at end of file