diff --git a/WarPlanes/WarPlanes/Direction.cs b/WarPlanes/WarPlanes/Direction.cs
index b0777d9..a43a18c 100644
--- a/WarPlanes/WarPlanes/Direction.cs
+++ b/WarPlanes/WarPlanes/Direction.cs
@@ -3,7 +3,7 @@
///
/// Направление перемещения
///
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/WarPlanes/WarPlanes/DrawningWarPlane.cs b/WarPlanes/WarPlanes/DrawningWarPlane.cs
index 3017cca..d05e9c4 100644
--- a/WarPlanes/WarPlanes/DrawningWarPlane.cs
+++ b/WarPlanes/WarPlanes/DrawningWarPlane.cs
@@ -3,7 +3,7 @@
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- internal class DrawningWarPlane
+ public class DrawningWarPlane
{
///
/// Класс-сущность
diff --git a/WarPlanes/WarPlanes/EntityWarPlane.cs b/WarPlanes/WarPlanes/EntityWarPlane.cs
index f9823b0..941dc1a 100644
--- a/WarPlanes/WarPlanes/EntityWarPlane.cs
+++ b/WarPlanes/WarPlanes/EntityWarPlane.cs
@@ -3,7 +3,7 @@
///
/// Класс-сущность "Военный самолёт"
///
- internal class EntityWarPlane
+ public class EntityWarPlane
{
///
/// Скорость
diff --git a/WarPlanes/WarPlanes/FormMap.Designer.cs b/WarPlanes/WarPlanes/FormMap.Designer.cs
deleted file mode 100644
index a2c54c1..0000000
--- a/WarPlanes/WarPlanes/FormMap.Designer.cs
+++ /dev/null
@@ -1,207 +0,0 @@
-namespace AirFighter
-{
- partial class FormMap
- {
- ///
- /// 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()
- {
- this.pictureBoxWarPlane = new System.Windows.Forms.PictureBox();
- this.statusStrip = new System.Windows.Forms.StatusStrip();
- this.toolStripStatusLabelSpeed = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
- this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
- this.buttonCreate = new System.Windows.Forms.Button();
- this.buttonUp = new System.Windows.Forms.Button();
- this.buttonLeft = new System.Windows.Forms.Button();
- this.buttonRight = new System.Windows.Forms.Button();
- this.buttonDown = new System.Windows.Forms.Button();
- this.buttonCreateModif = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
- this.statusStrip.SuspendLayout();
- this.SuspendLayout();
- //
- // pictureBoxWarPlane
- //
- this.pictureBoxWarPlane.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBoxWarPlane.Location = new System.Drawing.Point(0, 0);
- this.pictureBoxWarPlane.Name = "pictureBoxWarPlane";
- this.pictureBoxWarPlane.Size = new System.Drawing.Size(800, 428);
- this.pictureBoxWarPlane.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
- this.pictureBoxWarPlane.TabIndex = 0;
- this.pictureBoxWarPlane.TabStop = false;
- //
- // statusStrip
- //
- this.statusStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
- this.toolStripStatusLabelSpeed,
- this.toolStripStatusLabelWeight,
- this.toolStripStatusLabelBodyColor});
- this.statusStrip.Location = new System.Drawing.Point(0, 428);
- this.statusStrip.Name = "statusStrip";
- this.statusStrip.Size = new System.Drawing.Size(800, 22);
- this.statusStrip.TabIndex = 1;
- //
- // toolStripStatusLabelSpeed
- //
- this.toolStripStatusLabelSpeed.Name = "toolStripStatusLabelSpeed";
- this.toolStripStatusLabelSpeed.Size = new System.Drawing.Size(62, 17);
- this.toolStripStatusLabelSpeed.Text = "Скорость:";
- //
- // toolStripStatusLabelWeight
- //
- this.toolStripStatusLabelWeight.Name = "toolStripStatusLabelWeight";
- this.toolStripStatusLabelWeight.Size = new System.Drawing.Size(29, 17);
- this.toolStripStatusLabelWeight.Text = "Вес:";
- //
- // toolStripStatusLabelBodyColor
- //
- this.toolStripStatusLabelBodyColor.Name = "toolStripStatusLabelBodyColor";
- this.toolStripStatusLabelBodyColor.Size = new System.Drawing.Size(36, 17);
- this.toolStripStatusLabelBodyColor.Text = "Цвет:";
- //
- // buttonCreate
- //
- this.buttonCreate.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreate.Location = new System.Drawing.Point(12, 390);
- this.buttonCreate.Name = "buttonCreate";
- this.buttonCreate.Size = new System.Drawing.Size(75, 23);
- this.buttonCreate.TabIndex = 2;
- this.buttonCreate.Text = "Создать";
- this.buttonCreate.UseVisualStyleBackColor = true;
- this.buttonCreate.Click += new System.EventHandler(this.ButtonCreate_Click);
- //
- // buttonUp
- //
- this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.arrowUp;
- this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(722, 350);
- this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(30, 30);
- this.buttonUp.TabIndex = 3;
- this.buttonUp.UseVisualStyleBackColor = true;
- this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonLeft
- //
- this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.arrowLeft;
- this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(686, 386);
- this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(30, 30);
- this.buttonLeft.TabIndex = 4;
- this.buttonLeft.UseVisualStyleBackColor = true;
- this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonRight
- //
- this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.arrowRight;
- this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(758, 386);
- this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(30, 30);
- this.buttonRight.TabIndex = 5;
- this.buttonRight.UseVisualStyleBackColor = true;
- this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonDown
- //
- this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
- this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.arrowDown;
- this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(722, 386);
- this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(30, 30);
- this.buttonDown.TabIndex = 6;
- this.buttonDown.UseVisualStyleBackColor = true;
- this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
- //
- // buttonCreateModif
- //
- this.buttonCreateModif.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
- this.buttonCreateModif.Location = new System.Drawing.Point(104, 390);
- this.buttonCreateModif.Name = "buttonCreateModif";
- this.buttonCreateModif.Size = new System.Drawing.Size(110, 23);
- this.buttonCreateModif.TabIndex = 7;
- this.buttonCreateModif.Text = "Модификация";
- this.buttonCreateModif.UseVisualStyleBackColor = true;
- this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
- //
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта", "Закрытая карта"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(12, 12);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(121, 23);
- this.comboBoxSelectorMap.TabIndex = 8;
- this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
- //
- // FormMap
- //
- this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
- this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(800, 450);
- this.Controls.Add(this.comboBoxSelectorMap);
- this.Controls.Add(this.buttonCreateModif);
- this.Controls.Add(this.buttonDown);
- this.Controls.Add(this.buttonRight);
- this.Controls.Add(this.buttonLeft);
- this.Controls.Add(this.buttonUp);
- this.Controls.Add(this.buttonCreate);
- this.Controls.Add(this.pictureBoxWarPlane);
- this.Controls.Add(this.statusStrip);
- this.Name = "FormMap";
- this.Text = "Карта";
- ((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).EndInit();
- this.statusStrip.ResumeLayout(false);
- this.statusStrip.PerformLayout();
- this.ResumeLayout(false);
- this.PerformLayout();
-
- }
-
- #endregion
-
- private PictureBox pictureBoxWarPlane;
- private StatusStrip statusStrip;
- private ToolStripStatusLabel toolStripStatusLabelSpeed;
- private ToolStripStatusLabel toolStripStatusLabelWeight;
- private ToolStripStatusLabel toolStripStatusLabelBodyColor;
- private Button buttonCreate;
- private Button buttonUp;
- private Button buttonLeft;
- private Button buttonRight;
- private Button buttonDown;
- private Button buttonCreateModif;
- private ComboBox comboBoxSelectorMap;
- }
-}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormMap.cs b/WarPlanes/WarPlanes/FormMap.cs
deleted file mode 100644
index 758f8b6..0000000
--- a/WarPlanes/WarPlanes/FormMap.cs
+++ /dev/null
@@ -1,93 +0,0 @@
-namespace AirFighter
-{
- public partial class FormMap : Form
- {
- private AbstractMap _abstractMap;
-
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
- }
- ///
- /// Заполнение информации по объекту
- ///
- ///
- private void SetData(DrawningWarPlane warplane)
- {
- toolStripStatusLabelSpeed.Text = $"Скорость: {warplane.WarPlane.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {warplane.WarPlane.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет: {warplane.WarPlane.BodyColor.Name}";
- pictureBoxWarPlane.Image = _abstractMap.CreateMap(pictureBoxWarPlane.Width, pictureBoxWarPlane.Height, new DrawningObjectWarPlane(warplane));
- }
- ///
- /// Обработка нажатия кнопки "Создать"
- ///
- ///
- ///
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- SetData(warplane);
- }
- ///
- /// Изменение размеров формы
- ///
- ///
- ///
- private void ButtonMove_Click(object sender, EventArgs e)
- {
- //получаем имя кнопки
- string name = ((Button)sender)?.Name ?? string.Empty;
- Direction dir = Direction.None;
- switch (name)
- {
- case "buttonUp":
- dir = Direction.Up;
- break;
- case "buttonDown":
- dir = Direction.Down;
- break;
- case "buttonLeft":
- dir = Direction.Left;
- break;
- case "buttonRight":
- dir = Direction.Right;
- break;
- }
- pictureBoxWarPlane.Image = _abstractMap?.MoveObject(dir);
- }
- ///
- /// Обработка нажатия кнопки "Модификация"
- ///
- ///
- ///
- private void ButtonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var fighter = new DrawningFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
- SetData(fighter);
- }
- ///
- /// Смена карты
- ///
- ///
- ///
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- _abstractMap = new SimpleMap();
- break;
- case "Закрытая карта":
- _abstractMap = new CloseMap();
- break;
- }
- }
- }
-}
diff --git a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
new file mode 100644
index 0000000..888b39e
--- /dev/null
+++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.Designer.cs
@@ -0,0 +1,217 @@
+namespace AirFighter
+{
+ partial class FormMapWithSetWarPlanes
+ {
+ ///
+ /// 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()
+ {
+ this.groupBoxTools = new System.Windows.Forms.GroupBox();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonRemoveWarPlane = new System.Windows.Forms.Button();
+ this.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonDown = new System.Windows.Forms.Button();
+ this.buttonRight = new System.Windows.Forms.Button();
+ this.buttonLeft = new System.Windows.Forms.Button();
+ this.buttonUp = new System.Windows.Forms.Button();
+ this.buttonShowOnMap = new System.Windows.Forms.Button();
+ this.buttonAddWarPlane = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBoxTools.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBoxTools
+ //
+ this.groupBoxTools.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBoxTools.Controls.Add(this.buttonRemoveWarPlane);
+ this.groupBoxTools.Controls.Add(this.buttonShowStorage);
+ this.groupBoxTools.Controls.Add(this.buttonDown);
+ this.groupBoxTools.Controls.Add(this.buttonRight);
+ this.groupBoxTools.Controls.Add(this.buttonLeft);
+ this.groupBoxTools.Controls.Add(this.buttonUp);
+ this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
+ this.groupBoxTools.Controls.Add(this.buttonAddWarPlane);
+ this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
+ this.groupBoxTools.Name = "groupBoxTools";
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
+ this.groupBoxTools.TabIndex = 0;
+ this.groupBoxTools.TabStop = false;
+ this.groupBoxTools.Text = "Инструменты";
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
+ this.maskedTextBoxPosition.TabIndex = 2;
+ this.maskedTextBoxPosition.ValidatingType = typeof(int);
+ //
+ // buttonRemoveWarPlane
+ //
+ this.buttonRemoveWarPlane.Location = new System.Drawing.Point(17, 195);
+ this.buttonRemoveWarPlane.Name = "buttonRemoveWarPlane";
+ this.buttonRemoveWarPlane.Size = new System.Drawing.Size(175, 35);
+ this.buttonRemoveWarPlane.TabIndex = 3;
+ this.buttonRemoveWarPlane.Text = "Удалить самолёт";
+ this.buttonRemoveWarPlane.UseVisualStyleBackColor = true;
+ this.buttonRemoveWarPlane.Click += new System.EventHandler(this.ButtonRemoveWarPlane_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
+ this.buttonShowStorage.TabIndex = 4;
+ this.buttonShowStorage.Text = "Посмотреть хранилище";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.arrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(91, 504);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 10;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonRight
+ //
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.arrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(127, 504);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 9;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.arrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(55, 504);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(30, 30);
+ this.buttonLeft.TabIndex = 8;
+ this.buttonLeft.UseVisualStyleBackColor = true;
+ this.buttonLeft.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonUp
+ //
+ this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.arrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(91, 468);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(30, 30);
+ this.buttonUp.TabIndex = 7;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonShowOnMap
+ //
+ this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
+ this.buttonShowOnMap.TabIndex = 5;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonAddWarPlane
+ //
+ this.buttonAddWarPlane.Location = new System.Drawing.Point(17, 106);
+ this.buttonAddWarPlane.Name = "buttonAddWarPlane";
+ this.buttonAddWarPlane.Size = new System.Drawing.Size(175, 35);
+ this.buttonAddWarPlane.TabIndex = 1;
+ this.buttonAddWarPlane.Text = "Добавить самолёт";
+ this.buttonAddWarPlane.UseVisualStyleBackColor = true;
+ this.buttonAddWarPlane.Click += new System.EventHandler(this.ButtonAddWarPlane_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Закрытая карта"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(175, 23);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ this.comboBoxSelectorMap.SelectedIndexChanged += new System.EventHandler(this.ComboBoxSelectorMap_SelectedIndexChanged);
+ //
+ // pictureBox
+ //
+ this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
+ this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(811, 554);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetWarPlanes
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(1015, 554);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBoxTools);
+ this.Name = "FormMapWithSetWarPlanes";
+ this.Text = "Карта с набором объектов";
+ this.groupBoxTools.ResumeLayout(false);
+ this.groupBoxTools.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox groupBoxTools;
+ private PictureBox pictureBox;
+ private ComboBox comboBoxSelectorMap;
+ private Button buttonShowOnMap;
+ private Button buttonAddWarPlane;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonShowStorage;
+ private Button buttonRemoveWarPlane;
+ private MaskedTextBox maskedTextBoxPosition;
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
new file mode 100644
index 0000000..2f2b50f
--- /dev/null
+++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs
@@ -0,0 +1,153 @@
+namespace AirFighter
+{
+ public partial class FormMapWithSetWarPlanes : Form
+ {
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetWarPlanesGeneric _mapWarPlanesCollectionGeneric;
+ ///
+ /// Конструктор
+ ///
+ public FormMapWithSetWarPlanes()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Закрытая карта":
+ map = new CloseMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapWarPlanesCollectionGeneric = new MapWithSetWarPlanesGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapWarPlanesCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddWarPlane_Click(object sender, EventArgs e)
+ {
+ if(_mapWarPlanesCollectionGeneric == null)
+ {
+ return;
+ }
+ FormWarPlane form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawningObjectWarPlane warplane = new(form.SelectedWarPlane);
+ if (form.SelectedWarPlane == null || (_mapWarPlanesCollectionGeneric + warplane) == -1)
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ else
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveWarPlane_Click(object sender, EventArgs e)
+ {
+ if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
+ {
+ return;
+ }
+ if (MessageBox.Show("Удалить объект?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
+ {
+ return;
+ }
+ int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
+ if (_mapWarPlanesCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapWarPlanesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapWarPlanesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapWarPlanesCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapWarPlanesCollectionGeneric == null)
+ {
+ return;
+ }
+ //получаем имя кнопки
+ string name = ((Button)sender)?.Name ?? string.Empty;
+ Direction dir = Direction.None;
+ switch (name)
+ {
+ case "buttonUp":
+ dir = Direction.Up;
+ break;
+ case "buttonDown":
+ dir = Direction.Down;
+ break;
+ case "buttonLeft":
+ dir = Direction.Left;
+ break;
+ case "buttonRight":
+ dir = Direction.Right;
+ break;
+ }
+ pictureBox.Image = _mapWarPlanesCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormMap.resx b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.resx
similarity index 93%
rename from WarPlanes/WarPlanes/FormMap.resx
rename to WarPlanes/WarPlanes/FormMapWithSetWarPlanes.resx
index 2c0949d..f298a7b 100644
--- a/WarPlanes/WarPlanes/FormMap.resx
+++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.resx
@@ -57,7 +57,4 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
-
- 17, 17
-
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormWarPlane.Designer.cs b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
index 1d258b2..89a83cb 100644
--- a/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
+++ b/WarPlanes/WarPlanes/FormWarPlane.Designer.cs
@@ -39,6 +39,7 @@
this.toolStripStatusLabelWeight = new System.Windows.Forms.ToolStripStatusLabel();
this.toolStripStatusLabelBodyColor = new System.Windows.Forms.ToolStripStatusLabel();
this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.buttonSelectCar = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxWarPlane)).BeginInit();
this.statusStrip.SuspendLayout();
this.SuspendLayout();
@@ -152,11 +153,23 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
+ // buttonSelectCar
+ //
+ this.buttonSelectCar.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
+ this.buttonSelectCar.Location = new System.Drawing.Point(569, 390);
+ this.buttonSelectCar.Name = "buttonSelectCar";
+ this.buttonSelectCar.Size = new System.Drawing.Size(75, 23);
+ this.buttonSelectCar.TabIndex = 15;
+ this.buttonSelectCar.Text = "Выбрать";
+ this.buttonSelectCar.UseVisualStyleBackColor = true;
+ this.buttonSelectCar.Click += new System.EventHandler(this.ButtonSelectWarPlane_Click);
+ //
// FormWarPlane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonSelectCar);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonDown);
this.Controls.Add(this.buttonRight);
@@ -188,5 +201,6 @@
private ToolStripStatusLabel toolStripStatusLabelWeight;
private ToolStripStatusLabel toolStripStatusLabelBodyColor;
private Button buttonCreateModif;
+ private Button buttonSelectCar;
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/FormWarPlane.cs b/WarPlanes/WarPlanes/FormWarPlane.cs
index cdfd56f..5e6c347 100644
--- a/WarPlanes/WarPlanes/FormWarPlane.cs
+++ b/WarPlanes/WarPlanes/FormWarPlane.cs
@@ -3,6 +3,10 @@ namespace AirFighter
public partial class FormWarPlane : Form
{
private DrawningWarPlane _warplane;
+ ///
+ ///
+ ///
+ public DrawningWarPlane SelectedWarPlane { get; private set; }
public FormWarPlane()
{
@@ -37,7 +41,13 @@ namespace AirFighter
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ _warplane = new DrawningWarPlane(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
@@ -85,12 +95,29 @@ namespace AirFighter
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
- _warplane = new DrawningFighter(rnd.Next(100, 300), rnd.Next(1000, 2000),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
- Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)),
+ Color color = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialog = new();
+ if (dialog.ShowDialog() == DialogResult.OK)
+ {
+ color = dialog.Color;
+ }
+ Color dopColor = Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256));
+ ColorDialog dialogDop = new();
+ if (dialogDop.ShowDialog() == DialogResult.OK)
+ {
+ dopColor = dialogDop.Color;
+ }
+ _warplane = new DrawningFighter(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
+
SetData();
Draw();
}
+
+ private void ButtonSelectWarPlane_Click(object sender, EventArgs e)
+ {
+ SelectedWarPlane = _warplane;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs b/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
new file mode 100644
index 0000000..687f8d4
--- /dev/null
+++ b/WarPlanes/WarPlanes/MapWithSetWarPlanesGeneric.cs
@@ -0,0 +1,178 @@
+namespace AirFighter
+{
+ ///
+ /// Карта с набром объектов под нее
+ ///
+ ///
+ ///
+ internal class MapWithSetWarPlanesGeneric
+ where T : class, IDrawningObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 210;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 90;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetWarPlanesGeneric _setWarPlanes;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetWarPlanesGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setWarPlanes = new SetWarPlanesGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(MapWithSetWarPlanesGeneric map, T warplane)
+ {
+ return map._setWarPlanes.Insert(warplane);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetWarPlanesGeneric map, int position)
+ {
+ return map._setWarPlanes.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawWarPlanes(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setWarPlanes.Count; i++)
+ {
+ var warplane = _setWarPlanes.Get(i);
+ if (warplane != null)
+ {
+ return _map.CreateMap(_pictureWidth, _pictureHeight, warplane);
+ }
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// Перемещение объекта по крате
+ ///
+ ///
+ ///
+ public Bitmap MoveObject(Direction direction)
+ {
+ if (_map != null)
+ {
+ return _map.MoveObject(direction);
+ }
+ return new(_pictureWidth, _pictureHeight);
+ }
+ ///
+ /// "Взбалтываем" набор, чтобы все элементы оказались в начале
+ ///
+ private void Shaking()
+ {
+ int j = _setWarPlanes.Count - 1;
+ for (int i = 0; i < _setWarPlanes.Count; i++)
+ {
+ if (_setWarPlanes.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var warplane = _setWarPlanes.Get(j);
+ if (warplane != null)
+ {
+ _setWarPlanes.Insert(warplane, i);
+ _setWarPlanes.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ private void DrawHangar(Graphics g, int x, int y, int width, int height)
+ {
+ Pen pen = new(Color.Black, 3);
+ g.DrawLine(pen, x, y, x + width, y);
+ g.DrawLine(pen, x, y, x, y+height);
+ g.DrawLine(pen, x, y + height, x+ width, y + height);
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight + 1; ++j)
+ {
+ DrawHangar(g, i * _placeSizeWidth, j * _placeSizeHeight, _placeSizeWidth*3/4, _placeSizeHeight-10);
+ }
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawWarPlanes(Graphics g)
+ {
+ int countInLine = _pictureWidth / _placeSizeWidth;
+ int maxLeft = (countInLine - 1) * _placeSizeWidth;
+ for (int i = 0; i < _setWarPlanes.Count; i++)
+ {
+ var warplane = _setWarPlanes.Get(i);
+ warplane?.SetObject(maxLeft - i % countInLine * _placeSizeWidth +10, _pictureHeight - _placeSizeHeight - i / countInLine * _placeSizeHeight, _pictureWidth, _pictureHeight);
+ warplane?.DrawningObject(g);
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/Program.cs b/WarPlanes/WarPlanes/Program.cs
index b613151..70f3587 100644
--- a/WarPlanes/WarPlanes/Program.cs
+++ b/WarPlanes/WarPlanes/Program.cs
@@ -11,7 +11,7 @@ namespace AirFighter
// To customize application configuration such as set high DPI settings or default font,
// see https://aka.ms/applicationconfiguration.
ApplicationConfiguration.Initialize();
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetWarPlanes());
}
}
}
\ No newline at end of file
diff --git a/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs b/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
new file mode 100644
index 0000000..669f92f
--- /dev/null
+++ b/WarPlanes/WarPlanes/SetWarPlanesGeneric.cs
@@ -0,0 +1,87 @@
+namespace AirFighter
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetWarPlanesGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetWarPlanesGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый самолёт
+ ///
+ public int Insert(T warplane)
+ {
+ return Insert(warplane, 0);
+ }
+ private bool isCorrectPosition(int position)
+ {
+ return 0 <= position && position < Count;
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый военный самолёт
+ /// Позиция
+ ///
+ public int Insert(T warplane, int position)
+ {
+ int positionNullElement = position;
+ while (Get(positionNullElement) != null)
+ {
+ positionNullElement++;
+ }
+ if (!isCorrectPosition(positionNullElement))
+ {
+ return -1;
+ }
+ while (positionNullElement != position) // Смещение вправо
+ {
+ _places[positionNullElement] = _places[positionNullElement - 1];
+ positionNullElement--;
+ }
+ _places[position] = warplane;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ if (!isCorrectPosition(position)) return null;
+ var result = _places[position];
+ _places[position] = null;
+ return result;
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ if (isCorrectPosition(position)) { return _places[position]; }
+ else { return null; }
+ }
+ }
+}
\ No newline at end of file