From f80ead5cf8860b87f98f69c05acb7de0d49dd31f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=92=D1=8F=D1=87=D0=B5=D1=81=D0=BB=D0=B0=D0=B2=20=D0=98?= =?UTF-8?q?=D0=B2=D0=B0=D0=BD=D0=BE=D0=B2?= Date: Sat, 7 Oct 2023 00:59:22 +0400 Subject: [PATCH] Done --- .../DrawningObjects/DrawningBus.cs | 7 + .../FormBusCollection.Designer.cs | 133 +++++++++++++++ .../FormBusCollection.cs | 92 +++++++++++ .../FormBusCollection.resx | 120 ++++++++++++++ .../FormDoubleDeckerBus.Designer.cs | 14 ++ .../FormDoubleDeckerBus.cs | 66 ++++++-- .../Generics/SetGeneric.cs | 118 +++++++++++++ .../Generics/TheBusesGenericCollection.cs | 155 ++++++++++++++++++ .../Program.cs | 2 +- 9 files changed, 689 insertions(+), 18 deletions(-) create mode 100644 PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.Designer.cs create mode 100644 PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs create mode 100644 PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.resx create mode 100644 PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs create mode 100644 PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/DrawningObjects/DrawningBus.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/DrawningObjects/DrawningBus.cs index 16b3f7a..a67f67b 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/DrawningObjects/DrawningBus.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/DrawningObjects/DrawningBus.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Entities; +using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy; namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects { @@ -17,6 +18,12 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects /// public EntityBus? EntityBus { get; protected set; } + /// + /// Получение объекта IMoveableObject из объекта DrawningCar + /// + public IMoveableObject GetMoveableObject => new DrawningObjectBus(this); + + /// /// Ширина окна /// diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.Designer.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.Designer.cs new file mode 100644 index 0000000..5792355 --- /dev/null +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.Designer.cs @@ -0,0 +1,133 @@ +namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base +{ + partial class FormBusCollection + { + /// + /// 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() + { + toolsLabel = new Panel(); + ButtonRefreshCollection = new Button(); + ButtonDeleteBus = new Button(); + maskedTextBoxNumber = new TextBox(); + addBus = new Button(); + label1 = new Label(); + pictureBoxCollection = new PictureBox(); + toolsLabel.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).BeginInit(); + SuspendLayout(); + // + // toolsLabel + // + toolsLabel.Controls.Add(ButtonRefreshCollection); + toolsLabel.Controls.Add(ButtonDeleteBus); + toolsLabel.Controls.Add(maskedTextBoxNumber); + toolsLabel.Controls.Add(addBus); + toolsLabel.Controls.Add(label1); + toolsLabel.Location = new Point(581, -2); + toolsLabel.Name = "toolsLabel"; + toolsLabel.Size = new Size(221, 451); + toolsLabel.TabIndex = 0; + // + // ButtonRefreshCollection + // + ButtonRefreshCollection.Location = new Point(10, 194); + ButtonRefreshCollection.Name = "ButtonRefreshCollection"; + ButtonRefreshCollection.Size = new Size(197, 41); + ButtonRefreshCollection.TabIndex = 4; + ButtonRefreshCollection.Text = "Обновить коллекцию"; + ButtonRefreshCollection.UseVisualStyleBackColor = true; + ButtonRefreshCollection.Click += ButtonRefreshCollection_Click; + // + // ButtonDeleteBus + // + ButtonDeleteBus.Location = new Point(10, 121); + ButtonDeleteBus.Name = "ButtonDeleteBus"; + ButtonDeleteBus.Size = new Size(197, 41); + ButtonDeleteBus.TabIndex = 3; + ButtonDeleteBus.Text = "Удалить автобус"; + ButtonDeleteBus.UseVisualStyleBackColor = true; + ButtonDeleteBus.Click += ButtonDeleteBus_Click; + // + // maskedTextBoxNumber + // + maskedTextBoxNumber.Location = new Point(50, 88); + maskedTextBoxNumber.Name = "maskedTextBoxNumber"; + maskedTextBoxNumber.Size = new Size(125, 27); + maskedTextBoxNumber.TabIndex = 2; + // + // addBus + // + addBus.Location = new Point(10, 26); + addBus.Name = "addBus"; + addBus.Size = new Size(197, 41); + addBus.TabIndex = 1; + addBus.Text = "Добавить автобус"; + addBus.UseVisualStyleBackColor = true; + addBus.Click += ButtonAddBus_Click; + // + // label1 + // + label1.AutoSize = true; + label1.Location = new Point(5, 0); + label1.Name = "label1"; + label1.Size = new Size(103, 20); + label1.TabIndex = 0; + label1.Text = "Инструменты"; + // + // pictureBoxCollection + // + pictureBoxCollection.Location = new Point(1, -2); + pictureBoxCollection.Name = "pictureBoxCollection"; + pictureBoxCollection.Size = new Size(579, 451); + pictureBoxCollection.TabIndex = 1; + pictureBoxCollection.TabStop = false; + // + // FormBusCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 450); + Controls.Add(pictureBoxCollection); + Controls.Add(toolsLabel); + Name = "FormBusCollection"; + Text = "Набор автобусов"; + toolsLabel.ResumeLayout(false); + toolsLabel.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBoxCollection).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Panel toolsLabel; + private Label label1; + private Button ButtonDeleteBus; + private Button addBus; + private Button ButtonRefreshCollection; + private PictureBox pictureBoxCollection; + public TextBox maskedTextBoxNumber; + } +} \ No newline at end of file diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs new file mode 100644 index 0000000..b6e8277 --- /dev/null +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.cs @@ -0,0 +1,92 @@ +using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics; +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 PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects; +using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy; + +namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base +{ + /// + /// Форма для работы с набором объектов класса DrawningBus + /// + public partial class FormBusCollection : Form + { + /// + /// Набор объектов + /// + private readonly TheBusesGenericCollection _theBuses; + + /// + /// Конструктор + /// + public FormBusCollection() + { + InitializeComponent(); + _theBuses = new TheBusesGenericCollection + (pictureBoxCollection.Width, pictureBoxCollection.Height); + } + + /// + /// Добавление объекта в набор + /// + /// + /// + private void ButtonAddBus_Click(object sender, EventArgs e) + { + FormDoubleDeckerBus form = new(); + if (form.ShowDialog() == DialogResult.OK) + { + if (_theBuses + form.SelectedBus) + { + MessageBox.Show("Объект добавлен"); + pictureBoxCollection.Image = _theBuses.ShowTheBuses(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + } + + /// + /// Удаление объекта из набора + /// + /// + /// + private void ButtonDeleteBus_Click(object sender, EventArgs e) + { + if (MessageBox.Show("Удалить объект?", "Удаление", + MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) + { + return; + } + int pos = Convert.ToInt32(maskedTextBoxNumber.Text); + if (_theBuses - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBoxCollection.Image = _theBuses.ShowTheBuses(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Обновление рисунка по набору + /// + /// + /// + private void ButtonRefreshCollection_Click(object sender, EventArgs e) + { + pictureBoxCollection.Image = _theBuses.ShowTheBuses(); + } + } +} diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.resx b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormBusCollection.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/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.Designer.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.Designer.cs index 6419c2f..2b0ea68 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.Designer.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.Designer.cs @@ -37,6 +37,7 @@ comboBoxStrategy = new ComboBox(); buttonStep = new Button(); buttonCreateBus = new Button(); + ButtonSelectedBus = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxDoubleDeckerBus).BeginInit(); SuspendLayout(); // @@ -141,11 +142,23 @@ buttonCreateBus.UseVisualStyleBackColor = true; buttonCreateBus.Click += buttonCreateBus_Click; // + // ButtonSelectedBus + // + ButtonSelectedBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; + ButtonSelectedBus.Location = new Point(358, 389); + ButtonSelectedBus.Name = "ButtonSelectedBus"; + ButtonSelectedBus.Size = new Size(167, 52); + ButtonSelectedBus.TabIndex = 11; + ButtonSelectedBus.Text = "Добавить автобус"; + ButtonSelectedBus.UseVisualStyleBackColor = true; + ButtonSelectedBus.Click += ButtonSelectedBus_Click; + // // FormDoubleDeckerBus // AutoScaleDimensions = new SizeF(8F, 20F); AutoScaleMode = AutoScaleMode.Font; ClientSize = new Size(882, 453); + Controls.Add(ButtonSelectedBus); Controls.Add(buttonCreateBus); Controls.Add(buttonStep); Controls.Add(comboBoxStrategy); @@ -174,5 +187,6 @@ private ComboBox comboBoxStrategy; private Button buttonStep; private Button buttonCreateBus; + private Button ButtonSelectedBus; } } \ No newline at end of file diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.cs index f94315a..8e184b7 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/FormDoubleDeckerBus.cs @@ -13,7 +13,12 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base /// /// /// - private AbstractStrategy? _abstractStrategy; + private AbstractStrategy? _strategy; + + /// + /// + /// + public DrawningBus? SelectedBus { get; private set; } /// /// @@ -21,6 +26,8 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base public FormDoubleDeckerBus() { InitializeComponent(); + _strategy = null; + SelectedBus = null; } /// @@ -46,10 +53,24 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base private void ButtonCreateDoubleDeckerBus_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; + } + _drawningBus = new DrawningDoubleDeckerBus(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)), Convert.ToBoolean(random.Next(0, 2)), + random.Next(1000, 3000), color, dopColor, Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); @@ -64,9 +85,16 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base private void buttonCreateBus_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; + } + _drawningBus = new DrawningBus(random.Next(100, 300), random.Next(1000, 3000), - Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)), - pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height); + color, pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height); _drawningBus.SetPosition(random.Next(10, 100), random.Next(10, 100)); Draw(); } @@ -114,33 +142,37 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base } if (comboBoxStrategy.Enabled) { - _abstractStrategy = comboBoxStrategy.SelectedIndex - switch + _strategy = comboBoxStrategy.SelectedIndex switch { 0 => new MoveToCenter(), 1 => new MoveToBorder(), _ => null, }; - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.SetData(new - DrawningObjectBus(_drawningBus), pictureBoxDoubleDeckerBus.Width, - pictureBoxDoubleDeckerBus.Height); - comboBoxStrategy.Enabled = false; + _strategy.SetData(_drawningBus.GetMoveableObject, + pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height); } - if (_abstractStrategy == null) + if (_strategy == null) { return; } - _abstractStrategy.MakeStep(); + comboBoxStrategy.Enabled = false; + _strategy.MakeStep(); Draw(); - if (_abstractStrategy.GetStatus() == Status.Finish) + if (_strategy.GetStatus() == Status.Finish) { comboBoxStrategy.Enabled = true; - _abstractStrategy = null; + _strategy = null; } } + + private void ButtonSelectedBus_Click(object sender, EventArgs e) + { + SelectedBus = _drawningBus; + DialogResult = DialogResult.OK; + } } } \ No newline at end of file diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs new file mode 100644 index 0000000..c041aca --- /dev/null +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/SetGeneric.cs @@ -0,0 +1,118 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.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 bus) + { + if (_places[Count - 1] != null) + { + return false; + } + + return Insert(bus, 0); + } + + /// + /// Добавление объекта в набор на конкретную позицию + /// + /// Добавляемый автобус + /// Позиция + /// + public bool Insert(T bus, int position) + { + if (position < 0 || position >= _places.Length) + { + 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] = bus; + return true; + } + + /// + /// Удаление объекта из набора с конкретной позиции + /// + /// + /// + public bool Remove(int position) + { + if (position < 0 || position >= _places.Length || _places[position] == null) + { + 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/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs new file mode 100644 index 0000000..3eb9dea --- /dev/null +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Generics/TheBusesGenericCollection.cs @@ -0,0 +1,155 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.VisualBasic; +using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.DrawningObjects; +using PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.MovementStrategy; + +namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base.Generics +{ + /// + /// Параметризованный класс для набора объектов DrawningBus + /// + /// + /// + internal class TheBusesGenericCollection + where T : DrawningBus + 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 TheBusesGenericCollection(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 +(TheBusesGenericCollection collect, T? + obj) + { + if (obj == null) + { + return false; + } + return collect?._collection.Insert(obj) ?? false; + } + + /// + /// Перегрузка оператора вычитания + /// + /// + /// + /// + public static T? operator -(TheBusesGenericCollection 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 ShowTheBuses() + { + 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++) + { + DrawningBus bus = _collection.Get(i); + + if (bus != null) + { + int inRow = _pictureWidth / _placeSizeWidth; + bus.SetPosition((inRow - 1 - (i % inRow)) * _placeSizeWidth, + i / inRow * _placeSizeHeight); + bus.DrawTransport(g); + } + } + } + } +} diff --git a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Program.cs b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Program.cs index c3f5dfd..03f361e 100644 --- a/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Program.cs +++ b/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/PIbd-23_Ivanov_V.N._DoubleDeckerBus._Base/Program.cs @@ -11,7 +11,7 @@ namespace PIbd_23_Ivanov_V.N._DoubleDeckerBus._Base // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormDoubleDeckerBus()); + Application.Run(new FormBusCollection()); } } } \ No newline at end of file