diff --git a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
index 216637f..a9ce121 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirplaneWithRadar
{
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs
index fa164eb..92d02d6 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplane.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirplaneWithRadar
{
- internal class DrawningAirplane
+ public class DrawningAirplane
{
public EntityAirplane Airplane { get; protected set; }
protected float _startPosX;
@@ -84,9 +84,11 @@ namespace AirplaneWithRadar
// Корпус
g.DrawRectangle(pen, _startPosX, _startPosY + 10, 40, 10);
+ Brush darkBrush = new SolidBrush(Airplane?.BodyColor ?? Color.Black);
+ g.FillRectangle(darkBrush, _startPosX + 1, _startPosY + 11, 39, 9);
// Окно
- Brush darkBrush = new SolidBrush(Airplane?.BodyColor ?? Color.Black);
+ darkBrush = new SolidBrush(Color.Black);
g.FillRectangle(darkBrush, _startPosX + 12, _startPosY + 13, 20, 2);
// Хвост
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs
index 74b1dc3..ee5367f 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawningAirplaneWithRadar.cs
@@ -33,7 +33,7 @@ namespace AirplaneWithRadar
if (airplaneWithRadar.Window)
{
- g.DrawEllipse(new Pen(Color.Black), _startPosX + 40, _startPosY + 13, 5, 5);
+ g.FillEllipse(dopBrush, _startPosX + 40, _startPosY + 13, 5, 5);
}
if (airplaneWithRadar.Ladder)
diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
index 1590cb7..be48f3b 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
@@ -6,7 +6,7 @@ using System.Threading.Tasks;
namespace AirplaneWithRadar
{
- internal class EntityAirplane
+ public class EntityAirplane
{
public int Speed { get; private set; }
public float Weight { get; private set; }
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs
index c6f0ae9..54aef14 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.Designer.cs
@@ -39,6 +39,7 @@
this.buttonRight = new System.Windows.Forms.Button();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonCreateModify = new System.Windows.Forms.Button();
+ this.buttonSelectCar = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
this.statusStrip1.SuspendLayout();
this.SuspendLayout();
@@ -154,11 +155,22 @@
this.buttonCreateModify.UseVisualStyleBackColor = true;
this.buttonCreateModify.Click += new System.EventHandler(this.buttonCreateModify_Click);
//
+ // buttonSelectCar
+ //
+ this.buttonSelectCar.Location = new System.Drawing.Point(560, 391);
+ this.buttonSelectCar.Name = "buttonSelectCar";
+ this.buttonSelectCar.Size = new System.Drawing.Size(94, 29);
+ this.buttonSelectCar.TabIndex = 8;
+ this.buttonSelectCar.Text = "Выбрать";
+ this.buttonSelectCar.UseVisualStyleBackColor = true;
+ this.buttonSelectCar.Click += new System.EventHandler(this.buttonSelectCar_Click);
+ //
// FormAirplane
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 451);
+ this.Controls.Add(this.buttonSelectCar);
this.Controls.Add(this.buttonCreateModify);
this.Controls.Add(this.buttonUp);
this.Controls.Add(this.buttonRight);
@@ -190,5 +202,6 @@
private Button buttonRight;
private Button buttonUp;
private Button buttonCreateModify;
+ private Button buttonSelectCar;
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs
index eae7bbb..840125b 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplane.cs
@@ -3,6 +3,10 @@ namespace AirplaneWithRadar
public partial class FormAirplane : Form
{
private DrawningAirplane _airplane;
+ ///
+ ///
+ ///
+ public DrawningAirplane SelectedAirplane { get; private set; }
public FormAirplane()
{
InitializeComponent();
@@ -27,8 +31,14 @@ namespace AirplaneWithRadar
}
private void ButtonCreate_Click(object sender, EventArgs e)
{
- Random rnd = new();
- _airplane = new DrawningAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
+ Random random = new();
+ Color myColor = new Color();
+ ColorDialog MyDialog = new ColorDialog();
+ if (MyDialog.ShowDialog() == DialogResult.OK)
+ {
+ myColor = MyDialog.Color;
+ }
+ _airplane = new DrawningAirplane(random.Next(30, 50), random.Next(1000, 2000), myColor);
SetData();
Draw();
}
@@ -66,12 +76,28 @@ namespace AirplaneWithRadar
private void buttonCreateModify_Click(object sender, EventArgs e)
{
Random rnd = new();
- _airplane = new DrawningAirplaneWithRadar(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;
+ }
+ _airplane = new DrawningAirplaneWithRadar(rnd.Next(100, 300), rnd.Next(1000, 2000), color, dopColor,
Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)), Convert.ToBoolean(rnd.Next(0, 2)));
SetData();
Draw();
}
+
+ private void buttonSelectCar_Click(object sender, EventArgs e)
+ {
+ SelectedAirplane = _airplane;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs
new file mode 100644
index 0000000..1136dd0
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.Designer.cs
@@ -0,0 +1,239 @@
+namespace AirplaneWithRadar
+{
+ partial class FormMapWithSetAirplane
+ {
+ ///
+ /// 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.groupBox = new System.Windows.Forms.GroupBox();
+ 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.buttonShowStorage = new System.Windows.Forms.Button();
+ this.buttonRemoveAirplane = new System.Windows.Forms.Button();
+ this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
+ this.buttonAddAirplane = new System.Windows.Forms.Button();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
+ this.pictureBox = new System.Windows.Forms.PictureBox();
+ this.groupBox.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.SuspendLayout();
+ //
+ // groupBox
+ //
+ this.groupBox.Controls.Add(this.buttonDown);
+ this.groupBox.Controls.Add(this.buttonRight);
+ this.groupBox.Controls.Add(this.buttonLeft);
+ this.groupBox.Controls.Add(this.buttonUp);
+ this.groupBox.Controls.Add(this.buttonShowOnMap);
+ this.groupBox.Controls.Add(this.buttonShowStorage);
+ this.groupBox.Controls.Add(this.buttonRemoveAirplane);
+ this.groupBox.Controls.Add(this.maskedTextBoxPosition);
+ this.groupBox.Controls.Add(this.buttonAddAirplane);
+ this.groupBox.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
+ this.groupBox.Location = new System.Drawing.Point(685, 0);
+ this.groupBox.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Padding = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.groupBox.Size = new System.Drawing.Size(229, 600);
+ this.groupBox.TabIndex = 0;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Инструменты";
+ //
+ // buttonDown
+ //
+ this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.arrowDown;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(99, 537);
+ this.buttonDown.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(34, 40);
+ this.buttonDown.TabIndex = 9;
+ 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::AirplaneWithRadar.Properties.Resources.arrowRight;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(141, 537);
+ this.buttonRight.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(34, 40);
+ this.buttonRight.TabIndex = 8;
+ 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::AirplaneWithRadar.Properties.Resources.arrowLeft;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(58, 537);
+ this.buttonLeft.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonLeft.Name = "buttonLeft";
+ this.buttonLeft.Size = new System.Drawing.Size(34, 40);
+ this.buttonLeft.TabIndex = 7;
+ 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::AirplaneWithRadar.Properties.Resources.arrowUp;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(99, 489);
+ this.buttonUp.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonUp.Name = "buttonUp";
+ this.buttonUp.Size = new System.Drawing.Size(34, 40);
+ this.buttonUp.TabIndex = 6;
+ this.buttonUp.UseVisualStyleBackColor = true;
+ this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonShowOnMap
+ //
+ this.buttonShowOnMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonShowOnMap.Location = new System.Drawing.Point(22, 416);
+ this.buttonShowOnMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(193, 40);
+ this.buttonShowOnMap.TabIndex = 5;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonShowStorage.Location = new System.Drawing.Point(22, 311);
+ this.buttonShowStorage.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(193, 40);
+ this.buttonShowStorage.TabIndex = 4;
+ this.buttonShowStorage.Text = "Посмотреть хранилище";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonRemoveAirplane
+ //
+ this.buttonRemoveAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonRemoveAirplane.Location = new System.Drawing.Point(22, 228);
+ this.buttonRemoveAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
+ this.buttonRemoveAirplane.Size = new System.Drawing.Size(193, 40);
+ this.buttonRemoveAirplane.TabIndex = 3;
+ this.buttonRemoveAirplane.Text = "Удалить самолет";
+ this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
+ this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(22, 189);
+ this.maskedTextBoxPosition.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(193, 27);
+ this.maskedTextBoxPosition.TabIndex = 2;
+ //
+ // buttonAddAirplane
+ //
+ this.buttonAddAirplane.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ this.buttonAddAirplane.Location = new System.Drawing.Point(22, 120);
+ this.buttonAddAirplane.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.buttonAddAirplane.Name = "buttonAddAirplane";
+ this.buttonAddAirplane.Size = new System.Drawing.Size(193, 40);
+ this.buttonAddAirplane.TabIndex = 1;
+ this.buttonAddAirplane.Text = "Добавить самолет";
+ this.buttonAddAirplane.UseVisualStyleBackColor = true;
+ this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
+ 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(22, 44);
+ this.comboBoxSelectorMap.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(193, 28);
+ 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.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.pictureBox.Name = "pictureBox";
+ this.pictureBox.Size = new System.Drawing.Size(685, 600);
+ this.pictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize;
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetAirplane
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(914, 600);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBox);
+ this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
+ this.Name = "FormMapWithSetAirplane";
+ this.Text = "FormMapWithSetAirplane";
+ this.groupBox.ResumeLayout(false);
+ this.groupBox.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+ this.PerformLayout();
+
+ }
+
+ #endregion
+
+ private GroupBox groupBox;
+ private Button buttonDown;
+ private Button buttonRight;
+ private Button buttonLeft;
+ private Button buttonUp;
+ private Button buttonShowOnMap;
+ private Button buttonShowStorage;
+ private Button buttonRemoveAirplane;
+ private MaskedTextBox maskedTextBoxPosition;
+ private Button buttonAddAirplane;
+ private ComboBox comboBoxSelectorMap;
+ private PictureBox pictureBox;
+ }
+}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs
new file mode 100644
index 0000000..b5eba7a
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.cs
@@ -0,0 +1,164 @@
+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;
+using static System.Windows.Forms.DataFormats;
+
+namespace AirplaneWithRadar
+{
+ public partial class FormMapWithSetAirplane : Form
+ {
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetAirplaneGeneric _mapAirplaneCollectionGeneric;
+ public FormMapWithSetAirplane()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Карта неба с облаками":
+ map = new SkyMap();
+ break;
+ case "Карта туманного неба с грозой":
+ map = new FoggySkyMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapAirplaneCollectionGeneric = new MapWithSetAirplaneGeneric(
+ pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapAirplaneCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddAirplane_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplaneCollectionGeneric == null)
+ {
+ return;
+ }
+ FormAirplane form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawningObjectAirplane airplane = new(form.SelectedAirplane);
+ if (_mapAirplaneCollectionGeneric + airplane != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось добавить объект");
+ }
+ }
+ }
+ ///
+ /// Удаление объекта
+ ///
+ ///
+ ///
+ private void ButtonRemoveAirplane_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 (_mapAirplaneCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplaneCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapAirplaneCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplaneCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapAirplaneCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplaneCollectionGeneric == 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 = _mapAirplaneCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx
new file mode 100644
index 0000000..f298a7b
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplane.resx
@@ -0,0 +1,60 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 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/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs
new file mode 100644
index 0000000..69f4d04
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplaneGeneric.cs
@@ -0,0 +1,142 @@
+namespace AirplaneWithRadar
+{
+ // Карта с набром объектов под нее
+ internal class MapWithSetAirplaneGeneric
+ where T : class, IDrawningObject
+ where U : AbstractMap
+ {
+ // Ширина окна отрисовки
+ private readonly int _pictureWidth;
+ // Высота окна отрисовки
+ private readonly int _pictureHeight;
+ // Размер занимаемого объектом места (ширина)
+ private readonly int _placeSizeWidth = 180;
+ // Размер занимаемого объектом места (высота)
+ private readonly int _placeSizeHeight = 90;
+ // Набор объектов
+ private readonly SetAirplaneGeneric _setAirplane;
+ // Карта
+ private readonly U _map;
+ // Конструктор
+ public MapWithSetAirplaneGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setAirplane = new SetAirplaneGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ // Перегрузка оператора сложения
+ public static int operator +(MapWithSetAirplaneGeneric map, T airplane)
+ {
+ return map._setAirplane.Insert(airplane);
+ }
+ // Перегрузка оператора вычитания
+ public static T operator -(MapWithSetAirplaneGeneric map, int position)
+ {
+ return map._setAirplane.Remove(position);
+ }
+ // Вывод всего набора объектов
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawAirplane(gr);
+ return bmp;
+ }
+ // Просмотр объекта на карте
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setAirplane.Count; i++)
+ {
+ var airplane = _setAirplane.Get(i);
+ if (airplane != null)
+ {
+ return _map.CreateMap(_pictureWidth, _pictureHeight, airplane);
+ }
+ }
+ 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 = _setAirplane.Count - 1;
+ for (int i = 0; i < _setAirplane.Count; i++)
+ {
+ if (_setAirplane.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var airplane = _setAirplane.Get(j);
+ if (airplane != null)
+ {
+ _setAirplane.Insert(airplane, i);
+ _setAirplane.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ // Метод отрисовки фона
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.Black, 3);
+ Brush brush = new SolidBrush(Color.FromArgb(147, 146, 151));
+ g.FillRectangle(brush, 0, 0, _pictureWidth, _pictureHeight);
+ for (int i = 0; i <= _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j <= _pictureHeight / _placeSizeHeight + 1; ++j)
+ {//линия разметки места
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight);
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight + 10, i * _placeSizeWidth + _placeSizeWidth, j * _placeSizeHeight + 10);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
+ }
+ }
+ // Метод прорисовки объектов
+ private void DrawAirplane(Graphics g)
+ {
+ int widthEl = _pictureWidth / _placeSizeWidth;
+ int heightEl = _pictureHeight / _placeSizeHeight;
+
+ int curWidth = 0;
+ int curHeight = 0;
+
+ for (int i = _setAirplane.Count; i >= 0; i--)
+ {
+ _setAirplane.Get(i)?.SetObject(_pictureWidth - _placeSizeWidth * curWidth - 80,
+ curHeight * _placeSizeHeight + 30, _pictureWidth, _pictureHeight);
+ _setAirplane.Get(i)?.DrawningObject(g);
+
+ if (curWidth < widthEl)
+ curWidth++;
+ else
+ {
+ curWidth = 1;
+ curHeight++;
+ }
+ if (curHeight > heightEl)
+ {
+ return;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Program.cs b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
index f8a0be0..7c1941f 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Program.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
@@ -11,7 +11,7 @@ namespace AirplaneWithRadar
// 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 FormMapWithSetAirplane());
}
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplaneGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplaneGeneric.cs
new file mode 100644
index 0000000..53a1c55
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplaneGeneric.cs
@@ -0,0 +1,75 @@
+namespace AirplaneWithRadar
+{
+ // Параметризованный набор объектов
+ internal class SetAirplaneGeneric
+ where T : class
+ {
+ // Массив объектов, которые храним
+ private readonly T[] _places;
+ // Количество объектов в массиве
+ public int Count => _places.Length;
+ // Конструктор
+ public SetAirplaneGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ // Добавление объекта в набор
+ public int Insert(T airplane)
+ {
+ // вставка в начало набора
+ return Insert(airplane, 0);
+ }
+ // Добавление объекта в набор на конкретную позицию
+ public int Insert(T airplane, int position)
+ {
+ // проверка позиции
+ if (position >= _places.Length || position < 0)
+ return -1;
+ //проверка, что элемент массива по этой позиции пустой, если нет, то
+ if (_places[position] == null)
+ {
+ _places[position] = airplane;
+ return position;
+ }
+ //проверка, что после вставляемого элемента в массиве есть пустой элемент
+ int findEmptyPos = -1;
+
+ for (int i = position + 1; i < Count; i++)
+ {
+ if (_places[i] == null)
+ {
+ findEmptyPos = i;
+ break;
+ }
+ }
+ if (findEmptyPos < 0) return -1;
+
+ //сдвиг всех объектов, находящихся справа от позиции до первого пустого элемента
+ for (int i = findEmptyPos; i > position; i--)
+ {
+ _places[i] = _places[i - 1];
+ }
+ // вставка по позиции
+ _places[position] = airplane;
+ return position;
+ }
+ // Удаление объекта из набора с конкретной позиции
+ public T Remove(int position)
+ {
+ // проверка позиции
+ if (position >= _places.Length || position < 0) return null;
+ // удаление объекта из массива, присовив элементу массива значение null
+ T temp = _places[position];
+ _places[position] = null;
+ return temp;
+ }
+ // Получение объекта из набора по позиции
+ public T Get(int position)
+ {
+ // проверка позиции
+ if (position >= _places.Length || position < 0)
+ return null;
+ return _places[position];
+ }
+ }
+}
\ No newline at end of file