diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/DrawningTractor.cs
index c5af8d8..578ec20 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 из объекта DrawningCar
+ ///
+ 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..7bd9091 100644
--- a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractor.cs
@@ -20,30 +20,26 @@ 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 AbstractStrategy? _strategy;
+ ///
+ ///
+ ///
+ public DrawningTractor? SelectedTractor { get; private set; }
+ ///
///
///
public FormTractor()
{
InitializeComponent();
+ _strategy = null;
+ SelectedTractor = null;
}
///
///
@@ -65,19 +61,26 @@ namespace ProjectTractor
///
///
///
- private void ButtonCreate_Click(object sender, EventArgs e)
+ private void ButtonCreateBulldoserTractor_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));
+ Color color = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ Color dopColor = Color.FromArgb(random.Next(0, 256),
+ random.Next(0, 256), random.Next(0, 256));
+ //TODO
+ _drawningTractor = new DrawningBulldoser(random.Next(100, 300),
+ random.Next(1000, 3000),
+ 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));
Draw();
}
-
///
///
///
@@ -92,7 +95,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 +110,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 ButtonSelectCar_Click(object sender, EventArgs e)
+ {
+ SelectedTractor = _drawningTractor;
+ DialogResult = DialogResult.OK;
+ }
private void InitializeComponent()
{
@@ -239,6 +312,7 @@ namespace ProjectTractor
this.Controls.Add(this.buttonCreateTractor);
this.Controls.Add(this.pictureBoxTractor);
this.Name = "FormTractor";
+ this.Load += new System.EventHandler(this.FormTractor_Load);
((System.ComponentModel.ISupportInitialize)(this.pictureBoxTractor)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
@@ -271,33 +345,38 @@ 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;
}
}
+
+ private void FormTractor_Load(object sender, EventArgs e)
+ {
+
+ }
}
}
\ No newline at end of file
diff --git a/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs
new file mode 100644
index 0000000..baa946f
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.Designer.cs
@@ -0,0 +1,146 @@
+namespace ProjectTractor
+{
+ partial class FormTractorCollection
+ {
+ ///
+ /// 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.splitContainer1 = new System.Windows.Forms.SplitContainer();
+ this.pictureBox1 = new System.Windows.Forms.PictureBox();
+ this.labelPanelInstuments = new System.Windows.Forms.Label();
+ this.maskedTextBoxNumber = new System.Windows.Forms.MaskedTextBox();
+ this.button1 = new System.Windows.Forms.Button();
+ this.button2 = new System.Windows.Forms.Button();
+ this.button3 = new System.Windows.Forms.Button();
+ ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
+ this.splitContainer1.Panel1.SuspendLayout();
+ this.splitContainer1.Panel2.SuspendLayout();
+ this.splitContainer1.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
+ this.SuspendLayout();
+ //
+ // splitContainer1
+ //
+ this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.splitContainer1.Location = new System.Drawing.Point(0, 0);
+ this.splitContainer1.Name = "splitContainer1";
+ //
+ // splitContainer1.Panel1
+ //
+ this.splitContainer1.Panel1.Controls.Add(this.pictureBox1);
+ //
+ // splitContainer1.Panel2
+ //
+ this.splitContainer1.Panel2.Controls.Add(this.button3);
+ this.splitContainer1.Panel2.Controls.Add(this.button2);
+ this.splitContainer1.Panel2.Controls.Add(this.button1);
+ this.splitContainer1.Panel2.Controls.Add(this.maskedTextBoxNumber);
+ this.splitContainer1.Panel2.Controls.Add(this.labelPanelInstuments);
+ this.splitContainer1.Size = new System.Drawing.Size(800, 450);
+ this.splitContainer1.SplitterDistance = 591;
+ this.splitContainer1.TabIndex = 0;
+ //
+ // pictureBox1
+ //
+ this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox1.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox1.Name = "pictureBox1";
+ this.pictureBox1.Size = new System.Drawing.Size(591, 450);
+ this.pictureBox1.TabIndex = 0;
+ this.pictureBox1.TabStop = false;
+ //
+ // labelPanelInstuments
+ //
+ this.labelPanelInstuments.AutoSize = true;
+ this.labelPanelInstuments.Location = new System.Drawing.Point(8, 9);
+ this.labelPanelInstuments.Name = "labelPanelInstuments";
+ this.labelPanelInstuments.Size = new System.Drawing.Size(103, 20);
+ this.labelPanelInstuments.TabIndex = 0;
+ this.labelPanelInstuments.Text = "Инструменты";
+ //
+ // maskedTextBoxNumber
+ //
+ this.maskedTextBoxNumber.Location = new System.Drawing.Point(8, 146);
+ this.maskedTextBoxNumber.Name = "maskedTextBoxNumber";
+ this.maskedTextBoxNumber.Size = new System.Drawing.Size(185, 27);
+ this.maskedTextBoxNumber.TabIndex = 1;
+ //
+ // button1
+ //
+ this.button1.Location = new System.Drawing.Point(8, 54);
+ this.button1.Name = "button1";
+ this.button1.Size = new System.Drawing.Size(185, 40);
+ this.button1.TabIndex = 2;
+ this.button1.Text = "Добавить трактор";
+ this.button1.UseVisualStyleBackColor = true;
+ //
+ // button2
+ //
+ this.button2.Location = new System.Drawing.Point(8, 179);
+ this.button2.Name = "button2";
+ this.button2.Size = new System.Drawing.Size(185, 36);
+ this.button2.TabIndex = 3;
+ this.button2.Text = "Удалить трактор";
+ this.button2.UseVisualStyleBackColor = true;
+ //
+ // button3
+ //
+ this.button3.Location = new System.Drawing.Point(8, 376);
+ this.button3.Name = "button3";
+ this.button3.Size = new System.Drawing.Size(185, 42);
+ this.button3.TabIndex = 4;
+ this.button3.Text = "Обновить коллекцию";
+ this.button3.UseVisualStyleBackColor = true;
+ //
+ // FormTractorCollection
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.splitContainer1);
+ this.Name = "FormTractorCollection";
+ this.Text = "FormTractorCollection";
+ this.splitContainer1.Panel1.ResumeLayout(false);
+ this.splitContainer1.Panel2.ResumeLayout(false);
+ this.splitContainer1.Panel2.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
+ this.splitContainer1.ResumeLayout(false);
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private SplitContainer splitContainer1;
+ private PictureBox pictureBox1;
+ private Button button3;
+ private Button button2;
+ private Button button1;
+ private MaskedTextBox maskedTextBoxNumber;
+ private Label labelPanelInstuments;
+ }
+}
\ No newline at end of file
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..6ed2112
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/FormTractorCollection.cs
@@ -0,0 +1,20 @@
+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 ProjectTractor
+{
+ public partial class FormTractorCollection : Form
+ {
+ public FormTractorCollection()
+ {
+ InitializeComponent();
+ }
+ }
+}
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/SetGeneric.cs b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
new file mode 100644
index 0000000..ee4787f
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/SetGeneric.cs
@@ -0,0 +1,101 @@
+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 bool Insert(T tractor)
+ {
+ if (_places[0] == null)
+ {
+ _places[0] = tractor;
+ }
+ else
+ {
+ Insert(tractor, 0);
+ }
+ // TODO вставка в начало набора
+ return true;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый автомобиль
+ /// Позиция
+ ///
+ public bool Insert(T tractor, int position)
+ {
+
+ if (!(position >= 0 && position < Count))
+ return false;
+ if (_places[position] != null)
+ {
+ int ind = position;
+ while (ind < Count && _places[ind] != null)
+ ind++;
+ if (ind == Count)
+ return false;
+ for (int i = ind - 1; i >= position; i--)
+ _places[i + 1] = _places[i];
+ }
+ _places[position] = tractor;
+ return true;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ if (!(position >= 0 && position < Count))
+ {
+ return false;
+ }
+ _places[position] = null;
+ return true;
+ // TODO проверка позиции
+ // TODO удаление объекта из массива, присвоив элементу массива значение null
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ if (!(position >= 0 && position < Count))
+ {
+ return null;
+ }
+ // TODO проверка позиции
+ 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..46f2036
--- /dev/null
+++ b/RPP_FirstLaba_Tractor/RPP_FirstLaba_Tractor/TractorsGenericCollection.cs
@@ -0,0 +1,146 @@
+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
+{
+ ///
+ /// Параметризованный класс для набора объектов DrawningCar
+ ///
+ ///
+ ///
+ internal class TractorsGenericCollection
+ where T : DrawningTractor
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ 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 bool operator +(TractorsGenericCollection collect, T?
+ obj)
+ {
+ if (obj == null)
+ {
+ return false;
+ }
+ return collect?._collection.Insert(obj) ?? false;
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T? operator -(TractorsGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ }
+ return obj;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowCars()
+ {
+ 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 inRow = _pictureWidth / _placeSizeWidth;
+ tractor.SetPosition(_pictureWidth - _placeSizeWidth - (i % inRow * _placeSizeWidth) - _placeSizeHeight / 2 - 8, i / inRow * _placeSizeHeight + 20);
+ tractor.DrawTransport(g);
+ }
+ // TODO получение объекта
+ // TODO установка позиции
+ // TODO прорисовка объекта
+ }
+ }
+ }
+}
+