diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
index c5af8d8..99015c2 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ProjectTractor.Entities;
+using ProjectTractor.MovementStrategy;
namespace ProjectTractor.DrawningObjects {
@@ -79,6 +80,12 @@ namespace ProjectTractor.DrawningObjects {
EntityTractor = new EntityTractor(speed, weight, bodyColor);
}
+ ///
+ /// Получение объекта IMoveableObject из объекта DrawningTractor
+ ///
+ public IMoveableObject GetMoveableObject => new
+ DrawningObjectTractor(this);
+
///
/// Координата X объекта
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs
index 4dcb86d..4c4dd75 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs
@@ -20,30 +20,28 @@ namespace ProjectTractor
private ComboBox comboBoxStrategy;
private Button buttonRight;
- ///
- ///
- ///
- private AbstractStrategy? _abstractStrategy;
-
- public int getPictureWidth()
- {
- return pictureBoxTractor.Width;
- }
- public int getPictureHeight()
- {
- return pictureBoxTractor.Height;
- }
-
///
/// -
///
private DrawningTractor? _drawningTractor;
+ private Button ButtonSelectTractor;
+
+ ///
+ ///
+ ///
+ private AbstractStrategy? _strategy;
+ ///
+ ///
+ ///
+ public DrawningTractor? SelectedTractor { get; private set; }
///
///
///
public FormTractor()
{
InitializeComponent();
+ _strategy = null;
+ SelectedTractor = null;
}
///
///
@@ -60,24 +58,6 @@ namespace ProjectTractor
_drawningTractor.DrawTransport(gr);
pictureBoxTractor.Image = bmp;
}
- ///
- /// ""
- ///
- ///
- ///
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random random = new();
- _drawningTractor = new DrawningTractor(random.Next(100, 300),
- random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
- pictureBoxTractor.Width, pictureBoxTractor.Height);
- _drawningTractor.SetPosition(random.Next(10, 100),
- random.Next(10, 100));
- Draw();
- }
-
///
///
///
@@ -92,7 +72,7 @@ namespace ProjectTractor
string name = ((Button)sender)?.Name ?? string.Empty;
switch (name)
{
- case "buttonTop":
+ case "buttonUp":
_drawningTractor.MoveTransport(DirectionType.Up);
break;
case "buttonDown":
@@ -107,6 +87,76 @@ namespace ProjectTractor
}
Draw();
}
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonCreate_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;
+ }
+ _drawningTractor = new DrawningTractor(random.Next(100, 300),
+ random.Next(1000, 3000), color,
+ pictureBoxTractor.Width, pictureBoxTractor.Height);
+ _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
+ 100));
+ Draw();
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonStartegyStep_Click(object sender, EventArgs e)
+ {
+ if (_drawningTractor == null)
+ {
+ return;
+ }
+ if (comboBoxStrategy.Enabled)
+ {
+ _strategy = comboBoxStrategy.SelectedIndex switch
+ {
+ 0 => new MoveToCenter(),
+ 1 => new MoveToBorder(),
+ _ => null,
+ };
+ if (_strategy == null)
+ {
+ return;
+ }
+ _strategy.SetData(_drawningTractor.GetMoveableObject,
+ pictureBoxTractor.Width, pictureBoxTractor.Height);
+ }
+ if (_strategy == null)
+ {
+ return;
+ }
+ comboBoxStrategy.Enabled = false;
+ _strategy.MakeStep();
+ Draw();
+ if (_strategy.GetStatus() == Status.Finish)
+ {
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ }
+ }
+ ///
+ ///
+ ///
+ ///
+ ///
+ private void ButtonSelectTractor_Click(object sender, EventArgs e)
+ {
+ SelectedTractor = _drawningTractor;
+ DialogResult = DialogResult.OK;
+ }
private void InitializeComponent()
{
@@ -119,6 +169,7 @@ namespace ProjectTractor
this.buttonCreateBulldoserTractor = new System.Windows.Forms.Button();
this.buttonStep = new System.Windows.Forms.Button();
this.comboBoxStrategy = new System.Windows.Forms.ComboBox();
+ this.ButtonSelectTractor = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).BeginInit();
this.SuspendLayout();
//
@@ -226,9 +277,21 @@ namespace ProjectTractor
this.comboBoxStrategy.Size = new System.Drawing.Size(151, 28);
this.comboBoxStrategy.TabIndex = 8;
//
+ // ButtonSelectTractor
+ //
+ this.ButtonSelectTractor.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.ButtonSelectTractor.Location = new System.Drawing.Point(469, 403);
+ this.ButtonSelectTractor.Name = "ButtonSelectTractor";
+ this.ButtonSelectTractor.Size = new System.Drawing.Size(199, 29);
+ this.ButtonSelectTractor.TabIndex = 9;
+ this.ButtonSelectTractor.Text = " ";
+ this.ButtonSelectTractor.UseVisualStyleBackColor = true;
+ this.ButtonSelectTractor.Click += new System.EventHandler(this.ButtonSelectTractor_Click);
+ //
// FormTractor
//
this.ClientSize = new System.Drawing.Size(882, 453);
+ this.Controls.Add(this.ButtonSelectTractor);
this.Controls.Add(this.comboBoxStrategy);
this.Controls.Add(this.buttonStep);
this.Controls.Add(this.buttonCreateBulldoserTractor);
@@ -248,19 +311,30 @@ namespace ProjectTractor
private void buttonCreateBulldoserTractor_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 dialogColor = new();
+ if (dialogColor.ShowDialog() == DialogResult.OK)
+ {
+ color = dialogColor.Color;
+ }
+ Color dopColor = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialogDopColor = new();
+ if (dialogDopColor.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialogDopColor.Color;
+ }
_drawningTractor = new DrawningBulldoser(random.Next(100, 300),
random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256),
- random.Next(0, 256)),
+ color,
+ dopColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(0, 2)),
- pictureBoxTractor.Width, pictureBoxTractor.Height);
- _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10,
- 100));
+ pictureBoxTractor.Width,
+ pictureBoxTractor.Height);
+ _drawningTractor.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
-
}
private void buttonStep_Click(object sender, EventArgs e)
@@ -271,32 +345,32 @@ namespace ProjectTractor
}
if (comboBoxStrategy.Enabled)
{
- _abstractStrategy = comboBoxStrategy.SelectedIndex
+ _strategy = comboBoxStrategy.SelectedIndex
switch
{
0 => new MoveToCenter(),
1 => new MoveToBorder(),
_ => null,
};
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.SetData(new
+ _strategy.SetData(new
DrawningObjectTractor(_drawningTractor), pictureBoxTractor.Width,
pictureBoxTractor.Height);
comboBoxStrategy.Enabled = false;
}
- if (_abstractStrategy == null)
+ if (_strategy == null)
{
return;
}
- _abstractStrategy.MakeStep();
+ _strategy.MakeStep();
Draw();
- if (_abstractStrategy.GetStatus() == Status.Finish)
+ if (_strategy.GetStatus() == Status.Finish)
{
comboBoxStrategy.Enabled = true;
- _abstractStrategy = null;
+ _strategy = null;
}
}
}
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
new file mode 100644
index 0000000..4c32193
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
@@ -0,0 +1,181 @@
+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 ProjectTractor.DrawningObjects;
+using ProjectTractor.Generics;
+using ProjectTractor.MovementStrategy;
+
+namespace ProjectTractor
+{
+ public partial class FormTractorCollection : Form
+ {
+
+ ///
+ /// Набор объектов
+ ///
+ private readonly TractorsGenericCollection _tractors;
+ ///
+ /// Конструктор
+ ///
+ public FormTractorCollection()
+ {
+ InitializeComponent();
+ _tractors = new TractorsGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+
+ private void ButtonAddTractor_Click(object sender, EventArgs e)
+ {
+ FormTractor form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_tractors + form.SelectedTractor != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _tractors.ShowTractors();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
+ private void ButtonRemoveTractor_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxNumber.Text);
+ if (_tractors - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _tractors.ShowTractors();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
+ private void ButtonRefreshCollection_Click(object sender, EventArgs
+ e)
+ {
+ pictureBoxCollection.Image = _tractors.ShowTractors();
+ }
+
+ private void InitializeComponent()
+ {
+ this.pictureBoxCollection = new System.Windows.Forms.PictureBox();
+ this.groupBox = new System.Windows.Forms.GroupBox();
+ this.ButtonRefreshCollection = new System.Windows.Forms.Button();
+ this.ButtonRemoveTractor = new System.Windows.Forms.Button();
+ this.ButtonAddTractor = new System.Windows.Forms.Button();
+ this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).BeginInit();
+ this.groupBox.SuspendLayout();
+ this.SuspendLayout();
+ //
+ // pictureBoxCollection
+ //
+ this.pictureBoxCollection.Dock = System.Windows.Forms.DockStyle.Left;
+ this.pictureBoxCollection.Location = new System.Drawing.Point(0, 0);
+ this.pictureBoxCollection.Name = "pictureBoxCollection";
+ this.pictureBoxCollection.Size = new System.Drawing.Size(620, 437);
+ this.pictureBoxCollection.TabIndex = 1;
+ this.pictureBoxCollection.TabStop = false;
+ //
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.ButtonRefreshCollection);
+ this.groupBox.Controls.Add(this.ButtonRemoveTractor);
+ this.groupBox.Controls.Add(this.ButtonAddTractor);
+ this.groupBox.Controls.Add(this.maskedTextBoxNumber);
+ this.groupBox.Location = new System.Drawing.Point(626, 12);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(255, 413);
+ this.groupBox.TabIndex = 2;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Инструменты";
+ //
+ // ButtonRefreshCollection
+ //
+ this.ButtonRefreshCollection.Location = new System.Drawing.Point(20, 331);
+ this.ButtonRefreshCollection.Name = "ButtonRefreshCollection";
+ this.ButtonRefreshCollection.Size = new System.Drawing.Size(211, 35);
+ this.ButtonRefreshCollection.TabIndex = 8;
+ this.ButtonRefreshCollection.Text = "Обновить коллекцию";
+ this.ButtonRefreshCollection.UseVisualStyleBackColor = true;
+ this.ButtonRefreshCollection.Click += new System.EventHandler(this.ButtonRefreshCollection_Click);
+ //
+ // ButtonRemoveTractor
+ //
+ this.ButtonRemoveTractor.Location = new System.Drawing.Point(28, 156);
+ this.ButtonRemoveTractor.Name = "ButtonRemoveTractor";
+ this.ButtonRemoveTractor.Size = new System.Drawing.Size(203, 33);
+ this.ButtonRemoveTractor.TabIndex = 7;
+ this.ButtonRemoveTractor.Text = "Удалить трактор";
+ this.ButtonRemoveTractor.UseVisualStyleBackColor = true;
+ this.ButtonRemoveTractor.Click += new System.EventHandler(this.ButtonRemoveTractor_Click);
+ //
+ // ButtonAddTractor
+ //
+ this.ButtonAddTractor.Location = new System.Drawing.Point(28, 46);
+ this.ButtonAddTractor.Name = "ButtonAddTractor";
+ this.ButtonAddTractor.Size = new System.Drawing.Size(203, 34);
+ this.ButtonAddTractor.TabIndex = 6;
+ this.ButtonAddTractor.Text = "Добавить трактор";
+ this.ButtonAddTractor.UseVisualStyleBackColor = true;
+ this.ButtonAddTractor.Click += new System.EventHandler(this.ButtonAddTractor_Click);
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(28, 113);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(203, 27);
+ this.maskedTextBoxNumber.TabIndex = 5;
+ //
+ // FormTractorCollection
+ //
+ this.ClientSize = new System.Drawing.Size(893, 437);
+ this.Controls.Add(this.groupBox);
+ this.Controls.Add(this.pictureBoxCollection);
+ this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
+ this.MinimizeBox = false;
+ this.Name = "FormTractorCollection";
+ this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
+ this.Text = "Набор тракторов";
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBoxCollection)).EndInit();
+ this.groupBox.ResumeLayout(false);
+ this.groupBox.PerformLayout();
+ this.ResumeLayout(false);
+
+ }
+
+ private GroupBox groupBox;
+ private Button ButtonRefreshCollection;
+ private Button ButtonRemoveTractor;
+ private Button ButtonAddTractor;
+ private MaskedTextBox maskedTextBoxNumber;
+ private PictureBox pictureBoxCollection;
+
+ }
+}
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
index 61dbba1..56558ed 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/Program.cs
@@ -11,7 +11,7 @@ namespace ProjectTractor
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormTractor());
+ Application.Run(new FormTractorCollection());
}
}
}
\ No newline at end of file
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
new file mode 100644
index 0000000..c0d112a
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
@@ -0,0 +1,92 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace ProjectTractor.Generics
+{
+ internal class SetGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T?[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetGeneric(int count)
+ {
+ _places = new T?[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый трактор
+ ///
+ public int Insert(T tractor)
+ {
+ if (_places[Count - 1] != null)
+ return -1;
+
+ return Insert(tractor, 0);
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый трактор
+ /// Позиция
+ ///
+ public int Insert(T tractor, int position)
+ {
+
+ if (!(position >= 0 && position < Count))
+ return -1;
+ if (_places[position] != null)
+ {
+ int ind = position;
+ while (ind < Count && _places[ind] != null)
+ ind++;
+ if (ind == Count)
+ return -1;
+ for (int i = ind - 1; i >= position; i--)
+ _places[i + 1] = _places[i];
+ }
+ _places[position] = tractor;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ if (!(position >= 0 && position < Count))
+ {
+ return false;
+ }
+ _places[position] = null;
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ if (!(position >= 0 && position < Count))
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs
new file mode 100644
index 0000000..8a333eb
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs
@@ -0,0 +1,142 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using ProjectTractor.DrawningObjects;
+using ProjectTractor.MovementStrategy;
+
+namespace ProjectTractor.Generics
+{
+ ///
+ /// Параметризованный класс для набора объектов DrawningTractor
+ ///
+ ///
+ ///
+ internal class TractorsGenericCollection
+ where T : DrawningTractor
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 200;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 90;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public TractorsGenericCollection(int picWidth, int picHeight)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = new SetGeneric(width * height);
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(TractorsGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ return -1;
+
+ return collect._collection.Insert(obj);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static bool operator -(TractorsGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ }
+ return true;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowTractors()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawObjects(gr);
+ return bmp;
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight +
+ 1; ++j)
+ {//линия рамзетки места
+ g.DrawLine(pen, i * _placeSizeWidth, j *
+ _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth / 2, j *
+ _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i *
+ _placeSizeWidth, _pictureHeight / _placeSizeHeight * _placeSizeHeight);
+ }
+ }
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ for (int i = 0; i < _collection.Count; i++)
+ {
+
+ DrawningTractor? tractor = _collection.Get(i);
+ if (tractor != null)
+ {
+ int countRows = _pictureWidth / _placeSizeWidth;
+ tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % countRows * _placeSizeWidth), _pictureHeight - i / countRows * _placeSizeHeight - 150);
+ tractor.DrawTransport(g);
+ }
+ }
+ }
+ }
+}
+