diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/AbstractCompany.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..f55bf5a
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,120 @@
+using DoubleDeckerBus.Drawnings;
+using System;
+using System.CodeDom;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms.VisualStyles;
+
+namespace DoubleDeckerBus.CollectionGenericObjects;
+
+///
+/// Абстракция компаниии, хранящей коллекцию автобусов
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места(ширина)
+ ///
+ protected readonly int _placeSizeWidth = 210;
+
+ ///
+ /// Размер места(высота)
+ ///
+ protected readonly int _placeSizeHeight = 80;
+
+ ///
+ /// Ширина окна
+ ///
+ protected readonly int _pictureWidth;
+
+ ///
+ /// Высота окна
+ ///
+ protected readonly int _pictureHeight;
+
+ ///
+ /// Коллекция автобусов
+ ///
+ protected ICollectionGenericObjects? _collection = null;
+
+ ///
+ /// Вычисление максимального кол-ва элементов, который можно разместить в окне
+ ///
+ private int GetMaxCount => _pictureWidth * _pictureHeight / (_placeSizeWidth * _placeSizeHeight);
+
+ ///
+ /// Конструктор
+ ///
+ /// Ширина окна
+ /// Высота окна
+ /// Коллекция автобусов
+ public AbstractCompany(int picWidth, int picHeight, ICollectionGenericObjects collection)
+ {
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _collection = collection;
+ _collection.SetMaxCount = GetMaxCount;
+ }
+
+ ///
+ /// Перегрузка оператора сложения для класса
+ ///
+ /// Компания
+ /// Добавляемый объект
+ ///
+ public static bool operator +(AbstractCompany company, DrawingBus bus)
+ {
+ return company._collection?.Insert(bus) ?? false;
+ }
+
+ ///
+ /// Переугрузка оператора вычитания для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static bool operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position) ?? false;
+ }
+
+ public DrawingBus? GetRandomObject()
+ {
+ Random rnd = new();
+ return _collection?.Get(rnd.Next(GetMaxCount));
+ }
+
+ ///
+ /// Вывод всей коллекции
+ ///
+ ///
+ public Bitmap? Show()
+ {
+ Bitmap bitmap = new(_pictureWidth, _pictureHeight);
+ Graphics graphics = Graphics.FromImage(bitmap);
+ DrawBackground(graphics);
+
+ SetObjectsPosition();
+ for (int i = 0; i < (_collection?.Count ?? 0); ++i)
+ {
+ DrawingBus? obj = _collection?.Get(i);
+ obj?.DrawTrasnport(graphics);
+ }
+
+ return bitmap;
+ }
+
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackground(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/BusStation.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/BusStation.cs
new file mode 100644
index 0000000..6027ca1
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/BusStation.cs
@@ -0,0 +1,25 @@
+using DoubleDeckerBus.Drawnings;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DoubleDeckerBus.CollectionGenericObjects;
+
+public class BusStation : AbstractCompany
+{
+ public BusStation(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+
+ protected override void DrawBackground(Graphics g)
+ {
+ throw new NotImplementedException();
+ }
+
+ protected override void SetObjectsPosition()
+ {
+ throw new NotImplementedException();
+ }
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/ICollectionGenericObjects.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/ICollectionGenericObjects.cs
new file mode 100644
index 0000000..8c67a07
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -0,0 +1,54 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DoubleDeckerBus.CollectionGenericObjects;
+
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public interface ICollectionGenericObjects
+ where T : class
+{
+ ///
+ /// Кол-во объектов в коллекции
+ ///
+ int Count { get; }
+
+ ///
+ /// Установка максимального кол-ва элементов
+ ///
+ int SetMaxCount { set; }
+
+ ///
+ /// Добавление объекта в коллекцию
+ ///
+ /// Добавляемый объект
+ /// true - вставка прошла успешно, false - вставка не удалась
+ bool Insert(T obj);
+
+ ///
+ /// Добавление элемента на конкретную позицию
+ ///
+ /// Добавляемый объект
+ /// Позиция
+ /// true - вставка прошла успешно, false - вставка не удалась
+ bool Insert(T obj, int position);
+
+ ///
+ /// Удаление объекта из коллекции с конкретной позиции
+ ///
+ /// Позиция
+ /// true - удаление прошло успешно, false - удаление не удалось
+ bool Remove(int position);
+
+ ///
+ /// Получение объекта по позиции
+ ///
+ /// Позиция
+ /// Объект
+ T? Get(int position);
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/MassiveGenericObjects.cs b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/MassiveGenericObjects.cs
new file mode 100644
index 0000000..2c40eb9
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -0,0 +1,98 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace DoubleDeckerBus.CollectionGenericObjects;
+
+///
+/// Параметризованный набор объектов
+///
+/// Параметр: ограничение - ссылочный тип
+public class MassiveGenericObjects : ICollectionGenericObjects
+ where T : class
+{
+ private T?[] _collection;
+
+ public int Count => _collection.Length;
+
+ public int SetMaxCount
+ {
+ set
+ {
+ if (value > 0)
+ {
+ if (_collection.Length > 0)
+ {
+ Array.Resize(ref _collection, value);
+ }
+ else
+ {
+ _collection = new T?[value];
+ }
+ }
+ }
+ }
+ public MassiveGenericObjects()
+ {
+ _collection = Array.Empty();
+ }
+
+ public T? Get(int position)//возможно придётся доделать
+ {
+ if (position < 0 || position > Count)
+ {
+ return null;
+ }
+ return _collection[position];
+
+ }
+
+ public bool Insert(T obj)
+ {
+ if (Insert(obj, 0))
+ {
+ return true;
+ }
+ return false;
+ }
+
+ public bool Insert(T obj, int position)
+ {
+ //проверка позиции
+ if (position < 0 || position > Count)
+ {
+ return false;
+ }
+
+ if (_collection[position] == null)
+ {
+ _collection[position] = obj;
+ return true;
+ }
+ else
+ {
+ if (Insert(obj, position + 1))
+ {
+ return true;
+ }
+ if (Insert(obj, position - 1))
+ {
+ return true;
+ }
+ }
+ return false;
+
+ }
+
+ public bool Remove(int position)
+ {
+ if (position < 0 || position > Count)
+ {
+ return false;
+ }
+ _collection[position] = null;
+ return true;
+ }
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs
new file mode 100644
index 0000000..dececd8
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.Designer.cs
@@ -0,0 +1,172 @@
+namespace DoubleDeckerBus
+{
+ 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()
+ {
+ groupBoxTools = new GroupBox();
+ buttonRefresh = new Button();
+ buttonGoToCheck = new Button();
+ buttonRemoveBus = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddDoublrDeckerBus = new Button();
+ buttonAddBus = new Button();
+ comboBoxSelectCompany = new ComboBox();
+ pictureBox = new PictureBox();
+ groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).BeginInit();
+ SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ groupBoxTools.Controls.Add(buttonRefresh);
+ groupBoxTools.Controls.Add(buttonGoToCheck);
+ groupBoxTools.Controls.Add(buttonRemoveBus);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddDoublrDeckerBus);
+ groupBoxTools.Controls.Add(buttonAddBus);
+ groupBoxTools.Controls.Add(comboBoxSelectCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(600, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(200, 450);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Text = "Tools";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 390);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(188, 35);
+ buttonRefresh.TabIndex = 6;
+ buttonRefresh.Text = "Refresh";
+ buttonRefresh.UseVisualStyleBackColor = true;
+ buttonRefresh.Click += ButtonRefresh_Click;
+ //
+ // buttonGoToCheck
+ //
+ buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonGoToCheck.Location = new Point(6, 312);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(188, 35);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Send to check";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveBus
+ //
+ buttonRemoveBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveBus.Location = new Point(6, 225);
+ buttonRemoveBus.Name = "buttonRemoveBus";
+ buttonRemoveBus.Size = new Size(188, 35);
+ buttonRemoveBus.TabIndex = 4;
+ buttonRemoveBus.Text = "Remove bus";
+ buttonRemoveBus.UseVisualStyleBackColor = true;
+ buttonRemoveBus.Click += ButtonRemoveBus_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Location = new Point(6, 196);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(182, 23);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddDoublrDeckerBus
+ //
+ buttonAddDoublrDeckerBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddDoublrDeckerBus.Location = new Point(6, 126);
+ buttonAddDoublrDeckerBus.Name = "buttonAddDoublrDeckerBus";
+ buttonAddDoublrDeckerBus.Size = new Size(188, 35);
+ buttonAddDoublrDeckerBus.TabIndex = 2;
+ buttonAddDoublrDeckerBus.Text = "Add double-decker bus";
+ buttonAddDoublrDeckerBus.UseVisualStyleBackColor = true;
+ buttonAddDoublrDeckerBus.Click += ButtonAddDoublrDeckerBus_Click;
+ //
+ // buttonAddBus
+ //
+ buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddBus.Location = new Point(6, 85);
+ buttonAddBus.Name = "buttonAddBus";
+ buttonAddBus.Size = new Size(188, 35);
+ buttonAddBus.TabIndex = 1;
+ buttonAddBus.Text = "Add bus";
+ buttonAddBus.UseVisualStyleBackColor = true;
+ buttonAddBus.Click += ButtonAddBus_Click;
+ //
+ // comboBoxSelectCompany
+ //
+ comboBoxSelectCompany.DropDownStyle = ComboBoxStyle.DropDownList;
+ comboBoxSelectCompany.FormattingEnabled = true;
+ comboBoxSelectCompany.Items.AddRange(new object[] { "Storage" });
+ comboBoxSelectCompany.Location = new Point(6, 22);
+ comboBoxSelectCompany.Name = "comboBoxSelectCompany";
+ comboBoxSelectCompany.Size = new Size(188, 23);
+ comboBoxSelectCompany.TabIndex = 0;
+ comboBoxSelectCompany.SelectedIndexChanged += comboBoxSelectCompany_SelectedIndexChanged;
+ //
+ // pictureBox
+ //
+ pictureBox.Dock = DockStyle.Fill;
+ pictureBox.Location = new Point(0, 0);
+ pictureBox.Name = "pictureBox";
+ pictureBox.Size = new Size(600, 450);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormBusCollection
+ //
+ AutoScaleDimensions = new SizeF(7F, 15F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(800, 450);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormBusCollection";
+ Text = "Bus collection";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectCompany;
+ private Button buttonAddDoublrDeckerBus;
+ private Button buttonAddBus;
+ private Button buttonRemoveBus;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs
new file mode 100644
index 0000000..037219a
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.cs
@@ -0,0 +1,153 @@
+using DoubleDeckerBus.CollectionGenericObjects;
+using DoubleDeckerBus.Drawnings;
+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 DoubleDeckerBus;
+
+public partial class FormBusCollection : Form
+{
+ private AbstractCompany? _company = null;
+
+ ///
+ /// Конструктор
+ ///
+ public FormBusCollection()
+ {
+ InitializeComponent();
+ }
+
+ private void comboBoxSelectCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectCompany.Text)
+ {
+ case "Storage":
+ _company = new BusStation(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ Random random = new();
+ DrawingBus drawingBus;
+ switch (type)
+ {
+ case nameof(DrawingBus):
+ drawingBus = new DrawingBus(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawingDoubleDeckerBus):
+ drawingBus = new DrawingDoubleDeckerBus(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random),
+ GetColor(random),
+ Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+
+ if (_company + drawingBus)
+ {
+ MessageBox.Show("Object added");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Failed to add object");
+ }
+ }
+
+ private static Color GetColor(Random random)
+ {
+ 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;
+ }
+
+ return color;
+ }
+
+ private void ButtonAddBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingBus));
+
+ private void ButtonAddDoublrDeckerBus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawingDoubleDeckerBus));
+
+ private void ButtonRemoveBus_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null)
+ {
+ return;
+ }
+
+ if (MessageBox.Show("Remove object?", "Removal", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+
+ int pos = Convert.ToInt32(maskedTextBox.Text);
+ if (_company - pos)
+ {
+ MessageBox.Show("Object removed");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Failed to remove object");
+ }
+
+ }
+
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawingBus? bus = null;
+ int counter = 100;
+ while (bus == null)
+ {
+ bus = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+
+ if (bus == null)
+ {
+ return;
+ }
+
+ FormDoubleDeckerBus form = new()
+ {
+ SetBus = bus
+ };
+ form.ShowDialog();
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.resx b/DoubleDeckerBus/DoubleDeckerBus/FormBusCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/DoubleDeckerBus/DoubleDeckerBus/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/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.Designer.cs b/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.Designer.cs
index a56dad7..b1a1711 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.Designer.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.Designer.cs
@@ -28,29 +28,16 @@
///
private void InitializeComponent()
{
- buttonCreateDoubleDeckerBus = new Button();
pictureBoxDoubleDeckerBus = new PictureBox();
buttonLeft = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonRight = new Button();
- CreateBus = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxDoubleDeckerBus).BeginInit();
SuspendLayout();
//
- // buttonCreateDoubleDeckerBus
- //
- buttonCreateDoubleDeckerBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateDoubleDeckerBus.Location = new Point(12, 415);
- buttonCreateDoubleDeckerBus.Name = "buttonCreateDoubleDeckerBus";
- buttonCreateDoubleDeckerBus.Size = new Size(159, 23);
- buttonCreateDoubleDeckerBus.TabIndex = 1;
- buttonCreateDoubleDeckerBus.Text = "Create DoubleDeckerBus";
- buttonCreateDoubleDeckerBus.UseVisualStyleBackColor = true;
- buttonCreateDoubleDeckerBus.Click += buttonCreateDoubleDeckerBus_Click;
- //
// pictureBoxDoubleDeckerBus
//
pictureBoxDoubleDeckerBus.Dock = DockStyle.Fill;
@@ -108,17 +95,6 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += buttonMove_Click;
//
- // CreateBus
- //
- CreateBus.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- CreateBus.Location = new Point(188, 415);
- CreateBus.Name = "CreateBus";
- CreateBus.Size = new Size(159, 23);
- CreateBus.TabIndex = 7;
- CreateBus.Text = "Create Bus";
- CreateBus.UseVisualStyleBackColor = true;
- CreateBus.Click += buttonCreateBus_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.Anchor = AnchorStyles.Top | AnchorStyles.Right;
@@ -148,12 +124,10 @@
ClientSize = new Size(800, 450);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(CreateBus);
Controls.Add(buttonRight);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
Controls.Add(buttonLeft);
- Controls.Add(buttonCreateDoubleDeckerBus);
Controls.Add(pictureBoxDoubleDeckerBus);
Name = "FormDoubleDeckerBus";
StartPosition = FormStartPosition.CenterScreen;
@@ -163,13 +137,11 @@
}
#endregion
- private Button buttonCreateDoubleDeckerBus;
private PictureBox pictureBoxDoubleDeckerBus;
private Button buttonLeft;
private Button buttonUp;
private Button buttonDown;
private Button buttonRight;
- private Button CreateBus;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.cs b/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.cs
index e3168c9..5b34b25 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/FormDoubleDeckerBus.cs
@@ -17,6 +17,18 @@ namespace DoubleDeckerBus
private DrawingBus? _drawingBus;
private AbstractStrategy? _strategy;
+
+ public DrawingBus SetBus
+ {
+ set
+ {
+ _drawingBus = value;
+ _drawingBus.SetPictureSize(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
public FormDoubleDeckerBus()
{
InitializeComponent();
@@ -37,41 +49,6 @@ namespace DoubleDeckerBus
pictureBoxDoubleDeckerBus.Image = bmp;
}
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawingBus):
- _drawingBus = new DrawingBus(random.Next(100, 300), random.Next(1000, 3000),
- Color.FromArgb(random.Next(0, 256), random.Next(0, 256), random.Next(0, 256)));
- break;
- case nameof(DrawingDoubleDeckerBus):
- _drawingBus = new DrawingDoubleDeckerBus(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)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
-
- _drawingBus.SetPictureSize(pictureBoxDoubleDeckerBus.Width, pictureBoxDoubleDeckerBus.Height);
- _drawingBus.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
- comboBoxStrategy.Enabled = true;
- Draw();
- }
-
- private void buttonCreateDoubleDeckerBus_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingDoubleDeckerBus));
- }
- private void buttonCreateBus_Click(object sender, EventArgs e)
- {
- CreateObject(nameof(DrawingBus));
- }
-
private void buttonMove_Click(object sender, EventArgs e)
{
if (_drawingBus == null)
diff --git a/DoubleDeckerBus/DoubleDeckerBus/Program.cs b/DoubleDeckerBus/DoubleDeckerBus/Program.cs
index 913b697..8dd5e23 100644
--- a/DoubleDeckerBus/DoubleDeckerBus/Program.cs
+++ b/DoubleDeckerBus/DoubleDeckerBus/Program.cs
@@ -11,7 +11,7 @@ namespace DoubleDeckerBus
// 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