diff --git a/Liner/Drawing/DrawingBigLiner.cs b/Liner/Drawing/DrawingBigLiner.cs
index 2eb6608..bef1bed 100644
--- a/Liner/Drawing/DrawingBigLiner.cs
+++ b/Liner/Drawing/DrawingBigLiner.cs
@@ -75,7 +75,6 @@ namespace Liner.Drawing
g.FillPolygon(bottomBrush, bottom);
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
if (liner.SwimmingPool) { g.FillPolygon(poolBrush, pool); }//рисуем бассейн
- g.Dispose();
}
}
}
diff --git a/Liner/Drawing/DrawingLiner.cs b/Liner/Drawing/DrawingLiner.cs
index 04a9047..eddd0a6 100644
--- a/Liner/Drawing/DrawingLiner.cs
+++ b/Liner/Drawing/DrawingLiner.cs
@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Liner.Entities;
+using Liner.MovingStrategies;
namespace Liner.Drawing
{
@@ -54,6 +55,10 @@ namespace Liner.Drawing
///
public int GetHeight => _linerHeight;
///
+ /// Получение объекта IMoveableObject из объекта DrawingLiner
+ ///
+ public IMoveableObject GetMoveableObject => new DrawingObjectLiner(this);
+ ///
/// Конструктор
///
/// Скорость
@@ -125,7 +130,6 @@ namespace Liner.Drawing
}
g.FillPolygon(bottomBrush, bottom);
g.DrawPolygon(pen, bottom);//рисуем нижний корпус
- g.Dispose();
}
///
/// Проверка, что объект может переместится по указанному направлению
diff --git a/Liner/FormLinerCollection.Designer.cs b/Liner/FormLinerCollection.Designer.cs
new file mode 100644
index 0000000..06a7a37
--- /dev/null
+++ b/Liner/FormLinerCollection.Designer.cs
@@ -0,0 +1,123 @@
+namespace Liner
+{
+ partial class FormLinerCollection
+ {
+ ///
+ /// Required designer variable.
+ ///
+ private System.ComponentModel.IContainer components = null;
+
+ ///
+ /// Clean up any resources being used.
+ ///
+ /// true if managed resources should be disposed; otherwise, false.
+ protected override void Dispose(bool disposing)
+ {
+ if (disposing && (components != null))
+ {
+ components.Dispose();
+ }
+ base.Dispose(disposing);
+ }
+
+ #region Windows Form Designer generated code
+
+ ///
+ /// Required method for Designer support - do not modify
+ /// the contents of this method with the code editor.
+ ///
+ private void InitializeComponent()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefreshCollection = new Button();
+ buttonDeleteLiner = new Button();
+ textBoxNumber = new TextBox();
+ buttonAddLiner = new Button();
+ pictureBoxCollection = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefreshCollection);
+ groupBoxTools.Controls.Add(buttonDeleteLiner);
+ groupBoxTools.Controls.Add(textBoxNumber);
+ groupBoxTools.Controls.Add(buttonAddLiner);
+ groupBoxTools.Location = new Point(739, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(211, 565);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Tools";
+ //
+ // buttonRefreshCollection
+ //
+ buttonRefreshCollection.Location = new Point(11, 258);
+ buttonRefreshCollection.Name = "buttonRefreshCollection";
+ buttonRefreshCollection.Size = new Size(194, 40);
+ buttonRefreshCollection.TabIndex = 3;
+ buttonRefreshCollection.Text = "Refresh Collection";
+ buttonRefreshCollection.UseVisualStyleBackColor = true;
+ buttonRefreshCollection.Click += buttonRefreshCollection_Click;
+ //
+ // buttonDeleteLiner
+ //
+ buttonDeleteLiner.Location = new Point(11, 117);
+ buttonDeleteLiner.Name = "buttonDeleteLiner";
+ buttonDeleteLiner.Size = new Size(194, 40);
+ buttonDeleteLiner.TabIndex = 2;
+ buttonDeleteLiner.Text = "Delete Liner";
+ buttonDeleteLiner.UseVisualStyleBackColor = true;
+ buttonDeleteLiner.Click += buttonRemoveLiner_Click;
+ //
+ // textBoxNumber
+ //
+ textBoxNumber.Location = new Point(41, 77);
+ textBoxNumber.Name = "textBoxNumber";
+ textBoxNumber.Size = new Size(139, 23);
+ textBoxNumber.TabIndex = 1;
+ //
+ // buttonAddLiner
+ //
+ buttonAddLiner.Location = new Point(11, 22);
+ buttonAddLiner.Name = "buttonAddLiner";
+ buttonAddLiner.Size = new Size(194, 40);
+ buttonAddLiner.TabIndex = 0;
+ buttonAddLiner.Text = "Add Liner";
+ buttonAddLiner.UseVisualStyleBackColor = true;
+ buttonAddLiner.Click += buttonAddLiner_Click;
+ //
+ // pictureBoxCollection
+ //
+ pictureBoxCollection.Location = new Point(2, 0);
+ pictureBoxCollection.Name = "pictureBoxCollection";
+ pictureBoxCollection.Size = new Size(731, 565);
+ pictureBoxCollection.TabIndex = 1;
+ pictureBoxCollection.TabStop = false;
+ //
+ // FormLinerCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(951, 568);
+ Controls.Add(pictureBoxCollection);
+ Controls.Add(groupBoxTools);
+ Name = "FormLinerCollection";
+ Text = "Liner Collection";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private TextBox textBoxNumber;
+ private Button buttonAddLiner;
+ private Button buttonRefreshCollection;
+ private Button buttonDeleteLiner;
+ private PictureBox pictureBoxCollection;
+ }
+}
\ No newline at end of file
diff --git a/Liner/FormLinerCollection.cs b/Liner/FormLinerCollection.cs
new file mode 100644
index 0000000..3972175
--- /dev/null
+++ b/Liner/FormLinerCollection.cs
@@ -0,0 +1,88 @@
+using Liner.Drawing;
+using Liner.Generics;
+using Liner.MovingStrategies;
+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 Liner
+{
+ ///
+ /// Форма для работы с набором объектов класса DrawingLiner
+ ///
+ public partial class FormLinerCollection : Form
+ {
+ ///
+ /// Набор объектов
+ ///
+ private readonly LinerGenericCollection _liners;
+ ///
+ /// Конструктор
+ ///
+ public FormLinerCollection()
+ {
+ InitializeComponent();
+ _liners = new LinerGenericCollection(pictureBoxCollection.Width, pictureBoxCollection.Height);
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ ///
+ ///
+ private void buttonAddLiner_Click(object sender, EventArgs e)
+ {
+ MainScreen form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ if (_liners + form.SelectedLiner != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBoxCollection.Image = _liners.ShowLiners();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта из набора
+ ///
+ ///
+ ///
+ private void buttonRemoveLiner_Click(object sender, EventArgs e)
+ {
+ if (MessageBox.Show("Удалить объект?", "Удаление",
+ MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(textBoxNumber.Text);
+ if (_liners - pos)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBoxCollection.Image = _liners.ShowLiners();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Обновление рисунка по набору
+ ///
+ ///
+ ///
+ private void buttonRefreshCollection_Click(object sender, EventArgs e)
+ {
+ pictureBoxCollection.Image = _liners.ShowLiners();
+ }
+ }
+}
diff --git a/Liner/FormLinerCollection.resx b/Liner/FormLinerCollection.resx
new file mode 100644
index 0000000..a395bff
--- /dev/null
+++ b/Liner/FormLinerCollection.resx
@@ -0,0 +1,120 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ text/microsoft-resx
+
+
+ 2.0
+
+
+ System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
+ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+
\ No newline at end of file
diff --git a/Liner/Generics/LinerGenericCollection.cs b/Liner/Generics/LinerGenericCollection.cs
new file mode 100644
index 0000000..df20691
--- /dev/null
+++ b/Liner/Generics/LinerGenericCollection.cs
@@ -0,0 +1,156 @@
+using Liner.MovingStrategies;
+using Liner.Drawing;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Liner.Generics
+{
+ ///
+ /// Параметризованный класс для набора объектов DrawningCar
+ ///
+ ///
+ ///
+ public class LinerGenericCollection
+ where T : DrawingLiner
+ where U : IMoveableObject
+ {
+ ///
+ /// Ширина окна прорисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна прорисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 100;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 80;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetGeneric _collection;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public LinerGenericCollection(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 +(LinerGenericCollection collect, T? obj)
+ {
+ if (obj == null)
+ {
+ return -1;
+ }
+ return collect?._collection.Insert(obj);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static bool operator -(LinerGenericCollection collect, int pos)
+ {
+ T? obj = collect._collection.Get(pos);
+ if (obj != null)
+ {
+ collect._collection.Remove(pos);
+ return true;
+ }
+ return false;
+ }
+ ///
+ /// Получение объекта IMoveableObject
+ ///
+ ///
+ ///
+ public U? GetU(int pos)
+ {
+ return (U?)_collection.Get(pos)?.GetMoveableObject;
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowLiners()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawObjects(gr);
+ DrawBackground(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; j++)
+ {
+ g.DrawRectangle(pen, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth, _placeSizeHeight);
+ }
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawObjects(Graphics g)
+ {
+ /*int iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
+ int iY = 0;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ _collection.Get(i)?.SetPosition(iX,iY);
+ _collection.Get(i)?.DrawTransport(g);
+ if(_collection.Get(i) != null)
+ {
+ iY += _placeSizeHeight;
+ if(iY + _placeSizeHeight >= _pictureHeight)
+ {
+ iY = 0;
+ iX -= _placeSizeWidth;
+ }
+ }
+ }*/
+ int iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
+ int iY = 0;
+ for (int i = 0; i < _collection.Count; i++)
+ {
+ _collection.Get(i)?.SetPosition(iX,iY);
+ _collection.Get(i)?.DrawTransport(g);
+ iX -= _placeSizeWidth;
+ if(iX < 0)
+ {
+ iX = ((_pictureWidth / _placeSizeWidth) - 1) * _placeSizeWidth;
+ iY += _placeSizeHeight;
+ }
+ }
+ }
+ }
+}
diff --git a/Liner/Generics/SetGeneric.cs b/Liner/Generics/SetGeneric.cs
new file mode 100644
index 0000000..93c1bfe
--- /dev/null
+++ b/Liner/Generics/SetGeneric.cs
@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace Liner.Generics
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ public 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 liner)
+ {
+ int nulli = 0;
+ while (_places[nulli] != null)
+ {
+ nulli++;
+ if(nulli == _places.Length)
+ {
+ return -1; // нет пустого места
+ }
+ }
+ //сдвиг
+ for(int i = nulli; i > 0; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ _places[0] = liner;
+ return 0;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый лайнер
+ /// Позиция
+ ///
+ public int Insert(T liner, int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return -1;
+ }
+ if (_places[position] != null)
+ {
+ int nulli = position;
+ while (_places[nulli] != null)
+ {
+ nulli++;
+ if (nulli == _places.Length)
+ {
+ return -1; // нет пустого места
+ }
+ }
+ }
+ _places[position] = liner;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public bool Remove(int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return false;
+ }
+ _places[position] = null;
+ return true;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T? Get(int position)
+ {
+ if (position < 0 || position > _places.Length)
+ {
+ return null;
+ }
+ return _places[position];
+ }
+ }
+}
diff --git a/Liner/MainScreen.Designer.cs b/Liner/MainScreen.Designer.cs
index 29844b1..38965e7 100644
--- a/Liner/MainScreen.Designer.cs
+++ b/Liner/MainScreen.Designer.cs
@@ -37,6 +37,7 @@
buttonCreateBigLiner = new Button();
comboBoxStrategy = new ComboBox();
buttonStep = new Button();
+ buttonSelectLiner = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxLiner).BeginInit();
SuspendLayout();
//
@@ -140,11 +141,22 @@
buttonStep.UseVisualStyleBackColor = true;
buttonStep.Click += buttonStep_Click;
//
+ // buttonSelectLiner
+ //
+ buttonSelectLiner.Location = new Point(856, 93);
+ buttonSelectLiner.Name = "buttonSelectLiner";
+ buttonSelectLiner.Size = new Size(75, 23);
+ buttonSelectLiner.TabIndex = 9;
+ buttonSelectLiner.Text = "Select Liner";
+ buttonSelectLiner.UseVisualStyleBackColor = true;
+ buttonSelectLiner.Click += buttonSelectLiner_Click;
+ //
// MainScreen
//
AutoScaleDimensions = new SizeF(7F, 15F);
AutoScaleMode = AutoScaleMode.Font;
ClientSize = new Size(984, 661);
+ Controls.Add(buttonSelectLiner);
Controls.Add(buttonStep);
Controls.Add(comboBoxStrategy);
Controls.Add(buttonCreateBigLiner);
@@ -172,5 +184,6 @@
private Button buttonCreateBigLiner;
private ComboBox comboBoxStrategy;
private Button buttonStep;
+ private Button buttonSelectLiner;
}
}
\ No newline at end of file
diff --git a/Liner/MainScreen.cs b/Liner/MainScreen.cs
index 46f67e3..4e176e4 100644
--- a/Liner/MainScreen.cs
+++ b/Liner/MainScreen.cs
@@ -1,6 +1,8 @@
using Liner.Drawing;
using Liner.Entities;
using Liner.MovingStrategies;
+using System.Drawing;
+using static System.Windows.Forms.VisualStyles.VisualStyleElement.Window;
namespace Liner
{
@@ -16,12 +18,18 @@ namespace Liner
///
private AbstractStrategy? _abstractStrategy;
///
+ ///
+ ///
+ public DrawingLiner? SelectedLiner { get; private set; }
+ ///
///
///
public MainScreen()
{
InitializeComponent();
bmp = new(pictureBoxLiner.Width, pictureBoxLiner.Height);
+ SelectedLiner = null;
+ _abstractStrategy = null;
}
///
///
@@ -36,17 +44,15 @@ namespace Liner
gr.Clear(Color.White);
_drawingLiner.DrawTransport(gr);
pictureBoxLiner.Image = bmp;
- gr.Dispose();
}
private void buttonCreateLiner_Click(object sender, EventArgs e)
{
Random random = new();
+ Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
_drawingLiner = new DrawingLiner(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)),
+ random.Next(1000, 3000), mainColor, addColor,
pictureBoxLiner.Width, pictureBoxLiner.Height);
_drawingLiner.SetPosition(random.Next(10, 100), random.Next(10, 100));
Draw();
@@ -80,12 +86,15 @@ namespace Liner
private void buttonCreateBigLiner_Click(object sender, EventArgs e)
{
Random random = new();
+ Color mainColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ Color addColor = Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ addColor = dialog.Color;
+ }
_drawingLiner = new DrawingBigLiner(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)),
+ random.Next(1000, 3000), mainColor, addColor,
Convert.ToBoolean(random.Next(0, 2)),
Convert.ToBoolean(random.Next(1, 2)),
pictureBoxLiner.Width, pictureBoxLiner.Height);
@@ -128,5 +137,11 @@ namespace Liner
_abstractStrategy = null;
}
}
+ private void buttonSelectLiner_Click(object sender, EventArgs e)
+ {
+ SelectedLiner = _drawingLiner;
+ DialogResult = DialogResult.OK;
+ }
+
}
}
\ No newline at end of file
diff --git a/Liner/MovingStrategies/DrawingObjectLiner.cs b/Liner/MovingStrategies/DrawingObjectLiner.cs
index aa00f5c..0afe82d 100644
--- a/Liner/MovingStrategies/DrawingObjectLiner.cs
+++ b/Liner/MovingStrategies/DrawingObjectLiner.cs
@@ -35,5 +35,4 @@ namespace Liner.MovingStrategies
public void MoveObject(DirectionType direction) =>
_drawingLiner?.MoveTransport(direction);
}
-
}
diff --git a/Liner/Program.cs b/Liner/Program.cs
index 8976e9d..959f24c 100644
--- a/Liner/Program.cs
+++ b/Liner/Program.cs
@@ -11,7 +11,43 @@ namespace Liner
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new MainScreen());
+ Application.Run(new FormLinerCollection());
}
}
-}
\ No newline at end of file
+}
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+