diff --git a/ProjectAirbus.zip b/ProjectAirbus.zip new file mode 100644 index 0000000..a383d7a Binary files /dev/null and b/ProjectAirbus.zip differ diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..5349f37 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,116 @@ +using ProjectAirbus.Drawnings; + +namespace ProjectMotorboat.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию автомобилей +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 180; + + /// + /// Размер места (высота) + /// + 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 int operator +(AbstractCompany company, DrawningBus bus) + { + return company._collection?.Insert(bus) ?? -1; + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningBus operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position) ?? null; + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningBus? GetRandomObject() + { + Random rnd = new(); + return _collection?.Get(rnd.Next(GetMaxCount)); + } + + /// + /// Вывод всей коллекции + /// + /// + public Bitmap? Show() + { + Bitmap bitmap = new(_pictureWidth, _pictureHeight); + Graphics graphics = Graphics.FromImage(bitmap); + DrawBackgound(graphics); + + SetObjectsPosition(); + for (int i = 0; i < (_collection?.Count ?? 0); ++i) + { + DrawningBus? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs new file mode 100644 index 0000000..b89407b --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/AerodromService.cs @@ -0,0 +1,80 @@ +using ProjectAirbus.CollectionGenericObjects; +using ProjectAirbus.Drawnings; +using ProjectMotorboat.CollectionGenericObjects; + +namespace ProjectAirbus.CollectionGenericObjects; + +/// +/// Реализация абстрактной компании - каршеринг +/// +public class AerodromService : AbstractCompany +{ + private List> locCoord = new List>(); + private int numRows, numCols; + /// + /// Конструктор + /// + /// + /// + /// + public AerodromService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + protected override void DrawBackgound(Graphics g) + { + Pen pen = new Pen(Color.LightBlue, 3); + int offsetX = 10; + int offsetY = -12; + int x = 1 + offsetX, y = _pictureHeight - _placeSizeHeight + offsetY; + numRows = 0; + while (y >= 0) + { + int numCols = 0; + while (x + _placeSizeWidth <= _pictureWidth) + { + numCols++; + g.DrawLine(pen, x, y, x + _placeSizeWidth / 2, y); + g.DrawLine(pen, x, y, x, y + _placeSizeHeight + 8); + locCoord.Add(new Tuple(x, y)); + x += _placeSizeWidth + 2; + } + numRows++; + x = 1 + offsetX; + y -= _placeSizeHeight + 5 + offsetY; + } + + } + + protected override void SetObjectsPosition() + { + int width = _pictureWidth / _placeSizeWidth; + int height = _pictureHeight / _placeSizeHeight; + + int curWidth = width - 1; + int curHeight = height - 1; + + for (int i = 0; i < (_collection?.Count ?? 0); i++) + { + if (_collection.Get(i) != null) + { + _collection.Get(i).SetPictureSize(_pictureWidth, _pictureHeight); + _collection.Get(i).SetPosition(_placeSizeWidth * curWidth + 20, curHeight * _placeSizeHeight + 15); + } + + if (curWidth > 0) + curWidth--; + else + { + curWidth = width - 1; + curHeight--; + } + if (curHeight > height) + { + return; + } + } + + + } +} diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..eaf98c0 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMotorboat.CollectionGenericObjects; + +public interface ICollectionGenericObjects + + where T : class +{ + int Count { get; } + int SetMaxCount { set; } + int Insert(T obj); + int Insert(T obj, int position); + T Remove(int position); + T? Get(int position); +} + diff --git a/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..d80b1b2 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,123 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace ProjectMotorboat.CollectionGenericObjects; + +internal 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) + { + // TODO проверка позиции + if (position >= _collection.Length || position < 0) + { return null; } + return _collection[position]; + } + + public int Insert(T obj) + { + // TODO вставка в свободное место набора + int index = 0; + while (index < _collection.Length) + { + if (_collection[index] == null) + { + _collection[index] = obj; + return index; + } + + index++; + } + return -1; + } + + public int Insert(T obj, int position) + { + // TODO проверка позиции + // TODO проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + // TODO вставка + if (position >= _collection.Length || position < 0) + { return -1; } + + if (_collection[position] == null) + { + _collection[position] = obj; + return position; + } + int index; + + for (index = position + 1; index < _collection.Length; ++index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + + for (index = position - 1; index >= 0; --index) + { + if (_collection[index] == null) + { + _collection[position] = obj; + return position; + } + } + return -1; + } + + public T? Remove(int position) + { + // TODO проверка позиции + // TODO удаление объекта из массива, присвоив элементу массива значение null + if (position >= _collection.Length || position < 0) + { + return null; + } + T obj = _collection[position]; + _collection[position] = null; + return obj; + } +} + + diff --git a/ProjectAirbus/ProjectAirbus/FormAirbus.cs b/ProjectAirbus/ProjectAirbus/FormAirbus.cs index e9647a3..15578ed 100644 --- a/ProjectAirbus/ProjectAirbus/FormAirbus.cs +++ b/ProjectAirbus/ProjectAirbus/FormAirbus.cs @@ -19,6 +19,18 @@ namespace ProjectAirbus private DrawningBus? _drawningBus; private AbstractStrategy? _strategy; + + public DrawningBus SetBus + { + set + { + _drawningBus = value; + _drawningBus.SetPictureSize(pictureAirbus.Width, pictureAirbus.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } public FormAirbus() { InitializeComponent(); diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs new file mode 100644 index 0000000..bc3308e --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.Designer.cs @@ -0,0 +1,172 @@ +namespace ProjectAirbus +{ + 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(); + buttonGoToChek = new Button(); + buttonDelBus = new Button(); + maskedTextBox = new MaskedTextBox(); + buttonAddAirBus = new Button(); + buttonAddBus = new Button(); + comboBoxSelectorCompany = new ComboBox(); + pictureBox1 = new PictureBox(); + groupBoxTools.SuspendLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).BeginInit(); + SuspendLayout(); + // + // groupBoxTools + // + groupBoxTools.Controls.Add(buttonRefresh); + groupBoxTools.Controls.Add(buttonGoToChek); + groupBoxTools.Controls.Add(buttonDelBus); + groupBoxTools.Controls.Add(maskedTextBox); + groupBoxTools.Controls.Add(buttonAddAirBus); + groupBoxTools.Controls.Add(buttonAddBus); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(774, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(303, 584); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(15, 523); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(276, 49); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить "; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += buttonRefresh_Click; + // + // buttonGoToChek + // + buttonGoToChek.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToChek.Location = new Point(15, 445); + buttonGoToChek.Name = "buttonGoToChek"; + buttonGoToChek.Size = new Size(276, 49); + buttonGoToChek.TabIndex = 5; + buttonGoToChek.Text = "Передать на тесты"; + buttonGoToChek.UseVisualStyleBackColor = true; + // + // buttonDelBus + // + buttonDelBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonDelBus.Location = new Point(15, 344); + buttonDelBus.Name = "buttonDelBus"; + buttonDelBus.Size = new Size(276, 49); + buttonDelBus.TabIndex = 4; + buttonDelBus.Text = "Удалить самолет"; + buttonDelBus.UseVisualStyleBackColor = true; + // + // maskedTextBox + // + maskedTextBox.Location = new Point(15, 311); + maskedTextBox.Mask = "00"; + maskedTextBox.Name = "maskedTextBox"; + maskedTextBox.Size = new Size(276, 27); + maskedTextBox.TabIndex = 3; + maskedTextBox.ValidatingType = typeof(int); + maskedTextBox.MaskInputRejected += maskedTextBox_MaskInputRejected; + // + // buttonAddAirBus + // + buttonAddAirBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirBus.Location = new Point(15, 181); + buttonAddAirBus.Name = "buttonAddAirBus"; + buttonAddAirBus.Size = new Size(276, 49); + buttonAddAirBus.TabIndex = 2; + buttonAddAirBus.Text = "Добавление аэробуса"; + buttonAddAirBus.UseVisualStyleBackColor = true; + buttonAddAirBus.Click += ButtonAddAirbus_Click; + // + // buttonAddBus + // + buttonAddBus.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBus.Location = new Point(15, 125); + buttonAddBus.Name = "buttonAddBus"; + buttonAddBus.Size = new Size(276, 50); + buttonAddBus.TabIndex = 1; + buttonAddBus.Text = "Добавление самолета"; + buttonAddBus.UseVisualStyleBackColor = true; + buttonAddBus.Click += ButtonAddPlane_Click; + // + // comboBoxSelectorCompany + // + comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList; + comboBoxSelectorCompany.FormattingEnabled = true; + comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" }); + comboBoxSelectorCompany.Location = new Point(15, 26); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(276, 28); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += comboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox1 + // + pictureBox1.Dock = DockStyle.Fill; + pictureBox1.Location = new Point(0, 0); + pictureBox1.Name = "pictureBox1"; + pictureBox1.Size = new Size(774, 584); + pictureBox1.TabIndex = 1; + pictureBox1.TabStop = false; + // + // FormBusCollection + // + AutoScaleDimensions = new SizeF(8F, 20F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1077, 584); + Controls.Add(pictureBox1); + Controls.Add(groupBoxTools); + Name = "FormBusCollection"; + Text = "Коллекция самолетов "; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAirBus; + private Button buttonAddBus; + private PictureBox pictureBox1; + private Button buttonDelBus; + private MaskedTextBox maskedTextBox; + private Button buttonRefresh; + private Button buttonGoToChek; + } +} \ No newline at end of file diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.cs b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs new file mode 100644 index 0000000..b559f2e --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/FormBusCollection.cs @@ -0,0 +1,185 @@ +using ProjectAirbus.CollectionGenericObjects; +using ProjectAirbus.Drawnings; +using ProjectMotorboat.CollectionGenericObjects; +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 ProjectAirbus +{ + public partial class FormBusCollection : Form + { + private AbstractCompany? _company; + public FormBusCollection() + { + InitializeComponent(); + } + private void comboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new AerodromService(pictureBox1.Width, pictureBox1.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + 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 CreateObject(string type) + { + if (_company == null) + { + return; + } + DrawningBus _drawningShip; + Random random = new(); + switch (type) + { + case nameof(DrawningBus): + _drawningShip = new DrawningBus(random.Next(30, 70), random.Next(100, 500), + GetColor(random)); + break; + case nameof(DrawningAirbus): + _drawningShip = new DrawningAirbus(random.Next(30, 70), random.Next(100, 500), + GetColor(random), GetColor(random), + Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2))); + break; + default: + return; + + } + if (_company + _drawningShip != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox1.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось добавить объект"); + } + } + + /// + /// добавить самолет + /// + /// + /// + private void ButtonAddPlane_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBus)); + + /// + /// добавить аэробус + /// + /// + /// + private void ButtonAddAirbus_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirbus)); + + /// + /// Удаление объекта + /// + /// + /// + private void buttonDelPlane_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBox.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBox.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox1.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void buttonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningBus? bus = null; + int counter = 100; + while (bus == null) + { + bus = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (bus == null) + { + return; + } + + FormAirbus form = new(); + form.SetBus = bus; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void buttonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox1.Image = _company.Show(); + } + + private void maskedTextBox_MaskInputRejected(object sender, MaskInputRejectedEventArgs e) + { + + } + } +} diff --git a/ProjectAirbus/ProjectAirbus/FormBusCollection.resx b/ProjectAirbus/ProjectAirbus/FormBusCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirbus/ProjectAirbus/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/ProjectAirbus/ProjectAirbus/Program.cs b/ProjectAirbus/ProjectAirbus/Program.cs index 9d45ae4..34ef3f3 100644 --- a/ProjectAirbus/ProjectAirbus/Program.cs +++ b/ProjectAirbus/ProjectAirbus/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAirbus // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirbus()); + Application.Run(new FormBusCollection()); } } } \ No newline at end of file