diff --git a/Stormtrooper/Stormtrooper/CollectionGenericObjects/AbstractCompany.cs b/Stormtrooper/Stormtrooper/CollectionGenericObjects/AbstractCompany.cs
new file mode 100644
index 0000000..2d7e417
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/CollectionGenericObjects/AbstractCompany.cs
@@ -0,0 +1,114 @@
+using Stormtrooper.Drawnings;
+
+namespace Stormtrooper.CollectionGenericObjects;
+
+///
+/// Абстракция компании, хранящий коллекцию автомобилей
+///
+public abstract class AbstractCompany
+{
+ ///
+ /// Размер места (ширина)
+ ///
+ protected readonly int _placeSizeWidth = 155;
+
+ ///
+ /// Размер места (высота)
+ ///
+ protected readonly int _placeSizeHeight = 155;
+
+ ///
+ /// Ширина окна
+ ///
+ 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, DrawningAircraft aircraft)
+ {
+ return company._collection.Insert(aircraft);
+ }
+
+ ///
+ /// Перегрузка оператора удаления для класса
+ ///
+ /// Компания
+ /// Номер удаляемого объекта
+ ///
+ public static DrawningAircraft operator -(AbstractCompany company, int position)
+ {
+ return company._collection?.Remove(position);
+ }
+
+ ///
+ /// Получение случайного объекта из коллекции
+ ///
+ ///
+ public DrawningAircraft? 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)
+ {
+ DrawningAircraft? obj = _collection?.Get(i);
+ obj?.DrawTransport(graphics);
+ }
+ return bitmap;
+ }
+ ///
+ /// Вывод заднего фона
+ ///
+ ///
+ protected abstract void DrawBackgound(Graphics g);
+
+ ///
+ /// Расстановка объектов
+ ///
+ protected abstract void SetObjectsPosition();
+}
diff --git a/Stormtrooper/Stormtrooper/CollectionGenericObjects/AircraftHangarService.cs b/Stormtrooper/Stormtrooper/CollectionGenericObjects/AircraftHangarService.cs
new file mode 100644
index 0000000..63282a7
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/CollectionGenericObjects/AircraftHangarService.cs
@@ -0,0 +1,65 @@
+using Stormtrooper.Drawnings;
+
+namespace Stormtrooper.CollectionGenericObjects
+{
+ ///
+ /// Реализация абстрактной компании - каршеринг
+ ///
+ public class AircraftHangarService : AbstractCompany
+ {
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public AircraftHangarService(int picWidth, int picHeight,
+ ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+ protected override void DrawBackgound(Graphics g)
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+ Pen pen = new(Color.Black, 2);
+ for (int i = 0; i < width + 1; i++)
+ {
+ for (int j = 0; j < height + 1; ++j)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8 , j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight, i * _placeSizeWidth - _placeSizeWidth + 8, j * _placeSizeHeight - _placeSizeHeight);
+ }
+ }
+ }
+ protected override void SetObjectsPosition()
+ {
+ int width = _pictureWidth / _placeSizeWidth;
+ int height = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = width - 1;
+ int curHeight = 0;
+
+ 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 + 10, curHeight * _placeSizeHeight + 10);
+ }
+
+ if (curWidth > 0)
+ curWidth--;
+ else
+ {
+ curWidth = width - 1;
+ curHeight ++;
+ }
+
+ if (curHeight >= height)
+ {
+ return;
+ }
+ }
+ }
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs b/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
index 2a661c3..62e4526 100644
--- a/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/Stormtrooper/Stormtrooper/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -83,8 +83,8 @@ where T : class
{
if (position >= _collection.Length || position < 0)
{ return null; }
- T drawningCruiser = _collection[position];
+ T DrawningAircraft = _collection[position];
_collection[position] = null;
- return drawningCruiser;
+ return DrawningAircraft;
}
}
diff --git a/Stormtrooper/Stormtrooper/FormAircraftCollection.Designer.cs b/Stormtrooper/Stormtrooper/FormAircraftCollection.Designer.cs
new file mode 100644
index 0000000..f11846b
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/FormAircraftCollection.Designer.cs
@@ -0,0 +1,175 @@
+namespace Stormtrooper
+{
+ partial class FormAircraftCollection
+ {
+ ///
+ /// 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();
+ buttonRemoveAircraft = new Button();
+ maskedTextBox = new MaskedTextBox();
+ buttonAddStormtrooper = new Button();
+ buttonAddAiracft = 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(buttonRemoveAircraft);
+ groupBoxTools.Controls.Add(maskedTextBox);
+ groupBoxTools.Controls.Add(buttonAddStormtrooper);
+ groupBoxTools.Controls.Add(buttonAddAiracft);
+ groupBoxTools.Controls.Add(comboBoxSelectorCompany);
+ groupBoxTools.Dock = DockStyle.Right;
+ groupBoxTools.Location = new Point(980, 0);
+ groupBoxTools.Name = "groupBoxTools";
+ groupBoxTools.Size = new Size(264, 677);
+ groupBoxTools.TabIndex = 0;
+ groupBoxTools.TabStop = false;
+ groupBoxTools.Tag = "";
+ groupBoxTools.Text = "Инструменты";
+ //
+ // buttonRefresh
+ //
+ buttonRefresh.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRefresh.Location = new Point(6, 601);
+ buttonRefresh.Name = "buttonRefresh";
+ buttonRefresh.Size = new Size(252, 41);
+ 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(6, 493);
+ buttonGoToCheck.Name = "buttonGoToCheck";
+ buttonGoToCheck.Size = new Size(252, 41);
+ buttonGoToCheck.TabIndex = 5;
+ buttonGoToCheck.Text = "Передать на тесты";
+ buttonGoToCheck.UseVisualStyleBackColor = true;
+ buttonGoToCheck.Click += ButtonGoToCheck_Click;
+ //
+ // buttonRemoveAircraft
+ //
+ buttonRemoveAircraft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonRemoveAircraft.Location = new Point(6, 323);
+ buttonRemoveAircraft.Name = "buttonRemoveAircraft";
+ buttonRemoveAircraft.Size = new Size(252, 41);
+ buttonRemoveAircraft.TabIndex = 4;
+ buttonRemoveAircraft.Text = "Удалить самолет";
+ buttonRemoveAircraft.UseVisualStyleBackColor = true;
+ buttonRemoveAircraft.Click += ButtonRemoveAircraft_Click;
+ //
+ // maskedTextBox
+ //
+ maskedTextBox.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ maskedTextBox.Location = new Point(6, 274);
+ maskedTextBox.Mask = "00";
+ maskedTextBox.Name = "maskedTextBox";
+ maskedTextBox.Size = new Size(252, 27);
+ maskedTextBox.TabIndex = 3;
+ maskedTextBox.ValidatingType = typeof(int);
+ //
+ // buttonAddStormtrooper
+ //
+ buttonAddStormtrooper.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddStormtrooper.Location = new Point(6, 172);
+ buttonAddStormtrooper.Name = "buttonAddStormtrooper";
+ buttonAddStormtrooper.Size = new Size(252, 41);
+ buttonAddStormtrooper.TabIndex = 2;
+ buttonAddStormtrooper.Text = "Добавление штурмовика";
+ buttonAddStormtrooper.UseVisualStyleBackColor = true;
+ buttonAddStormtrooper.Click += ButtonAddStormtrooper_Click;
+ //
+ // buttonAddAiracft
+ //
+ buttonAddAiracft.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
+ buttonAddAiracft.Location = new Point(6, 116);
+ buttonAddAiracft.Name = "buttonAddAiracft";
+ buttonAddAiracft.Size = new Size(252, 41);
+ buttonAddAiracft.TabIndex = 1;
+ buttonAddAiracft.Text = "Добавление самолета";
+ buttonAddAiracft.UseVisualStyleBackColor = true;
+ buttonAddAiracft.Click += ButtonAddAircraft_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(6, 26);
+ comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
+ comboBoxSelectorCompany.Size = new Size(252, 28);
+ 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(980, 677);
+ pictureBox.TabIndex = 1;
+ pictureBox.TabStop = false;
+ //
+ // FormAircraftCollection
+ //
+ AutoScaleDimensions = new SizeF(8F, 20F);
+ AutoScaleMode = AutoScaleMode.Font;
+ ClientSize = new Size(1244, 677);
+ Controls.Add(pictureBox);
+ Controls.Add(groupBoxTools);
+ Name = "FormAircraftCollection";
+ Text = "Коллекция самолетов";
+ groupBoxTools.ResumeLayout(false);
+ groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)pictureBox).EndInit();
+ ResumeLayout(false);
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private ComboBox comboBoxSelectorCompany;
+ private Button buttonAddStormtrooper;
+ private Button buttonAddAiracft;
+ private Button buttonRemoveAircraft;
+ private MaskedTextBox maskedTextBox;
+ private PictureBox pictureBox;
+ private Button buttonRefresh;
+ private Button buttonGoToCheck;
+ }
+}
\ No newline at end of file
diff --git a/Stormtrooper/Stormtrooper/FormAircraftCollection.cs b/Stormtrooper/Stormtrooper/FormAircraftCollection.cs
new file mode 100644
index 0000000..796c0d6
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/FormAircraftCollection.cs
@@ -0,0 +1,164 @@
+using Stormtrooper.CollectionGenericObjects;
+using Stormtrooper.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 Stormtrooper;
+
+public partial class FormAircraftCollection : Form
+{
+ ///
+ /// Компания
+ ///
+ private AbstractCompany? _company = null;
+ ///
+ /// Конструктор
+ ///
+ public FormAircraftCollection()
+ {
+ InitializeComponent();
+ }
+
+ private void ComboBoxSelectorCompany_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ switch (comboBoxSelectorCompany.Text)
+ {
+ case "Хранилище":
+ _company = new AircraftHangarService(pictureBox.Width,
+ pictureBox.Height, new MassiveGenericObjects());
+ break;
+ }
+ }
+
+ ///
+ /// Создание объекта класса-перемещения
+ ///
+ /// Тип создаваемого объекта
+ private void CreateObject(string type)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+ Random random = new();
+ DrawningAircraft drawningAircraft;
+ switch (type)
+ {
+ case nameof(DrawningAircraft):
+ drawningAircraft = new DrawningAircraft(random.Next(100, 300), random.Next(1000, 3000), GetColor(random));
+ break;
+ case nameof(DrawningStormtrooper):
+ drawningAircraft = new DrawningStormtrooper(random.Next(100, 300), random.Next(1000, 3000),
+ GetColor(random),GetColor(random),Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)), Convert.ToBoolean(random.Next(0, 2)));
+ break;
+ default:
+ return;
+ }
+ if (_company + drawningAircraft != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+
+ ///
+ /// Получение цвета
+ ///
+ /// Генератор случайных чисел
+ ///
+ 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 ButtonAddAircraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAicraft));
+ //private void ButtonStormtrooper_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
+ private void ButtonAddAircraft_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningAircraft));
+ }
+
+ private void ButtonAddStormtrooper_Click(object sender, EventArgs e)
+ {
+ CreateObject(nameof(DrawningStormtrooper));
+ }
+
+ private void ButtonRemoveAircraft_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("Объект удален!");
+ pictureBox.Image = _company.Show();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+
+ private void ButtonGoToCheck_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ DrawningAircraft? aircraft = null;
+ int counter = 100;
+ while (aircraft == null)
+ {
+ aircraft = _company.GetRandomObject();
+ counter--;
+ if (counter <= 0)
+ {
+ break;
+ }
+ }
+ if (aircraft == null)
+ {
+ return;
+ }
+ FormStormtrooper form = new()
+ {
+ SetAircraft = aircraft
+ };
+ form.ShowDialog();
+ }
+
+ private void ButtonRefresh_Click(object sender, EventArgs e)
+ {
+ if (_company == null)
+ {
+ return;
+ }
+
+ pictureBox.Image = _company.Show();
+ }
+}
diff --git a/Stormtrooper/Stormtrooper/FormAircraftCollection.resx b/Stormtrooper/Stormtrooper/FormAircraftCollection.resx
new file mode 100644
index 0000000..af32865
--- /dev/null
+++ b/Stormtrooper/Stormtrooper/FormAircraftCollection.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/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
index 3be5a11..8cb1780 100644
--- a/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
+++ b/Stormtrooper/Stormtrooper/FormStormtrooper.Designer.cs
@@ -29,12 +29,10 @@
private void InitializeComponent()
{
pictureBoxStormtrooper = new PictureBox();
- buttonCreate = new Button();
buttonUp = new Button();
buttonDown = new Button();
buttonLeft = new Button();
buttonRight = new Button();
- buttonCreateAircraft = new Button();
comboBoxStrategy = new ComboBox();
buttonStrategyStep = new Button();
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).BeginInit();
@@ -48,18 +46,7 @@
pictureBoxStormtrooper.Size = new Size(773, 439);
pictureBoxStormtrooper.TabIndex = 0;
pictureBoxStormtrooper.TabStop = false;
- pictureBoxStormtrooper.Click += pictureBoxStormtrooper_Click;
- //
- // buttonCreate
- //
- buttonCreate.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreate.Location = new Point(12, 395);
- buttonCreate.Name = "buttonCreate";
- buttonCreate.Size = new Size(205, 32);
- buttonCreate.TabIndex = 1;
- buttonCreate.Text = "Создать штурмовик";
- buttonCreate.UseVisualStyleBackColor = true;
- buttonCreate.Click += ButtonCreate_Click;
+
//
// buttonUp
//
@@ -109,17 +96,6 @@
buttonRight.UseVisualStyleBackColor = true;
buttonRight.Click += ButtonMove_Click;
//
- // buttonCreateAircraft
- //
- buttonCreateAircraft.Anchor = AnchorStyles.Bottom | AnchorStyles.Left;
- buttonCreateAircraft.Location = new Point(239, 395);
- buttonCreateAircraft.Name = "buttonCreateAircraft";
- buttonCreateAircraft.Size = new Size(205, 32);
- buttonCreateAircraft.TabIndex = 7;
- buttonCreateAircraft.Text = "Создать самолет";
- buttonCreateAircraft.UseVisualStyleBackColor = true;
- buttonCreateAircraft.Click += buttonCreateAircraft_Click;
- //
// comboBoxStrategy
//
comboBoxStrategy.DropDownStyle = ComboBoxStyle.DropDownList;
@@ -129,7 +105,6 @@
comboBoxStrategy.Name = "comboBoxStrategy";
comboBoxStrategy.Size = new Size(151, 28);
comboBoxStrategy.TabIndex = 8;
- comboBoxStrategy.SelectedIndexChanged += comboBox1_SelectedIndexChanged;
//
// buttonStrategyStep
//
@@ -148,16 +123,13 @@
ClientSize = new Size(773, 439);
Controls.Add(buttonStrategyStep);
Controls.Add(comboBoxStrategy);
- Controls.Add(buttonCreateAircraft);
Controls.Add(buttonRight);
Controls.Add(buttonLeft);
Controls.Add(buttonDown);
Controls.Add(buttonUp);
- Controls.Add(buttonCreate);
Controls.Add(pictureBoxStormtrooper);
Name = "FormStormtrooper";
Text = "Штурмовик";
- Load += FormStormtrooper_Load;
Click += ButtonMove_Click;
((System.ComponentModel.ISupportInitialize)pictureBoxStormtrooper).EndInit();
ResumeLayout(false);
@@ -166,12 +138,10 @@
#endregion
private PictureBox pictureBoxStormtrooper;
- private Button buttonCreate;
private Button buttonUp;
private Button buttonDown;
private Button buttonLeft;
private Button buttonRight;
- private Button buttonCreateAircraft;
private ComboBox comboBoxStrategy;
private Button buttonStrategyStep;
}
diff --git a/Stormtrooper/Stormtrooper/FormStormtrooper.cs b/Stormtrooper/Stormtrooper/FormStormtrooper.cs
index 236594e..e6dfb8d 100644
--- a/Stormtrooper/Stormtrooper/FormStormtrooper.cs
+++ b/Stormtrooper/Stormtrooper/FormStormtrooper.cs
@@ -21,7 +21,18 @@ public partial class FormStormtrooper : Form
// Стратегия перемещения
private AbstractStrategy? _strategy;
-
+ public DrawningAircraft SetAircraft
+ {
+ set
+ {
+ _drawningAircraft = value;
+ _drawningAircraft.SetPictureSize(pictureBoxStormtrooper.Width,
+ pictureBoxStormtrooper.Height);
+ comboBoxStrategy.Enabled = true;
+ _strategy = null;
+ Draw();
+ }
+ }
// Конструктор формы
public FormStormtrooper()
{
@@ -29,46 +40,6 @@ public partial class FormStormtrooper : Form
_strategy = null;
}
- // Метод прорисовки машины
- private void FormStormtrooper_Load(object sender, EventArgs e)
- {
-
- }
- ///
- /// Создание объекта класса-перемещения
- ///
- /// Тип создаваемого объекта
- private void CreateObject(string type)
- {
- Random random = new();
- switch (type)
- {
- case nameof(DrawningAircraft):
- _drawningAircraft = new DrawningAircraft(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(DrawningStormtrooper):
- _drawningAircraft = new DrawningStormtrooper(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)), Convert.ToBoolean(random.Next(0, 2)));
- break;
- default:
- return;
- }
- _drawningAircraft.SetPictureSize(pictureBoxStormtrooper.Width,
- pictureBoxStormtrooper.Height);
- _drawningAircraft.SetPosition(random.Next(10, 100), random.Next(10, 100));
- _strategy = null;
-
- Draw();
- }
-
- // Обработка нажатия кнопки Создать штурмовик
- private void ButtonCreate_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningStormtrooper));
- // Обработка нажатия кнопки Создать самолет
- private void buttonCreateAircraft_Click(object sender, EventArgs e) => CreateObject(nameof(DrawningAircraft));
// Прорисовка
private void Draw()
{
@@ -113,15 +84,6 @@ public partial class FormStormtrooper : Form
}
}
- private void pictureBoxStormtrooper_Click(object sender, EventArgs e)
- {
-
- }
-
- private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
- {
-
- }
private void buttonStrategyStep_Click(object sender, EventArgs e)
{
if (_drawningAircraft == null)
diff --git a/Stormtrooper/Stormtrooper/MovementStrategy/MoveableAircraft.cs b/Stormtrooper/Stormtrooper/MovementStrategy/MoveableAircraft.cs
index 0ec0904..527b1b1 100644
--- a/Stormtrooper/Stormtrooper/MovementStrategy/MoveableAircraft.cs
+++ b/Stormtrooper/Stormtrooper/MovementStrategy/MoveableAircraft.cs
@@ -11,36 +11,36 @@ public class MoveableAircraft : IMoveableObject
///
/// Поле-объект класса DrawningAircraft или его наследника
///
- private readonly DrawningAircraft? _cruiser = null;
+ private readonly DrawningAircraft? _aircraft = null;
///
/// Конструктор
///
- /// Объект класса DrawningAircraft
- public MoveableAircraft(DrawningAircraft cruiser)
+ /// Объект класса DrawningAircraft
+ public MoveableAircraft(DrawningAircraft aircraft)
{
- _cruiser = cruiser;
+ _aircraft = aircraft;
}
public ObjectParameters? GetObjectPosition
{
get
{
- if (_cruiser == null || _cruiser.EntityAircraft == null ||
- !_cruiser.GetPosX.HasValue || !_cruiser.GetPosY.HasValue)
+ if (_aircraft == null || _aircraft.EntityAircraft == null ||
+ !_aircraft.GetPosX.HasValue || !_aircraft.GetPosY.HasValue)
{
return null;
}
- return new ObjectParameters(_cruiser.GetPosX.Value,
- _cruiser.GetPosY.Value, _cruiser.GetWidth, _cruiser.GetHeight);
+ return new ObjectParameters(_aircraft.GetPosX.Value,
+ _aircraft.GetPosY.Value, _aircraft.GetWidth, _aircraft.GetHeight);
}
}
- public int GetStep => (int)(_cruiser?.EntityAircraft?.Step ?? 0);
+ public int GetStep => (int)(_aircraft?.EntityAircraft?.Step ?? 0);
public bool TryMoveObject(MovementDirection direction)
{
- if (_cruiser == null || _cruiser.EntityAircraft == null)
+ if (_aircraft == null || _aircraft.EntityAircraft == null)
{
return false;
}
- return _cruiser.MoveTransport(GetDirectionType(direction));
+ return _aircraft.MoveTransport(GetDirectionType(direction));
}
///
/// Конвертация из MovementDirection в DirectionType
diff --git a/Stormtrooper/Stormtrooper/Program.cs b/Stormtrooper/Stormtrooper/Program.cs
index f56f0d8..8d32d67 100644
--- a/Stormtrooper/Stormtrooper/Program.cs
+++ b/Stormtrooper/Stormtrooper/Program.cs
@@ -11,7 +11,7 @@ namespace Stormtrooper
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormStormtrooper());
+ Application.Run(new FormAircraftCollection());
}
}
}
\ No newline at end of file