diff --git a/WarmlyLocomotive/WarmlyLocomotive/Direction.cs b/WarmlyLocomotive/WarmlyLocomotive/Direction.cs
index 53e0dc8..0b3cb83 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/Direction.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/Direction.cs
@@ -9,7 +9,7 @@ namespace WarmlyLocomotive
///
/// Направление перемещения
///
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/WarmlyLocomotive/WarmlyLocomotive/DrawningLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/DrawningLocomotive.cs
index 8145c57..ed7a3fe 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/DrawningLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/DrawningLocomotive.cs
@@ -9,7 +9,7 @@ namespace WarmlyLocomotive
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- internal class DrawningLocomotive
+ public class DrawningLocomotive
{
///
/// Класс-сущность
diff --git a/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
index 36ee67c..59c79c5 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/EntityLocomotive.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace WarmlyLocomotive
{
- internal class EntityLocomotive
+ public class EntityLocomotive
{
///
/// Скорость
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.Designer.cs
index 843fe60..b3b4cbb 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.Designer.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.Designer.cs
@@ -39,6 +39,7 @@
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.buttonSelectLocomotive = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -153,11 +154,23 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
+ // buttonSelectLocomotive
+ //
+ this.buttonSelectLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonSelectLocomotive.Location = new System.Drawing.Point(618, 415);
+ this.buttonSelectLocomotive.Name = "buttonSelectLocomotive";
+ this.buttonSelectLocomotive.Size = new System.Drawing.Size(75, 23);
+ this.buttonSelectLocomotive.TabIndex = 8;
+ this.buttonSelectLocomotive.Text = "Выбрать";
+ this.buttonSelectLocomotive.UseVisualStyleBackColor = true;
+ this.buttonSelectLocomotive.Click += new System.EventHandler(this.ButtonSelectLocomotive_Click);
+ //
// FormLocomotive
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(837, 483);
+ this.Controls.Add(this.buttonSelectLocomotive);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonLeft);
this.Controls.Add(this.buttonDown);
@@ -190,5 +203,6 @@
private Button buttonDown;
private Button buttonLeft;
private Button buttonCreateModif;
+ private Button buttonSelectLocomotive;
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.cs b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.cs
index f46b6f9..a49a5e6 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.cs
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormLocomotive.cs
@@ -3,6 +3,7 @@ namespace WarmlyLocomotive
public partial class FormLocomotive : Form
{
private DrawningLocomotive _locomotive;
+ public DrawningLocomotive SelectedLocomotive { get; private set; }
public FormLocomotive()
{
InitializeComponent();
@@ -36,7 +37,13 @@ namespace WarmlyLocomotive
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
@@ -68,12 +75,27 @@ namespace WarmlyLocomotive
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
- _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialogDop = new();
+ if (dialogDop.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialogDop.Color;
+ }
+ _locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
+ private void ButtonSelectLocomotive_Click(object sender, EventArgs e)
+ {
+ SelectedLocomotive = _locomotive;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMap.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormMap.Designer.cs
deleted file mode 100644
index 62fd506..0000000
--- a/WarmlyLocomotive/WarmlyLocomotive/FormMap.Designer.cs
+++ /dev/null
@@ -1,209 +0,0 @@
-namespace WarmlyLocomotive
-{
- partial class FormMap
- {
- ///
- /// Required designer variable.
- ///
- private System.ComponentModel.IContainer components = null;
-
- ///
- /// Clean up any resources being used.
- ///
- /// true if managed resources should be disposed; otherwise, false.
- protected override void Dispose(bool disposing)
- {
- if (disposing && (components != null))
- {
- components.Dispose();
- }
- base.Dispose(disposing);
- }
-
- #region Windows Form Designer generated code
-
- ///
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- ///
- private void InitializeComponent()
- {
- this.pictureBoxLocomotive = new System.Windows.Forms.PictureBox();
- this.statusStrip = new System.Windows.Forms.StatusStrip();
- this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.buttonRight = new System.Windows.Forms.Button();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
- this.buttonLeft = new System.Windows.Forms.Button();
- this.buttonCreateModif = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).BeginInit();
- this.statusStrip.SuspendLayout();
- this.SuspendLayout();
- //
- // pictureBoxLocomotive
- //
- this.pictureBoxLocomotive.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxLocomotive.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxLocomotive.Name = "pictureBoxLocomotive";
- this.pictureBoxLocomotive.Size = new System.Drawing.Size(837, 461);
- this.pictureBoxLocomotive.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxLocomotive.TabIndex = 0;
- this.pictureBoxLocomotive.TabStop = false;
- //
- // statusStrip
- //
- this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripStatusLabelSpeed,
- this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelBodyColor});
- this.statusStrip.Location = new System.Drawing.Point(0, 461);
- this.statusStrip.Name = "statusStrip";
- this.statusStrip.Size = new System.Drawing.Size(837, 22);
- this.statusStrip.TabIndex = 1;
- //
- // toolStripStatusLabelSpeed
- //
- this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
- this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
- this.toolStripStatusLabelSpeed.Text = "Скорость:";
- //
- // toolStripStatusLabelWeight
- //
- this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
- this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
- this.toolStripStatusLabelWeight.Text = "Вес:";
- //
- // toolStripStatusLabelBodyColor
- //
- this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
- this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
- this.toolStripStatusLabelBodyColor.Text = "Цвет:";
- //
- // buttonCreate
- //
- this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(12, 418);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(75, 23);
- this.buttonCreate.TabIndex = 2;
- this.buttonCreate.Text = "Создать";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
- //
- // buttonRight
- //
- this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowRight;
- this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(795, 411);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
- this.buttonRight.TabIndex = 3;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_click);
- //
- // buttonUp
- //
- this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowUp;
- this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(759, 375);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
- this.buttonUp.TabIndex = 4;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_click);
- //
- // buttonDown
- //
- this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowDown;
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(759, 411);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(30, 30);
- this.buttonDown.TabIndex = 5;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.Click += new System.EventHandler(this.ButtonMove_click);
- //
- // buttonLeft
- //
- this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowLeft;
- this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(723, 411);
- this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(30, 30);
- this.buttonLeft.TabIndex = 6;
- this.buttonLeft.UseVisualStyleBackColor = true;
- this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_click);
- //
- // buttonCreateModif
- //
- this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreateModif.Location = new System.Drawing.Point(105, 418);
- this.buttonCreateModif.Name = "buttonCreateModif";
- this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
- this.buttonCreateModif.TabIndex = 7;
- this.buttonCreateModif.Text = "Модификация";
- this.buttonCreateModif.UseVisualStyleBackColor = true;
- this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
- //
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Карта с большими барьерами",
- "Карта с барьерами-кругами"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
- this.comboBoxSelectorMap.TabIndex = 8;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
- //
- // FormMap
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(837, 483);
- this.Controls.Add(this.comboBoxSelectorMap);
- this.Controls.Add(this.buttonCreateModif);
- this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonDown);
- this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxLocomotive);
- this.Controls.Add(this.statusStrip);
- this.Name = "FormMap";
- this.Text = "Карта";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxLocomotive)).EndInit();
- this.statusStrip.ResumeLayout(false);
- this.statusStrip.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private PictureBox pictureBoxLocomotive;
- private StatusStrip statusStrip;
- private ToolStripStatusLabel toolStripStatusLabelSpeed;
- private ToolStripStatusLabel toolStripStatusLabelWeight;
- private ToolStripStatusLabel toolStripStatusLabelBodyColor;
- private Button buttonCreate;
- private Button buttonRight;
- private Button buttonUp;
- private Button buttonDown;
- private Button buttonLeft;
- private Button buttonCreateModif;
- private ComboBox comboBoxSelectorMap;
- }
-}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMap.cs b/WarmlyLocomotive/WarmlyLocomotive/FormMap.cs
deleted file mode 100644
index 362576d..0000000
--- a/WarmlyLocomotive/WarmlyLocomotive/FormMap.cs
+++ /dev/null
@@ -1,90 +0,0 @@
-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 FormMap : Form
- {
- private AbstractMap _abstractMap;
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
- }
- ///
- /// Заполнение информации по объекту
- ///
- ///
- private void SetData(DrawningLocomotive locomotive)
- {
- toolStripStatusLabelSpeed.Text = $"Скорость: {locomotive.Locomotive.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {locomotive.Locomotive.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет: {locomotive.Locomotive.BodyColor.Name}";
- pictureBoxLocomotive.Image = _abstractMap.CreateMap(pictureBoxLocomotive.Width, pictureBoxLocomotive.Height,
- new DrawningObjectLocomotive(locomotive));
- }
- ///
- /// Обработка нажатия кнопки "Создать"
- ///
- ///
- ///
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var locomotive = new DrawningLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- SetData(locomotive);
- }
- private void ButtonMove_click(object sender, EventArgs e)
- {
- string name = ((Button)sender)?.Name ?? string.Empty;
- Direction dir = Direction.None;
- switch (name)
- {
- case "buttonUp":
- dir = Direction.Up;
- break;
- case "buttonDown":
- dir = Direction.Down;
- break;
- case "buttonLeft":
- dir = Direction.Left;
- break;
- case "buttonRight":
- dir = Direction.Right;
- break;
- }
- pictureBoxLocomotive.Image = _abstractMap?.MoveObject(dir);
- }
- private void ButtonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var locomotive = new DrawningWarmlyLocomotive(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
- SetData(locomotive);
- }
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- _abstractMap = new SimpleMap();
- break;
- case "Карта с большими барьерами":
- _abstractMap = new BigBarriersMap();
- break;
- case "Карта с барьерами-кругами":
- _abstractMap = new CirclesMap();
- break;
- }
- }
- }
-}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.Designer.cs b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.Designer.cs
new file mode 100644
index 0000000..f17a7ae
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.Designer.cs
@@ -0,0 +1,225 @@
+namespace WarmlyLocomotive
+{
+ partial class FormMapWithSetLocomotives
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ this.groupBox = new System.Windows.Forms.GroupBox();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonShowOnMap = new System.Windows.Forms.Button();
+ this.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonRemoveLocomotive = new System.Windows.Forms.Button();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonAddLocomotive = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.buttonDown);
+ this.groupBox.Controls.Add(this.buttonRight);
+ this.groupBox.Controls.Add(this.buttonLeft);
+ this.groupBox.Controls.Add(this.buttonUp);
+ this.groupBox.Controls.Add(this.buttonShowOnMap);
+ this.groupBox.Controls.Add(this.buttonShowStorage);
+ this.groupBox.Controls.Add(this.buttonRemoveLocomotive);
+ this.groupBox.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBox.Controls.Add(this.buttonAddLocomotive);
+ this.groupBox.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBox.Location = new System.Drawing.Point(600, 0);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(200, 450);
+ this.groupBox.TabIndex = 0;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Инструменты";
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(87, 403);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 9;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(123, 403);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 8;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(51, 403);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 7;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::WarmlyLocomotive.Properties.Resources.arrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(87, 367);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 6;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonShowOnMap
+ //
+ this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonShowOnMap.Location = new System.Drawing.Point(19, 312);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(169, 30);
+ this.buttonShowOnMap.TabIndex = 5;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonShowStorage.Location = new System.Drawing.Point(19, 233);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(169, 30);
+ this.buttonShowStorage.TabIndex = 4;
+ this.buttonShowStorage.Text = "Посмотреть хранилище";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonRemoveLocomotive
+ //
+ this.buttonRemoveLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRemoveLocomotive.Location = new System.Drawing.Point(19, 171);
+ this.buttonRemoveLocomotive.Name = "buttonRemoveLocomotive";
+ this.buttonRemoveLocomotive.Size = new System.Drawing.Size(169, 30);
+ this.buttonRemoveLocomotive.TabIndex = 3;
+ this.buttonRemoveLocomotive.Text = "Удалить локомотив";
+ this.buttonRemoveLocomotive.UseVisualStyleBackColor = true;
+ this.buttonRemoveLocomotive.Click += new System.EventHandler(this.ButtonRemoveLocomotive_Click);
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(19, 142);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(169, 23);
+ this.maskedTextBoxPosition.TabIndex = 2;
+ //
+ // buttonAddLocomotive
+ //
+ this.buttonAddLocomotive.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAddLocomotive.Location = new System.Drawing.Point(19, 90);
+ this.buttonAddLocomotive.Name = "buttonAddLocomotive";
+ this.buttonAddLocomotive.Size = new System.Drawing.Size(169, 30);
+ this.buttonAddLocomotive.TabIndex = 1;
+ this.buttonAddLocomotive.Text = "Добавить локомотив";
+ this.buttonAddLocomotive.UseVisualStyleBackColor = true;
+ this.buttonAddLocomotive.Click += new System.EventHandler(this.ButtonAddLocomotive_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Карта с большими барьерами",
+ "Карта с круглыми барьерами"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(19, 33);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(169, 23);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // pictureBox
+ //
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(600, 450);
+ this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetLocomotives
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBox);
+ this.Name = "FormMapWithSetLocomotives";
+ this.Text = "FormMapWithSetLocomotives";
+ this.groupBox.ResumeLayout(false);
+ this.groupBox.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private GroupBox groupBox;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonShowOnMap;
+ private Button buttonShowStorage;
+ private Button buttonRemoveLocomotive;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonAddLocomotive;
+ private ComboBox comboBoxSelectorMap;
+ private PictureBox pictureBox;
+ }
+}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
new file mode 100644
index 0000000..9f1f729
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.cs
@@ -0,0 +1,164 @@
+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 static System.Windows.Forms.DataFormats;
+
+namespace WarmlyLocomotive
+{
+ public partial class FormMapWithSetLocomotives : Form
+ {
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetLocomotivesGeneric _mapLocomotivesCollectionGeneric;
+ public FormMapWithSetLocomotives()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Карта с большими барьерами":
+ map = new BigBarriersMap();
+ break;
+ case "Карта с круглыми барьерами":
+ map = new CirclesMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapLocomotivesCollectionGeneric = new MapWithSetLocomotivesGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapLocomotivesCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddLocomotive_Click(object sender, EventArgs e)
+ {
+ if (_mapLocomotivesCollectionGeneric == null)
+ {
+ return;
+ }
+ FormLocomotive form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawningObjectLocomotive locomotive = new(form.SelectedLocomotive);
+ if (_mapLocomotivesCollectionGeneric + locomotive != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveLocomotive_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_mapLocomotivesCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapLocomotivesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapLocomotivesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapLocomotivesCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapLocomotivesCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapLocomotivesCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/FormMap.resx b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.resx
similarity index 93%
rename from WarmlyLocomotive/WarmlyLocomotive/FormMap.resx
rename to WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.resx
index 2c0949d..f298a7b 100644
--- a/WarmlyLocomotive/WarmlyLocomotive/FormMap.resx
+++ b/WarmlyLocomotive/WarmlyLocomotive/FormMapWithSetLocomotives.resx
@@ -57,7 +57,4 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- 17, 17
-
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/MapWithSetLocomotivesGeneric.cs b/WarmlyLocomotive/WarmlyLocomotive/MapWithSetLocomotivesGeneric.cs
new file mode 100644
index 0000000..297daad
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/MapWithSetLocomotivesGeneric.cs
@@ -0,0 +1,201 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyLocomotive
+{
+ internal class MapWithSetLocomotivesGeneric
+ where T : class, IDrawningObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 120;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetLocomotivesGeneric _setLocomotives;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetLocomotivesGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setLocomotives = new SetLocomotivesGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(MapWithSetLocomotivesGeneric map, T locomotive)
+ {
+ return map._setLocomotives.Insert(locomotive);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetLocomotivesGeneric map, int position)
+ {
+ return map._setLocomotives.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawLocomotives(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setLocomotives.Count; i++)
+ {
+ var locomotive = _setLocomotives.Get(i);
+ if (locomotive != null)
+ {
+ return _map.CreateMap(_pictureWidth, _pictureHeight, locomotive);
+ }
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// Перемещение объекта по крате
+ ///
+ ///
+ ///
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (_map != null)
+ {
+ return _map.MoveObject(direction);
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// "Взбалтываем" набор, чтобы все элементы оказались в начале
+ ///
+ private void Shaking()
+ {
+ int j = _setLocomotives.Count - 1;
+ for (int i = 0; i < _setLocomotives.Count; i++)
+ {
+ if (_setLocomotives.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var locomotive = _setLocomotives.Get(j);
+ if (locomotive != null)
+ {
+ _setLocomotives.Insert(locomotive, i);
+ _setLocomotives.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ Pen penTwo = new(Color.Black, 2);
+ Brush brushLightGray = new SolidBrush(Color.LightGray);
+ Brush brushBrown = new SolidBrush(Color.Brown);
+ g.FillRectangle(brushLightGray, 0, 0, _pictureWidth, _pictureHeight);
+ int placesInRow = _pictureWidth / (_placeSizeWidth + 30);
+ for (int i = 0; i < placesInRow; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {//линия рамзетки места
+ if (j != 0)
+ {
+ int xForRail = i * (_placeSizeWidth + 30);
+ g.DrawLine(penTwo, xForRail, j * _placeSizeHeight, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight);
+ g.DrawLine(penTwo, xForRail, j * _placeSizeHeight - 20, xForRail + _placeSizeWidth - 20, j * _placeSizeHeight - 20);
+ for (int k = 0; k < (_placeSizeWidth - 20) / 15; ++k)
+ {
+ g.FillRectangle(brushBrown, xForRail, j * _placeSizeHeight - 20, 5, 20);
+ xForRail += 15;
+ }
+ }
+ g.DrawLine(pen, i * (_placeSizeWidth + 30), j * _placeSizeHeight + 10, i * (_placeSizeWidth + 30) + _placeSizeWidth / 2, j * _placeSizeHeight + 10);
+ }
+ g.DrawLine(pen, i * (_placeSizeWidth + 30), 10, i * (_placeSizeWidth + 30), (_pictureHeight / _placeSizeHeight) * _placeSizeHeight + 10);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawLocomotives(Graphics g)
+ {
+ int xForLocomotive = 2;
+ int yForLocomotive = 10;
+ int countInRow = 0;
+ for (int i = 0; i < _setLocomotives.Count; i++)
+ {
+ if (countInRow >= _pictureWidth / (_placeSizeWidth + 30))
+ {
+ xForLocomotive = 2;
+ yForLocomotive += _placeSizeHeight;
+ countInRow = 0;
+ }
+ if (_setLocomotives.Get(i) != null)
+ {
+ T locomotive = _setLocomotives.Get(i);
+ locomotive.SetObject(xForLocomotive, yForLocomotive, _pictureWidth, _pictureHeight);
+ locomotive.DrawningObject(g);
+ }
+ xForLocomotive += _placeSizeWidth + 30;
+ countInRow++;
+ }
+ }
+ }
+}
diff --git a/WarmlyLocomotive/WarmlyLocomotive/Program.cs b/WarmlyLocomotive/WarmlyLocomotive/Program.cs
index f6449b7..5334215 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 FormMap());
+ Application.Run(new FormMapWithSetLocomotives());
}
}
}
\ No newline at end of file
diff --git a/WarmlyLocomotive/WarmlyLocomotive/SetLocomotivesGeneric.cs b/WarmlyLocomotive/WarmlyLocomotive/SetLocomotivesGeneric.cs
new file mode 100644
index 0000000..eec3dba
--- /dev/null
+++ b/WarmlyLocomotive/WarmlyLocomotive/SetLocomotivesGeneric.cs
@@ -0,0 +1,134 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace WarmlyLocomotive
+{
+ internal class SetLocomotivesGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetLocomotivesGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый локомотив
+ ///
+ public int Insert(T locomotive)
+ {
+ bool hasEmptySpace = false;
+ int indexOfEmptyPlace = 0;
+ for (int i = 0; i < Count; ++i)
+ {
+ if (_places[i] == null || _places[i] == default(T))
+ {
+ hasEmptySpace = true;
+ indexOfEmptyPlace = i;
+ break;
+ }
+ }
+ if (hasEmptySpace)
+ {
+ for (int i = indexOfEmptyPlace; i > 0; --i)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[0] = locomotive;
+ return 0;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый локомотив
+ /// Позиция
+ ///
+ public int Insert(T locomotive, int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+ if (_places[position] == null || _places[position] == default(T))
+ {
+ _places[position] = locomotive;
+ return position;
+ }
+ else
+ {
+ bool hasEmptySpace = false;
+ int indexOfEmptyPlace = 0;
+ for (int i = position + 1; i < Count; ++i)
+ {
+ if (_places[i] == null || _places[i] == default(T))
+ {
+ hasEmptySpace = true;
+ indexOfEmptyPlace = i;
+ break;
+ }
+ }
+ if (hasEmptySpace)
+ {
+ for (int i = indexOfEmptyPlace; i > position; --i)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[position] = locomotive;
+ return position;
+ }
+ else
+ {
+ return -1;
+ }
+ }
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ T memoryObj = _places[position];
+ _places[position] = null;
+ return memoryObj;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ if (position < 0 || position >= Count)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}