diff --git a/WarmlyLocomotive/DrawningObjectCar.cs b/WarmlyLocomotive/DrawningObjectWarmlyLocomotive.cs
similarity index 82%
rename from WarmlyLocomotive/DrawningObjectCar.cs
rename to WarmlyLocomotive/DrawningObjectWarmlyLocomotive.cs
index b8b339e..1372c1d 100644
--- a/WarmlyLocomotive/DrawningObjectCar.cs
+++ b/WarmlyLocomotive/DrawningObjectWarmlyLocomotive.cs
@@ -2,12 +2,12 @@
namespace WarmlyLocomotive.MovementStrategy
{
- internal class DrawningObjectCar : IMoveableObject
+ internal class DrawningObjectWarmlyLocomotive : IMoveableObject
{
private readonly DrawningWarmlyLocomotive? _drawningWarmlyLocomotive = null;
- public DrawningObjectCar(DrawningWarmlyLocomotive drawningCar)
+ public DrawningObjectWarmlyLocomotive(DrawningWarmlyLocomotive drawningWarmlylocomotive)
{
- _drawningWarmlyLocomotive = drawningCar;
+ _drawningWarmlyLocomotive = drawningWarmlylocomotive;
}
public ObjectParameters? GetObjectPosition
{
diff --git a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs
index 15df6f6..3c5ec72 100644
--- a/WarmlyLocomotive/DrawningWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/DrawningWarmlyLocomotive.cs
@@ -12,7 +12,7 @@ public class DrawningWarmlyLocomotive
/// Класс-сущность
///
public EntityWarmlyLocomotive? EntityWarmlyLocomotive { get; protected set; }
- public IMoveableObject GetMoveableObject => new DrawningObjectCar(this);
+ public IMoveableObject GetMoveableObject => new DrawningObjectWarmlyLocomotive(this);
///
/// Ширина окна
///
@@ -22,19 +22,19 @@ public class DrawningWarmlyLocomotive
///
private int _pictureHeight;
///
- /// Левая координата прорисовки локомотива
+ /// Левая координата прорисовки тепловоза
///
protected int _startPosX;
///
- /// Верхняя кооридната прорисовки локомотива
+ /// Верхняя кооридната прорисовки тепловоза
///
protected int _startPosY;
///
- /// Ширина прорисовки локомотива
+ /// Ширина прорисовки тепловоза
///
protected readonly int _WarmlyLocomotiveWidth = 200;
///
- /// Высота прорисовки локомотива
+ /// Высота прорисовки тепловоза
///
protected readonly int _WarmlyLocomotiveHeight = 75;
private readonly int _trumpetHeight = 25;
diff --git a/WarmlyLocomotive/EntityWarmlyLocomotive.cs b/WarmlyLocomotive/EntityWarmlyLocomotive.cs
index f5ce921..09ca708 100644
--- a/WarmlyLocomotive/EntityWarmlyLocomotive.cs
+++ b/WarmlyLocomotive/EntityWarmlyLocomotive.cs
@@ -1,7 +1,7 @@
namespace WarmlyLocomotive.Entities
{
///
- /// Класс-сущность "Автомобиль"
+ /// Класс-сущность "Тепловоз"
///
public class EntityWarmlyLocomotive
{
diff --git a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs
index 867fb26..1760ef0 100644
--- a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs
+++ b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.Designer.cs
@@ -30,12 +30,19 @@
{
labelCollection = new Label();
panelCollectionWarmlyLocomotive = new Panel();
+ labelGenericCollection = new Label();
+ panel1 = new Panel();
+ buttonDelObject = new Button();
+ textBoxStorageName = new TextBox();
+ listBoxStorages = new ListBox();
+ buttonAddObject = new Button();
buttonreFreshCollection = new Button();
- textBoxCollectionWarmlyLocomotive = new TextBox();
+ maskedTextBoxNumber = new TextBox();
buttonRemove = new Button();
- buttonadd = new Button();
+ buttonAdd = new Button();
pictureBoxCollectionWarmlyLocomotive = new PictureBox();
panelCollectionWarmlyLocomotive.SuspendLayout();
+ panel1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).BeginInit();
SuspendLayout();
//
@@ -51,18 +58,77 @@
//
// panelCollectionWarmlyLocomotive
//
+ panelCollectionWarmlyLocomotive.Controls.Add(labelGenericCollection);
+ panelCollectionWarmlyLocomotive.Controls.Add(panel1);
panelCollectionWarmlyLocomotive.Controls.Add(buttonreFreshCollection);
- panelCollectionWarmlyLocomotive.Controls.Add(textBoxCollectionWarmlyLocomotive);
+ panelCollectionWarmlyLocomotive.Controls.Add(maskedTextBoxNumber);
panelCollectionWarmlyLocomotive.Controls.Add(buttonRemove);
- panelCollectionWarmlyLocomotive.Controls.Add(buttonadd);
+ panelCollectionWarmlyLocomotive.Controls.Add(buttonAdd);
panelCollectionWarmlyLocomotive.Location = new Point(662, 28);
panelCollectionWarmlyLocomotive.Name = "panelCollectionWarmlyLocomotive";
- panelCollectionWarmlyLocomotive.Size = new Size(149, 350);
+ panelCollectionWarmlyLocomotive.Size = new Size(149, 410);
panelCollectionWarmlyLocomotive.TabIndex = 1;
//
+ // labelGenericCollection
+ //
+ labelGenericCollection.AutoSize = true;
+ labelGenericCollection.Location = new Point(17, -1);
+ labelGenericCollection.Name = "labelGenericCollection";
+ labelGenericCollection.Size = new Size(52, 15);
+ labelGenericCollection.TabIndex = 5;
+ labelGenericCollection.Text = "Наборы";
+ //
+ // panel1
+ //
+ panel1.Controls.Add(buttonDelObject);
+ panel1.Controls.Add(textBoxStorageName);
+ panel1.Controls.Add(listBoxStorages);
+ panel1.Controls.Add(buttonAddObject);
+ panel1.Location = new Point(3, 16);
+ panel1.Name = "panel1";
+ panel1.Size = new Size(143, 209);
+ panel1.TabIndex = 4;
+ //
+ // buttonDelObject
+ //
+ buttonDelObject.Location = new Point(15, 175);
+ buttonDelObject.Name = "buttonDelObject";
+ buttonDelObject.Size = new Size(115, 23);
+ buttonDelObject.TabIndex = 3;
+ buttonDelObject.Text = "Удалить набор";
+ buttonDelObject.UseVisualStyleBackColor = true;
+ buttonDelObject.Click += buttonDelObject_Click;
+ //
+ // textBoxStorageName
+ //
+ textBoxStorageName.Location = new Point(13, 13);
+ textBoxStorageName.Name = "textBoxStorageName";
+ textBoxStorageName.Size = new Size(117, 23);
+ textBoxStorageName.TabIndex = 2;
+ //
+ // listBoxStorages
+ //
+ listBoxStorages.FormattingEnabled = true;
+ listBoxStorages.ItemHeight = 15;
+ listBoxStorages.Location = new Point(14, 90);
+ listBoxStorages.Name = "listBoxStorages";
+ listBoxStorages.Size = new Size(119, 79);
+ listBoxStorages.TabIndex = 1;
+ listBoxStorages.SelectedIndexChanged += listBoxStorages_SelectedIndexChanged;
+ //
+ // buttonAddObject
+ //
+ buttonAddObject.Location = new Point(15, 51);
+ buttonAddObject.Name = "buttonAddObject";
+ buttonAddObject.Size = new Size(118, 22);
+ buttonAddObject.TabIndex = 0;
+ buttonAddObject.Text = "Добавить набор";
+ buttonAddObject.UseVisualStyleBackColor = true;
+ buttonAddObject.Click += buttonAddObject_Click;
+ //
// buttonreFreshCollection
//
- buttonreFreshCollection.Location = new Point(3, 193);
+ buttonreFreshCollection.Location = new Point(3, 325);
buttonreFreshCollection.Name = "buttonreFreshCollection";
buttonreFreshCollection.Size = new Size(146, 23);
buttonreFreshCollection.TabIndex = 3;
@@ -70,38 +136,38 @@
buttonreFreshCollection.UseVisualStyleBackColor = true;
buttonreFreshCollection.Click += buttonreFreshCollection_Click;
//
- // textBoxCollectionWarmlyLocomotive
+ // maskedTextBoxNumber
//
- textBoxCollectionWarmlyLocomotive.Location = new Point(17, 128);
- textBoxCollectionWarmlyLocomotive.Name = "textBoxCollectionWarmlyLocomotive";
- textBoxCollectionWarmlyLocomotive.Size = new Size(117, 23);
- textBoxCollectionWarmlyLocomotive.TabIndex = 2;
+ maskedTextBoxNumber.Location = new Point(16, 296);
+ maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ maskedTextBoxNumber.Size = new Size(117, 23);
+ maskedTextBoxNumber.TabIndex = 2;
//
// buttonRemove
//
- buttonRemove.Location = new Point(3, 71);
+ buttonRemove.Location = new Point(6, 369);
buttonRemove.Name = "buttonRemove";
- buttonRemove.Size = new Size(131, 23);
+ buttonRemove.Size = new Size(143, 23);
buttonRemove.TabIndex = 1;
buttonRemove.Text = "Удалить тепловоз";
buttonRemove.UseVisualStyleBackColor = true;
buttonRemove.Click += buttonRemove_Click;
//
- // buttonadd
+ // buttonAdd
//
- buttonadd.Location = new Point(3, 22);
- buttonadd.Name = "buttonadd";
- buttonadd.Size = new Size(131, 23);
- buttonadd.TabIndex = 0;
- buttonadd.Text = "Добавить тепловоз";
- buttonadd.UseVisualStyleBackColor = true;
- buttonadd.Click += buttonAdd_Click;
+ buttonAdd.Location = new Point(6, 247);
+ buttonAdd.Name = "buttonAdd";
+ buttonAdd.Size = new Size(143, 22);
+ buttonAdd.TabIndex = 0;
+ buttonAdd.Text = "Добавить тепловоз";
+ buttonAdd.UseVisualStyleBackColor = true;
+ buttonAdd.Click += buttonAdd_Click;
//
// pictureBoxCollectionWarmlyLocomotive
//
pictureBoxCollectionWarmlyLocomotive.Location = new Point(12, 28);
pictureBoxCollectionWarmlyLocomotive.Name = "pictureBoxCollectionWarmlyLocomotive";
- pictureBoxCollectionWarmlyLocomotive.Size = new Size(647, 350);
+ pictureBoxCollectionWarmlyLocomotive.Size = new Size(647, 410);
pictureBoxCollectionWarmlyLocomotive.TabIndex = 2;
pictureBoxCollectionWarmlyLocomotive.TabStop = false;
//
@@ -117,6 +183,8 @@
Text = "FormWarmlyLocomotiveCollection";
panelCollectionWarmlyLocomotive.ResumeLayout(false);
panelCollectionWarmlyLocomotive.PerformLayout();
+ panel1.ResumeLayout(false);
+ panel1.PerformLayout();
((System.ComponentModel.ISupportInitialize)pictureBoxCollectionWarmlyLocomotive).EndInit();
ResumeLayout(false);
PerformLayout();
@@ -127,9 +195,15 @@
private Label labelCollection;
private Panel panelCollectionWarmlyLocomotive;
private PictureBox pictureBoxCollectionWarmlyLocomotive;
- private Button buttonadd;
+ private Button buttonAdd;
private Button buttonRemove;
private Button buttonreFreshCollection;
- private TextBox textBoxCollectionWarmlyLocomotive;
+ private TextBox maskedTextBoxNumber;
+ private Label labelGenericCollection;
+ private Panel panel1;
+ private Button buttonAddObject;
+ private ListBox listBoxStorages;
+ private TextBox textBoxStorageName;
+ private Button buttonDelObject;
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs
index a3d054a..cb85cbb 100644
--- a/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs
+++ b/WarmlyLocomotive/FormWarmlyLocomotiveCollection.cs
@@ -1,28 +1,102 @@
-using WarmlyLocomotive.DrawningObjects;
-using WarmlyLocomotive.Generics;
+using WarmlyLocomotive.Generics;
using WarmlyLocomotive.MovementStrategy;
-
+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 WarmlyLocomotive
{
public partial class FormWarmlyLocomotiveCollection : Form
{
- private readonly CarsGenericCollection _warmlylocomotives;
+ ///
+ /// Набор объектов
+ ///
+ private readonly WarmlyLocomotivesGenericStorage _storage;
public FormWarmlyLocomotiveCollection()
{
InitializeComponent();
- _warmlylocomotives = new CarsGenericCollection(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
+ _storage = new WarmlyLocomotivesGenericStorage(pictureBoxCollectionWarmlyLocomotive.Width, pictureBoxCollectionWarmlyLocomotive.Height);
}
-
+ ///
+ /// Заполнение listBoxObjects
+ ///
+ private void ReloadObjects()
+ {
+ int index = listBoxStorages.SelectedIndex;
+ listBoxStorages.Items.Clear();
+ for (int i = 0; i < _storage.Keys.Count; i++)
+ {
+ listBoxStorages.Items.Add(_storage.Keys[i]);
+ }
+ if (listBoxStorages.Items.Count > 0 && (index == -1 || index
+ >= listBoxStorages.Items.Count))
+ {
+ listBoxStorages.SelectedIndex = 0;
+ }
+ else if (listBoxStorages.Items.Count > 0 && index > -1 &&
+ index < listBoxStorages.Items.Count)
+ {
+ listBoxStorages.SelectedIndex = index;
+ }
+ }
+ ///
+ /// Выбор набора
+ ///
+ ///
+ ///
+ private void listBoxStorages_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBoxCollectionWarmlyLocomotive.Image =
+ _storage[listBoxStorages.SelectedItem?.ToString() ?? string.Empty]?.ShowWarmlyLocomotives();
+ }
+ ///
+ /// Удаление набора
+ ///
+ ///
+ ///
+ private void buttonDelObject_Click(object sender, EventArgs e)
+ {
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ if (MessageBox.Show($"Удалить объект {listBoxStorages.SelectedItem}?",
+ "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _storage.DelSet(listBoxStorages.SelectedItem.ToString()
+ ?? string.Empty);
+ ReloadObjects();
+ }
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ ///
+ ///
private void buttonAdd_Click(object sender, EventArgs e)
{
- WarmlyLocomotiveForm form = new();
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+ string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ WarmlyLocomotiveForm form = new();
if (form.ShowDialog() == DialogResult.OK)
{
- if (_warmlylocomotives + form.SelectedCar != null)
+ if (obj + form.SelectedWarmlyLocomotive)
{
MessageBox.Show("Объект добавлен");
- pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
+ pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
}
else
{
@@ -31,35 +105,73 @@ namespace WarmlyLocomotive
}
}
-
- private void buttonreFreshCollection_Click(object sender, EventArgs e)
- {
- pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
- }
-
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
private void buttonRemove_Click(object sender, EventArgs e)
{
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+ string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
if (MessageBox.Show("Удалить объект?", "Удаление",
- MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
{
return;
}
- int pos;
- if (textBoxCollectionWarmlyLocomotive.Text == null || !int.TryParse(textBoxCollectionWarmlyLocomotive.Text, out pos))
- {
- MessageBox.Show("Введите номер парковочного места");
- return;
- }
-
- if (_warmlylocomotives - pos != null)
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (obj - pos != null)
{
MessageBox.Show("Объект удален");
- pictureBoxCollectionWarmlyLocomotive.Image = _warmlylocomotives.ShowCars();
+ pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
}
else
{
MessageBox.Show("Не удалось удалить объект");
}
}
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
+ private void buttonreFreshCollection_Click(object sender, EventArgs e)
+ {
+ if (listBoxStorages.SelectedIndex == -1)
+ {
+ return;
+ }
+ var obj = _storage[listBoxStorages.SelectedItem.ToString() ??
+ string.Empty];
+ if (obj == null)
+ {
+ return;
+ }
+ pictureBoxCollectionWarmlyLocomotive.Image = obj.ShowWarmlyLocomotives();
+ }
+ ///
+ /// Добавление набора в коллекцию
+ ///
+ ///
+ ///
+ private void buttonAddObject_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(textBoxStorageName.Text))
+ {
+ MessageBox.Show("Не все данные заполнены", "Ошибка",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _storage.AddSet(textBoxStorageName.Text);
+ ReloadObjects();
+ }
}
-}
+}
\ No newline at end of file
diff --git a/WarmlyLocomotive/Program.cs b/WarmlyLocomotive/Program.cs
index fc272d5..063fbae 100644
--- a/WarmlyLocomotive/Program.cs
+++ b/WarmlyLocomotive/Program.cs
@@ -12,7 +12,6 @@ namespace WarmlyLocomotive
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
Application.Run(new FormWarmlyLocomotiveCollection());
- Application.Run(new WarmlyLocomotiveForm());
}
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/SetGeneric.cs b/WarmlyLocomotive/SetGeneric.cs
index 3e0383e..eea1c51 100644
--- a/WarmlyLocomotive/SetGeneric.cs
+++ b/WarmlyLocomotive/SetGeneric.cs
@@ -4,95 +4,107 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
-
- namespace WarmlyLocomotive.Generics
+namespace WarmlyLocomotive.Generics
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetGeneric
+ where T : class
{
- internal class SetGeneric
- where T : class
+ ///
+ /// Список объектов, которые храним
+ ///
+ private readonly List _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Count;
+ ///
+ /// Максимальное количество объектов в списке
+ ///
+ private readonly int _maxCount;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetGeneric(int count)
{
- ///
- /// Массив объектов, которые храним
- ///
- private readonly T?[] _places;
- ///
- /// Количество объектов в массиве
- ///
- public int Count => _places.Length;
- ///
- /// Конструктор
- ///
- ///
- ///
- public int startPointer = 0;
- public SetGeneric(int count)
+ _maxCount = count;
+ _places = new List(count);
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый тепловоз
+ ///
+ public bool Insert(T warmlylocomotive)
+ {
+ if (_places.Count == _maxCount)
{
- _places = new T?[count];
- }
- ///
- /// Добавление объекта в набор
- ///
- /// Добавляемый автомобиль
- ///
- public int Insert(T car)
- {
- if (_places[Count - 1] != null)
- return -1;
- return Insert(car, 0);
- }
- ///
- /// Добавление объекта в набор на конкретную позицию
- ///
- /// Добавляемый автомобиль
- /// Позиция
- ///
- public int Insert(T car, int position)
- {
- int nullIndex = -1, i;
-
- if (position < 0 || position >= Count)
- return -1;
- for (i = position; i < Count; i++)
- {
- if (_places[i] == null)
- {
- nullIndex = i;
- break;
- }
- }
- if (nullIndex < 0)
- return -1;
-
- for (i = nullIndex; i > position; i--)
- {
- _places[i] = _places[i - 1];
- }
- _places[position] = car;
- return position;
- }
- ///
- /// Удаление объекта из набора с конкретной позиции
- ///
- ///
- ///
- public bool Remove(int position)
- {
- if (position < Count && position >= 0)
- {
- _places[position] = null;
- return true;
- }
return false;
}
- ///
- /// Получение объекта из набора по позиции
- ///
- ///
- ///
- public T? Get(int position)
+ Insert(warmlylocomotive, 0);
+ return true;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый тепловоз
+ /// Позиция
+ ///
+ public bool Insert(T warmlylocomotive, int position)
+ {
+ if (!(position >= 0 && position <= Count && _places.Count < _maxCount)) return false;
+ _places.Insert(position, warmlylocomotive);
+ return true;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ if (position < 0 || position >= Count) return false;
+ _places.RemoveAt(position);
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? this[int position]
+ {
+ get
{
- if (position < Count && position >= 0) { return _places[position]; }
- return null;
+ if (position < 0 || position >= Count) return null;
+ return _places[position];
+ }
+ set
+ {
+ if (!(position >= 0 && position < Count && _places.Count < _maxCount)) return;
+ _places.Insert(position, value);
+ return;
+ }
+ }
+ ///
+ /// Проход по списку
+ ///
+ ///
+ public IEnumerable GetWarmlyLocomotives(int? maxWarmlyLocomotives = null)
+ {
+ for (int i = 0; i < _places.Count; ++i)
+ {
+ yield return _places[i];
+ if (maxWarmlyLocomotives.HasValue && i == maxWarmlyLocomotives.Value)
+ {
+ yield break;
+ }
}
}
}
+}
diff --git a/WarmlyLocomotive/WarmlyLocomotiveForm.cs b/WarmlyLocomotive/WarmlyLocomotiveForm.cs
index 58f42d6..cfccc4f 100644
--- a/WarmlyLocomotive/WarmlyLocomotiveForm.cs
+++ b/WarmlyLocomotive/WarmlyLocomotiveForm.cs
@@ -7,20 +7,18 @@ using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive
{
///
- /// " "
+ /// " "
///
public partial class WarmlyLocomotiveForm : Form
{
private DrawningWarmlyLocomotive? _drawningWarmlyLocomotive;
-
- private AbstractStrategy? _abstractStrategy;
private AbstractStrategy? _strategy;
- public DrawningWarmlyLocomotive? SelectedCar { get; private set; }
+ public DrawningWarmlyLocomotive? SelectedWarmlyLocomotive { get; private set; }
public WarmlyLocomotiveForm()
{
InitializeComponent();
_strategy = null;
- SelectedCar = null;
+ SelectedWarmlyLocomotive = null;
}
///
///
@@ -99,32 +97,32 @@ namespace WarmlyLocomotive
}
if (comboBoxWarmlyLocomotive.Enabled)
{
- _abstractStrategy = comboBoxWarmlyLocomotive.SelectedIndex
+ _strategy = comboBoxWarmlyLocomotive.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.SetData(new
- DrawningObjectCar(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
+ _strategy.SetData(new
+ DrawningObjectWarmlyLocomotive(_drawningWarmlyLocomotive), pictureBoxWarmlyLocomotive.Width,
pictureBoxWarmlyLocomotive.Height);
comboBoxWarmlyLocomotive.Enabled = false;
}
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.MakeStep();
+ _strategy.MakeStep();
Draw();
- if (_abstractStrategy.GetStatus() == Status.Finish)
+ if (_strategy.GetStatus() == Status.Finish)
{
comboBoxWarmlyLocomotive.Enabled = true;
- _abstractStrategy = null;
+ _strategy = null;
}
}
///
@@ -132,6 +130,37 @@ namespace WarmlyLocomotive
///
///
///
+ private void buttonCreate_WarmlyLocomotivePro_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));
+ ColorDialog dopDialog = new();
+ if (dopDialog.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dopDialog.Color;
+ }
+ _drawningWarmlyLocomotive = new DrawningWarmlyLocomotiveWithTrumpet(random.Next(100, 300),
+ random.Next(1000, 3000),
+ color,
+ dopColor,
+ Convert.ToBoolean(random.Next(0, 2)),
+ Convert.ToBoolean(random.Next(0, 2)),
+ pictureBoxWarmlyLocomotive.Width, pictureBoxWarmlyLocomotive.Height);
+ _drawningWarmlyLocomotive.SetPosition(random.Next(10, 100), random.Next(10,
+ 100));
+ Draw();
+ }
+ private void buttonSelectWarmlyLocomotive_Click(object sender, EventArgs e)
+ {
+ SelectedWarmlyLocomotive = _drawningWarmlyLocomotive;
+ DialogResult = DialogResult.OK;
+ }
private void buttonCreate_Pro_Click(object sender, EventArgs e)
{
Random random = new();
@@ -158,11 +187,5 @@ namespace WarmlyLocomotive
100));
Draw();
}
-
- private void buttonSelectCar_Click(object sender, EventArgs e)
- {
- SelectedCar = _drawningWarmlyLocomotive;
- DialogResult = DialogResult.OK;
- }
}
}
diff --git a/WarmlyLocomotive/CarsGenericCollectioncs.cs b/WarmlyLocomotive/WarmlyLocomotivesGenericCollectioncs.cs
similarity index 85%
rename from WarmlyLocomotive/CarsGenericCollectioncs.cs
rename to WarmlyLocomotive/WarmlyLocomotivesGenericCollectioncs.cs
index 32f1191..6a48e4a 100644
--- a/WarmlyLocomotive/CarsGenericCollectioncs.cs
+++ b/WarmlyLocomotive/WarmlyLocomotivesGenericCollectioncs.cs
@@ -2,7 +2,7 @@
using WarmlyLocomotive.MovementStrategy;
namespace WarmlyLocomotive.Generics
{
- internal class CarsGenericCollection
+ internal class WarmlyLocomotivesGenericCollection
where T : DrawningWarmlyLocomotive
where U : IMoveableObject
{
@@ -31,7 +31,7 @@ namespace WarmlyLocomotive.Generics
///
///
///
- public CarsGenericCollection(int picWidth, int picHeight)
+ public WarmlyLocomotivesGenericCollection(int picWidth, int picHeight)
{
int width = picWidth / _placeSizeWidth;
int height = picHeight / _placeSizeHeight;
@@ -45,14 +45,13 @@ namespace WarmlyLocomotive.Generics
///
///
///
- public static int operator +(CarsGenericCollection collect, T?
- obj)
+ public static bool operator +(WarmlyLocomotivesGenericCollection collect, T? obj)
{
if (obj == null)
{
- return -1;
+ return false;
}
- return collect._collection.Insert(obj);
+ return (bool)collect?._collection.Insert(obj);
}
///
/// Перегрузка оператора вычитания
@@ -60,15 +59,14 @@ namespace WarmlyLocomotive.Generics
///
///
///
- public static bool operator -(CarsGenericCollection collect, int
- pos)
+ public static bool operator -(WarmlyLocomotivesGenericCollection collect, int pos)
{
- T? obj = collect._collection.Get(pos);
+ T? obj = collect._collection[pos];
if (obj != null)
{
collect._collection.Remove(pos);
}
- return true;
+ return false;
}
///
/// Получение объекта IMoveableObject
@@ -77,13 +75,13 @@ namespace WarmlyLocomotive.Generics
///
public U? GetU(int pos)
{
- return (U?)_collection.Get(pos)?.GetMoveableObject;
+ return (U?)_collection[pos]?.GetMoveableObject;
}
///
/// Вывод всего набора объектов
///
///
- public Bitmap ShowCars()
+ public Bitmap ShowWarmlyLocomotives()
{
Bitmap bmp = new(_pictureWidth, _pictureHeight);
Graphics gr = Graphics.FromImage(bmp);
@@ -117,16 +115,16 @@ namespace WarmlyLocomotive.Generics
///
private void DrawObjects(Graphics g)
{
- DrawningWarmlyLocomotive warmlylocomotive;
+ int i = 0;
int numPlacesInRow = _pictureWidth / _placeSizeWidth;
- for (int i = 0; i < _collection.Count; i++)
+ foreach (var warmlylocomotive in _collection.GetWarmlyLocomotives())
{
- warmlylocomotive = _collection.Get(i);
if (warmlylocomotive != null)
{
warmlylocomotive.SetPosition((i % numPlacesInRow) * _placeSizeWidth + _placeSizeWidth / 20, _placeSizeHeight * (i / numPlacesInRow) + _placeSizeHeight / 10);
warmlylocomotive.DrawTransport(g);
}
+ i++;
}
}
}
diff --git a/WarmlyLocomotive/WarmlyLocomotivesGenericStorage.cs b/WarmlyLocomotive/WarmlyLocomotivesGenericStorage.cs
new file mode 100644
index 0000000..5d4233d
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotivesGenericStorage.cs
@@ -0,0 +1,40 @@
+using WarmlyLocomotive.DrawningObjects;
+using WarmlyLocomotive.MovementStrategy;
+namespace WarmlyLocomotive.Generics
+{
+ internal class WarmlyLocomotivesGenericStorage
+ {
+ readonly Dictionary> _warmlylocomotiveStorages;
+ public List Keys => _warmlylocomotiveStorages.Keys.ToList();
+ private readonly int _pictureWidth;
+
+ private readonly int _pictureHeight;
+ public WarmlyLocomotivesGenericStorage(int pictureWidth, int pictureHeight)
+ {
+ _warmlylocomotiveStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ public void AddSet(string name)
+ {
+ _warmlylocomotiveStorages.Add(name, new WarmlyLocomotivesGenericCollection(_pictureWidth, _pictureHeight));
+ }
+ public void DelSet(string name)
+ {
+ if (!_warmlylocomotiveStorages.ContainsKey(name))
+ return;
+ _warmlylocomotiveStorages.Remove(name);
+ }
+
+ public WarmlyLocomotivesGenericCollection? this[string ind]
+ {
+ get
+ {
+ if (_warmlylocomotiveStorages.ContainsKey(ind))
+ return _warmlylocomotiveStorages[ind];
+ return null;
+ }
+ }
+ }
+}
diff --git a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs
index 82933ad..a569215 100644
--- a/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs
+++ b/WarmlyLocomotive/WarmlylocomotiveForm.Designer.cs
@@ -149,7 +149,7 @@
buttonSelectCar.TabIndex = 11;
buttonSelectCar.Text = "Выбор тепловоза";
buttonSelectCar.UseVisualStyleBackColor = true;
- buttonSelectCar.Click += buttonSelectCar_Click;
+ buttonSelectCar.Click += buttonSelectWarmlyLocomotive_Click;
//
// WarmlyLocomotiveForm
//