diff --git a/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/AbstractCompany.cs new file mode 100644 index 0000000..76662de --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/AbstractCompany.cs @@ -0,0 +1,116 @@ +using ProjectAirBomber.Drawnings; + +namespace ProjectAirBomber.CollectionGenericObjects; + +/// +/// Абстракция компании, хранящий коллекцию самолетов +/// +public abstract class AbstractCompany +{ + /// + /// Размер места (ширина) + /// + protected readonly int _placeSizeWidth = 300; + + /// + /// Размер места (высота) + /// + protected readonly int _placeSizeHeight = 180; + + /// + /// Ширина окна + /// + 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, DrawningBomber bomber) + { + return company._collection.Insert(bomber); + } + + /// + /// Перегрузка оператора удаления для класса + /// + /// Компания + /// Номер удаляемого объекта + /// + public static DrawningBomber? operator -(AbstractCompany company, int position) + { + return company._collection?.Remove(position); + } + + /// + /// Получение случайного объекта из коллекции + /// + /// + public DrawningBomber? 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) + { + DrawningBomber? obj = _collection?.Get(i); + obj?.DrawTransport(graphics); + } + + return bitmap; + } + + /// + /// Вывод заднего фона + /// + /// + protected abstract void DrawBackgound(Graphics g); + + /// + /// Расстановка объектов + /// + protected abstract void SetObjectsPosition(); +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/BomberHungarService.cs b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/BomberHungarService.cs new file mode 100644 index 0000000..d83c69a --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/BomberHungarService.cs @@ -0,0 +1,63 @@ +using ProjectAirBomber.Drawnings; +using ProjectAirBomber.Entities; +using System; + +namespace ProjectAirBomber.CollectionGenericObjects; + +/// +/// Реализация абстрактной компании - Ангар самолёта +/// +public class BomberHungarService : AbstractCompany +{ + /// + /// Конструктор + /// + /// + /// + /// + public BomberHungarService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection) + { + } + + /// + /// Вывод заднего фона + /// + /// + /// + protected override void DrawBackgound(Graphics g) + { + Pen pen = new(Color.Black, 2); + for (int i = 0; i < _pictureWidth / _placeSizeWidth + 1; i++) + { + for(int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.7f)), _placeSizeHeight * j)); + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1))); + } + g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.7f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight))); + } + + + } + + /// + /// Установка объекта в Ангар + /// + protected override void SetObjectsPosition() + { + int n = 0; + for (int i = _pictureWidth / _placeSizeWidth; i > 0; i--) + { + for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++) + { + DrawningBomber? drawningBomber = _collection?.Get(n); + n++; + if (drawningBomber != null) + { + drawningBomber.SetPictureSize(_pictureWidth, _pictureHeight); + drawningBomber.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5); + } + } + } + } +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs new file mode 100644 index 0000000..e1c31a3 --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/ICollectionGenericObjects.cs @@ -0,0 +1,50 @@ +using ProjectAirBomber.Drawnings; + +namespace ProjectAirBomber.CollectionGenericObjects; + +/// +/// Интерфейс описания действий для набора хранимых объектов +/// +/// Параметр: ограничение - ссылочный тип +public interface ICollectionGenericObjects + where T : class +{ + /// + /// Количество объектов в коллекции + /// + int Count { get; } + + /// + /// Установка максимального количества элементов + /// + int SetMaxCount { set; } + + /// + /// Добавление объекта в коллекцию + /// + /// Добавляемый объект + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj); + + /// + /// Добавление объекта в коллекцию на конкретную позицию + /// + /// Добавляемый объект + /// Позиция + /// true - вставка прошла удачно, false - вставка не удалась + int Insert(T obj, int position); + + /// + /// Удаление объекта из коллекции с конкретной позиции + /// + /// Позиция + /// true - удаление прошло удачно, false - удаление не удалось + T? Remove(int position); + + /// + /// Получение объекта по позиции + /// + /// Позиция + /// Объект + T? Get(int position); +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/MassiveGenericObjects.cs new file mode 100644 index 0000000..e94f886 --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/CollectionGenericObjects/MassiveGenericObjects.cs @@ -0,0 +1,134 @@ +using System.Runtime.Remoting; +using ProjectAirBomber.Drawnings; + +namespace ProjectAirBomber.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 _collection[position]; + } + + return null; + } + + public int Insert(T obj) + { + // вставка в свободное место набора + for (int i = 0; i < Count; i++) + { + if (_collection[i] == null) + { + _collection[i] = obj; + return i; + } + } + + return -1; + } + + public int Insert(T obj, int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return -1; + } + + // проверка, что элемент массива по этой позиции пустой, если нет, то + // ищется свободное место после этой позиции и идет вставка туда + // если нет после, ищем до + if (_collection[position] != null) + { + bool pushed = false; + for (int index = position + 1; index < Count; index++) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + + if (!pushed) + { + for (int index = position - 1; index >= 0; index--) + { + if (_collection[index] == null) + { + position = index; + pushed = true; + break; + } + } + } + + if (!pushed) + { + return position; + } + } + + // вставка + _collection[position] = obj; + return position; + } + + public T? Remove(int position) + { + // проверка позиции + if (position < 0 || position >= Count) + { + return null; + } + + if (_collection[position] == null) return null; + + T? temp = _collection[position]; + _collection[position] = null; + return temp; + } +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs b/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs index df80ecf..fe6dba4 100644 --- a/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs +++ b/ProjectAirBomber/ProjectAirBomber/Drawnings/DirectionType.cs @@ -5,6 +5,9 @@ /// public enum DirectionType { + /// + /// Неизвестное направление + /// Unknow = -1, /// /// Вверх diff --git a/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs index 5d0e8c3..4295c92 100644 --- a/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/Drawnings/DrawningAirBomber.cs @@ -5,6 +5,7 @@ namespace ProjectAirBomber.Drawnings; /// /// Класс, отвечающий за прорисовку и перемещение объекта-сущности /// +/// public class DrawningAirBomber : DrawningBomber { @@ -19,16 +20,12 @@ public class DrawningAirBomber : DrawningBomber /// Признак наличия бомб - - - //TO DO!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + //TO DO!!! public DrawningAirBomber(int speed, double weight, Color bodyColor, Color additionalColor, bool fuelTanks, bool bombs) : base(200, 160) { EntityBomber = new EntityAirBomber(speed, weight, bodyColor, additionalColor, fuelTanks, bombs); } - - public override void DrawTransport(Graphics g) { if (EntityBomber == null || EntityBomber is not EntityAirBomber airBomber || !_startPosX.HasValue || !_startPosY.HasValue) @@ -63,13 +60,10 @@ public class DrawningAirBomber : DrawningBomber new Point(_startPosX.Value + 80, _startPosY.Value + 100) }); } - _startPosX += 10; _startPosY += 5; base.DrawTransport(g); _startPosX -= 10; _startPosY -= 5; - - } } \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs b/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs index 7d24cca..33745d2 100644 --- a/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/Entities/EntityBomber.cs @@ -30,7 +30,7 @@ public class EntityBomber /// Вес бомбардировщика /// Основной цвет /// - /// TO DO?!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + /// TO DO public EntityBomber(int speed, double weight, Color bodyColor) { Speed = speed; diff --git a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs index 815856a..3f82e9d 100644 --- a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs +++ b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.Designer.cs @@ -33,43 +33,30 @@ namespace ProjectAirBomber private void InitializeComponent() { pictureBoxAirBomber = new PictureBox(); - buttonCreateAirBomber = new Button(); buttonLeft = new Button(); buttonUp = new Button(); buttonDown = new Button(); buttonRight = new Button(); - buttonCreateCar = new Button(); comboBoxStrategy = new ComboBox(); buttonStrategyStep = new Button(); ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).BeginInit(); SuspendLayout(); // - // pictureBoxElectroTrans + // pictureBoxAirBomber // pictureBoxAirBomber.Dock = DockStyle.Fill; pictureBoxAirBomber.Location = new Point(0, 0); - pictureBoxAirBomber.Name = "pictureBoxElectroTrans"; - pictureBoxAirBomber.Size = new Size(923, 597); + pictureBoxAirBomber.Name = "pictureBoxAirBomber"; + pictureBoxAirBomber.Size = new Size(920, 597); pictureBoxAirBomber.TabIndex = 0; pictureBoxAirBomber.TabStop = false; // - // buttonCreateElectroTrans - // - buttonCreateAirBomber.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateAirBomber.Location = new Point(12, 562); - buttonCreateAirBomber.Name = "buttonCreateAirBomber"; - buttonCreateAirBomber.Size = new Size(223, 23); - buttonCreateAirBomber.TabIndex = 1; - buttonCreateAirBomber.Text = "Создать бомбардировщик"; - buttonCreateAirBomber.UseVisualStyleBackColor = true; - buttonCreateAirBomber.Click += ButtonCreateAirBomber_Click; - // // buttonLeft // buttonLeft.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonLeft.BackgroundImage = Properties.Resources.arrowLeft; buttonLeft.BackgroundImageLayout = ImageLayout.Stretch; - buttonLeft.Location = new Point(787, 550); + buttonLeft.Location = new Point(784, 550); buttonLeft.Name = "buttonLeft"; buttonLeft.Size = new Size(35, 35); buttonLeft.TabIndex = 2; @@ -81,7 +68,7 @@ namespace ProjectAirBomber buttonUp.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonUp.BackgroundImage = Properties.Resources.arrowUp; buttonUp.BackgroundImageLayout = ImageLayout.Stretch; - buttonUp.Location = new Point(828, 509); + buttonUp.Location = new Point(825, 509); buttonUp.Name = "buttonUp"; buttonUp.Size = new Size(35, 35); buttonUp.TabIndex = 3; @@ -93,7 +80,7 @@ namespace ProjectAirBomber buttonDown.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonDown.BackgroundImage = Properties.Resources.arrowDown; buttonDown.BackgroundImageLayout = ImageLayout.Stretch; - buttonDown.Location = new Point(828, 550); + buttonDown.Location = new Point(825, 550); buttonDown.Name = "buttonDown"; buttonDown.Size = new Size(35, 35); buttonDown.TabIndex = 4; @@ -105,24 +92,13 @@ namespace ProjectAirBomber buttonRight.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; buttonRight.BackgroundImage = Properties.Resources.arrowRight; buttonRight.BackgroundImageLayout = ImageLayout.Stretch; - buttonRight.Location = new Point(869, 550); + buttonRight.Location = new Point(866, 550); buttonRight.Name = "buttonRight"; buttonRight.Size = new Size(35, 35); buttonRight.TabIndex = 5; buttonRight.UseVisualStyleBackColor = true; buttonRight.Click += ButtonMove_Click; // - // buttonCreateCar - // - buttonCreateCar.Anchor = AnchorStyles.Bottom | AnchorStyles.Left; - buttonCreateCar.Location = new Point(250, 562); - buttonCreateCar.Name = "buttonCreateTrans"; - buttonCreateCar.Size = new Size(223, 23); - buttonCreateCar.TabIndex = 6; - buttonCreateCar.Text = "Создать военный самолет"; - buttonCreateCar.UseVisualStyleBackColor = true; - buttonCreateCar.Click += ButtonCreateBomber_Click; - // // comboBoxStrategy // comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList; @@ -143,21 +119,19 @@ namespace ProjectAirBomber buttonStrategyStep.UseVisualStyleBackColor = true; buttonStrategyStep.Click += ButtonStrategyStep_Click; // - // FormElectroTrans + // FormAirBomber // AutoScaleDimensions = new SizeF(7F, 15F); AutoScaleMode = AutoScaleMode.Font; - ClientSize = new Size(923, 597); + ClientSize = new Size(920, 597); Controls.Add(buttonStrategyStep); Controls.Add(comboBoxStrategy); - Controls.Add(buttonCreateCar); Controls.Add(buttonRight); Controls.Add(buttonDown); Controls.Add(buttonUp); Controls.Add(buttonLeft); - Controls.Add(buttonCreateAirBomber); Controls.Add(pictureBoxAirBomber); - Name = "FormElectroTrans"; + Name = "FormAirBomber"; Text = "Электропоезд"; ((System.ComponentModel.ISupportInitialize)pictureBoxAirBomber).EndInit(); ResumeLayout(false); @@ -166,12 +140,10 @@ namespace ProjectAirBomber #endregion private PictureBox pictureBoxAirBomber; - private Button buttonCreateAirBomber; private Button buttonLeft; private Button buttonUp; private Button buttonDown; private Button buttonRight; - private Button buttonCreateCar; private ComboBox comboBoxStrategy; private Button buttonStrategyStep; } diff --git a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs index bcdbd7b..8c94774 100644 --- a/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs +++ b/ProjectAirBomber/ProjectAirBomber/FormAirBomber.cs @@ -2,19 +2,39 @@ using ProjectAirBomber.MovementStrategy; namespace ProjectAirBomber; - +/// +/// Форма работы с объектом "Бомбардировщик" +/// public partial class FormAirBomber : Form { /// - /// Ïîëå-îáúåêò äëÿ ïðîðèñîâêè îáúåêòà + /// Поле-объект для прорисовки объекта /// - private DrawningBomber? _drawingBomber; + private DrawningBomber? _drawningBomber; /// - /// Ñòðàòåãèÿ ïåðåìåùåíèÿ + /// Стратегия перемещения /// private AbstractStrategy? _strategy; + /// + /// Получение объекта + /// + public DrawningBomber SetBomber + { + set + { + _drawningBomber = value; + _drawningBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + comboBoxStrategy.Enabled = true; + _strategy = null; + Draw(); + } + } + + /// + /// Конструктор формы + /// public FormAirBomber() { InitializeComponent(); @@ -22,66 +42,29 @@ public partial class FormAirBomber : Form } /// - /// Ìåòîä ïðîðèñîâêè ìàøèíû + /// Метод прорисовки бомбардировщика /// private void Draw() { - if (_drawingBomber == null) + if (_drawningBomber == null) { return; } Bitmap bmp = new(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); Graphics gr = Graphics.FromImage(bmp); - _drawingBomber.DrawTransport(gr); + _drawningBomber.DrawTransport(gr); pictureBoxAirBomber.Image = bmp; } - private void CreateObject(string type) - { - Random random = new(); - switch (type) - { - case nameof(DrawningBomber): - _drawingBomber = new DrawningBomber(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(DrawningAirBomber): - _drawingBomber = new DrawningAirBomber(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; - } - _drawingBomber.SetPictureSize(pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); - _drawingBomber.SetPosition(random.Next(10, 100), random.Next(10, 100)); - _strategy = null; - comboBoxStrategy.Enabled = true; - Draw(); - } /// - /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü ñïîðòèâíûé àâòîìîáèëü" + /// Перемещение объекта по форме (нажатие кнопок навигации) /// /// /// - private void ButtonCreateAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber)); - - /// - /// Îáðàáîòêà íàæàòèÿ êíîïêè "Ñîçäàòü àâòîìîáèëü" - /// - /// - /// - private void ButtonCreateBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber)); - /// - /// Ïåðåìåùåíèå îáúåêòà ïî ôîðìå (íàæàòèå êíîïîê íàâèãàöèè) - /// - /// - /// - private void ButtonMove_Click(object sender, EventArgs e) + private void ButtonMove_Click(object sender, EventArgs e) { - if (_drawingBomber == null) + if (_drawningBomber == null) { return; } @@ -91,16 +74,16 @@ public partial class FormAirBomber : Form switch (name) { case "buttonUp": - result = _drawingBomber.MoveTransport(DirectionType.Up); + result = _drawningBomber.MoveTransport(DirectionType.Up); break; case "buttonDown": - result = _drawingBomber.MoveTransport(DirectionType.Down); + result = _drawningBomber.MoveTransport(DirectionType.Down); break; case "buttonLeft": - result = _drawingBomber.MoveTransport(DirectionType.Left); + result = _drawningBomber.MoveTransport(DirectionType.Left); break; case "buttonRight": - result = _drawingBomber.MoveTransport(DirectionType.Right); + result = _drawningBomber.MoveTransport(DirectionType.Right); break; } @@ -110,13 +93,13 @@ public partial class FormAirBomber : Form } } /// - /// Îáðàáîòêà íàæàòèÿ êíîïêè "Øàã" - /// - /// - /// - private void ButtonStrategyStep_Click(object sender, EventArgs e) + /// Обработка нажатия кнопки "Шаг" + /// + /// + /// + private void ButtonStrategyStep_Click(object sender, EventArgs e) { - if (_drawingBomber == null) + if (_drawningBomber == null) { return; } @@ -133,7 +116,7 @@ public partial class FormAirBomber : Form { return; } - _strategy.SetData(new MoveableTrans(_drawingBomber), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); + _strategy.SetData(new MoveableBomber(_drawningBomber), pictureBoxAirBomber.Width, pictureBoxAirBomber.Height); } if (_strategy == null) diff --git a/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.Designer.cs b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.Designer.cs new file mode 100644 index 0000000..f4cbbef --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.Designer.cs @@ -0,0 +1,173 @@ +namespace ProjectAirBomber +{ + partial class FormBomberCollection + { + /// + /// 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(); + buttonRemoveBomber = new Button(); + maskedTextBoxPosition = new MaskedTextBox(); + buttonAddAirBomber = new Button(); + buttonAddBomber = new Button(); + comboBoxSelectorCompany = 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(buttonRemoveBomber); + groupBoxTools.Controls.Add(maskedTextBoxPosition); + groupBoxTools.Controls.Add(buttonAddAirBomber); + groupBoxTools.Controls.Add(buttonAddBomber); + groupBoxTools.Controls.Add(comboBoxSelectorCompany); + groupBoxTools.Dock = DockStyle.Right; + groupBoxTools.Location = new Point(1136, 0); + groupBoxTools.Name = "groupBoxTools"; + groupBoxTools.Size = new Size(268, 835); + groupBoxTools.TabIndex = 0; + groupBoxTools.TabStop = false; + groupBoxTools.Text = "Инструменты"; + // + // buttonRefresh + // + buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRefresh.Location = new Point(20, 567); + buttonRefresh.Name = "buttonRefresh"; + buttonRefresh.Size = new Size(236, 42); + buttonRefresh.TabIndex = 6; + buttonRefresh.Text = "Обновить"; + buttonRefresh.UseVisualStyleBackColor = true; + buttonRefresh.Click += ButtonRefresh_Click; + // + // buttonGoToCheck + // + buttonGoToCheck.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonGoToCheck.Location = new Point(20, 314); + buttonGoToCheck.Name = "buttonGoToCheck"; + buttonGoToCheck.Size = new Size(236, 42); + buttonGoToCheck.TabIndex = 5; + buttonGoToCheck.Text = "Передать на тесты"; + buttonGoToCheck.UseVisualStyleBackColor = true; + buttonGoToCheck.Click += ButtonGoToCheck_Click; + // + // buttonRemoveBomber + // + buttonRemoveBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonRemoveBomber.Location = new Point(20, 255); + buttonRemoveBomber.Name = "buttonRemoveBomber"; + buttonRemoveBomber.Size = new Size(236, 42); + buttonRemoveBomber.TabIndex = 4; + buttonRemoveBomber.Text = "Удалить военный самолёт"; + buttonRemoveBomber.UseVisualStyleBackColor = true; + buttonRemoveBomber.Click += ButtonRemoveBomber_Click; + // + // maskedTextBoxPosition + // + maskedTextBoxPosition.Location = new Point(20, 210); + maskedTextBoxPosition.Mask = "00"; + maskedTextBoxPosition.Name = "maskedTextBoxPosition"; + maskedTextBoxPosition.Size = new Size(236, 23); + maskedTextBoxPosition.TabIndex = 3; + maskedTextBoxPosition.ValidatingType = typeof(int); + // + // buttonAddAirBomber + // + buttonAddAirBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddAirBomber.Location = new Point(20, 149); + buttonAddAirBomber.Name = "buttonAddAirBomber"; + buttonAddAirBomber.Size = new Size(236, 42); + buttonAddAirBomber.TabIndex = 2; + buttonAddAirBomber.Text = "Добавление бомбардировщика"; + buttonAddAirBomber.UseVisualStyleBackColor = true; + buttonAddAirBomber.Click += ButtonAddAirBomber_Click; + // + // buttonAddBomber + // + buttonAddBomber.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right; + buttonAddBomber.Location = new Point(20, 91); + buttonAddBomber.Name = "buttonAddBomber"; + buttonAddBomber.Size = new Size(236, 42); + buttonAddBomber.TabIndex = 1; + buttonAddBomber.Text = "Добавление военного самолёта"; + buttonAddBomber.UseVisualStyleBackColor = true; + buttonAddBomber.Click += ButtonAddBomber_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(20, 22); + comboBoxSelectorCompany.Name = "comboBoxSelectorCompany"; + comboBoxSelectorCompany.Size = new Size(236, 23); + comboBoxSelectorCompany.TabIndex = 0; + comboBoxSelectorCompany.SelectedIndexChanged += ComboBoxSelectorCompany_SelectedIndexChanged; + // + // pictureBox + // + pictureBox.Dock = DockStyle.Fill; + pictureBox.Location = new Point(0, 0); + pictureBox.Name = "pictureBox"; + pictureBox.Size = new Size(1136, 835); + pictureBox.TabIndex = 1; + pictureBox.TabStop = false; + // + // FormBomberCollection + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(1404, 835); + Controls.Add(pictureBox); + Controls.Add(groupBoxTools); + Name = "FormBomberCollection"; + Text = "Коллекция самолетов"; + groupBoxTools.ResumeLayout(false); + groupBoxTools.PerformLayout(); + ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit(); + ResumeLayout(false); + } + + #endregion + + private GroupBox groupBoxTools; + private ComboBox comboBoxSelectorCompany; + private Button buttonAddAirBomber; + private Button buttonAddBomber; + private PictureBox pictureBox; + private Button buttonGoToCheck; + private Button buttonRemoveBomber; + private MaskedTextBox maskedTextBoxPosition; + private Button buttonRefresh; + } +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.cs b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.cs new file mode 100644 index 0000000..bbd61d6 --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.cs @@ -0,0 +1,199 @@ +using ProjectAirBomber.CollectionGenericObjects; +using ProjectAirBomber.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 ProjectAirBomber; + + +/// +/// Форма работы с компанией и ее коллекцией +/// +public partial class FormBomberCollection : Form +{ + /// + /// Компания + /// + private AbstractCompany? _company = null; + + /// + /// Конструктор + /// + public FormBomberCollection() + { + InitializeComponent(); + } + + /// + /// Выбор компании + /// + /// + /// + private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e) + { + switch (comboBoxSelectorCompany.Text) + { + case "Хранилище": + _company = new BomberHungarService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects()); + break; + } + } + + /// + /// Добавление обычного военного самолета + /// + /// + /// + private void ButtonAddBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningBomber)); + + /// + /// Добавление бомбардировщика + /// + /// + /// + private void ButtonAddAirBomber_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAirBomber)); + + /// + /// Создание объекта класса-перемещения + /// + /// Тип создаваемого объекта + private void CreateObject(string type) + { + if (_company == null) + { + return; + } + + Random random = new(); + DrawningBomber drawningBomber; + switch (type) + { + case nameof(DrawningBomber): + drawningBomber = new DrawningBomber(random.Next(100, 300), random.Next(1000, 3000), GetColor(random)); + break; + case nameof(DrawningAirBomber): + // вызов диалогового окна для выбора цвета + drawningBomber = new DrawningAirBomber(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 + drawningBomber != -1) + { + MessageBox.Show("Объект добавлен"); + pictureBox.Image = _company.Show(); + } + else + { + _ = MessageBox.Show(drawningBomber.ToString()); + } + } + + /// + /// Получение цвета + /// + /// Генератор случайных чисел + /// + 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 ButtonRemoveBomber_Click(object sender, EventArgs e) + { + if (string.IsNullOrEmpty(maskedTextBoxPosition.Text) || _company == null) + { + return; + } + + if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) != DialogResult.Yes) + { + return; + } + + int pos = Convert.ToInt32(maskedTextBoxPosition.Text); + if (_company - pos != null) + { + MessageBox.Show("Объект удален"); + pictureBox.Image = _company.Show(); + } + else + { + MessageBox.Show("Не удалось удалить объект"); + } + } + + /// + /// Передача объекта в другую форму + /// + /// + /// + private void ButtonGoToCheck_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + DrawningBomber? bomber = null; + int counter = 100; + while (bomber == null) + { + bomber = _company.GetRandomObject(); + counter--; + if (counter <= 0) + { + break; + } + } + + if (bomber == null) + { + return; + } + + FormAirBomber form = new() + { + SetBomber = bomber + }; + form.ShowDialog(); + } + + /// + /// Перерисовка коллекции + /// + /// + /// + private void ButtonRefresh_Click(object sender, EventArgs e) + { + if (_company == null) + { + return; + } + + pictureBox.Image = _company.Show(); + } +} \ No newline at end of file diff --git a/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.resx b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.resx new file mode 100644 index 0000000..af32865 --- /dev/null +++ b/ProjectAirBomber/ProjectAirBomber/FormBomberCollection.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/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToBorder.cs b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToBorder.cs index d3c61f8..2486041 100644 --- a/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToBorder.cs +++ b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToBorder.cs @@ -1,7 +1,9 @@ using ProjectAirBomber.MovementStrategy; - namespace ProjectAirBomber.MovementStrategy; +/// +/// Стратегия перемещения объекта в край экрана +/// public class MoveToBorder : AbstractStrategy { protected override bool IsTargetDestinaion() @@ -17,6 +19,7 @@ public class MoveToBorder : AbstractStrategy && objParams.ObjectMiddleVertical + GetStep() >= FieldHeight; } + protected override void MoveToTarget() { ObjectParameters? objParams = GetObjectParameters; diff --git a/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToCenter.cs b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToCenter.cs index 6966932..8631220 100644 --- a/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToCenter.cs +++ b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveToCenter.cs @@ -1,6 +1,10 @@  namespace ProjectAirBomber.MovementStrategy; +/// +/// Стратегия перемещения объекта в центр экрана +/// + public class MoveToCenter : AbstractStrategy { protected override bool IsTargetDestinaion() diff --git a/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableTrans.cs b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableBomber.cs similarity index 90% rename from ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableTrans.cs rename to ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableBomber.cs index e3ebfd3..3d3eb0f 100644 --- a/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableTrans.cs +++ b/ProjectAirBomber/ProjectAirBomber/MovementStrategy/MoveableBomber.cs @@ -1,18 +1,18 @@ using ProjectAirBomber.Drawnings; - namespace ProjectAirBomber.MovementStrategy; -public class MoveableTrans : IMoveableObject + +public class MoveableBomber : IMoveableObject { /// - /// Поле-объект класса DrawningTrans или его наследника + /// Поле-объект класса DrawningBomber или его наследника /// private readonly DrawningBomber? _bomber = null; /// /// Конструктор /// /// Объект класса DrawningTrans - public MoveableTrans(DrawningBomber bomber) + public MoveableBomber(DrawningBomber bomber) { _bomber = bomber; } @@ -55,6 +55,4 @@ public class MoveableTrans : IMoveableObject _ => DirectionType.Unknow, }; } - - } diff --git a/ProjectAirBomber/ProjectAirBomber/Program.cs b/ProjectAirBomber/ProjectAirBomber/Program.cs index 7f59104..0a98864 100644 --- a/ProjectAirBomber/ProjectAirBomber/Program.cs +++ b/ProjectAirBomber/ProjectAirBomber/Program.cs @@ -11,7 +11,7 @@ namespace ProjectAirBomber // To customize application configuration such as set high DPI settings or default font, // see https://aka.ms/applicationconfiguration. ApplicationConfiguration.Initialize(); - Application.Run(new FormAirBomber()); + Application.Run(new FormBomberCollection()); } } } \ No newline at end of file