diff --git a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs
index e235bf8..39ca2cc 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/AbstractMap.cs
@@ -67,6 +67,8 @@ namespace AirplaneWithRadar
return DrawMapWithObject();
}
private bool CheckBarriers(float leftMove, float rightMove, float topMove, float bottomMove)
+<<<<<<< HEAD
+=======
{
int left = Convert.ToInt32((_drawingObject.GetCurrentPosition().Left + leftMove) / _size_x);
int right = Convert.ToInt32((_drawingObject.GetCurrentPosition().Right + rightMove) / _size_x);
@@ -76,6 +78,27 @@ namespace AirplaneWithRadar
{
return false;
}
+ for (int i = top; i <= bottom; i++)
+ {
+ for (int j = left; j <= right; j++)
+ {
+ if (_map[j, i] == 1) return false;
+ }
+ }
+ return true;
+ }
+ private bool SetObjectOnMap()
+>>>>>>> LabWork03
+ {
+ int left = Convert.ToInt32((_drawingObject.GetCurrentPosition().Left + leftMove) / _size_x);
+ int right = Convert.ToInt32((_drawingObject.GetCurrentPosition().Right + rightMove) / _size_x);
+ int top = Convert.ToInt32((_drawingObject.GetCurrentPosition().Top + topMove) / _size_y);
+ int bottom = Convert.ToInt32((_drawingObject.GetCurrentPosition().Bottom + bottomMove) / _size_y);
+ if (top < 0 || left < 0 || right >= _map.GetLength(1) || bottom >= _map.GetLength(0))
+ {
+ return false;
+ }
+<<<<<<< HEAD
for (int i = top; i <= bottom; i++)
{
for (int j = left; j <= right; j++)
@@ -101,6 +124,15 @@ namespace AirplaneWithRadar
{
return false;
}
+=======
+ int x = _random.Next(0, 10);
+ int y = _random.Next(0, 10);
+ _drawingObject.SetObject(x, y, _width, _height);
+ if (!CheckBarriers(0, 0, 0, 0))
+ {
+ return false;
+ }
+>>>>>>> LabWork03
return true;
}
private Bitmap DrawMapWithObject()
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
index 9a262a7..9e6fc28 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Direction.cs
@@ -9,7 +9,7 @@ namespace AirplaneWithRadar
///
/// Направление перемещения
///
- internal enum Direction
+ public enum Direction
{
None = 0,
Up = 1,
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
index 475668b..ab2ee46 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplane.cs
@@ -9,7 +9,7 @@ namespace AirplaneWithRadar
///
/// Класс, отвечающий за прорисовку и перемещение объекта-сущности
///
- internal class DrawingAirplane
+ public class DrawingAirplane
{
///
/// Класс-сущность
diff --git a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
index b959a73..6ee6a32 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/DrawingAirplaneWithRadar.cs
@@ -17,7 +17,11 @@ namespace AirplaneWithRadar
/// Дополнительный цвет
/// Признак наличия радара
/// Признак наличия дополнительных топливных баков
+<<<<<<< HEAD
public DrawingAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor, 304, 109)
+=======
+ public DrawingAirplaneWithRadar(int speed, float weight, Color bodyColor, Color dopColor, bool radar, bool extraFuelTank) : base(speed, weight, bodyColor, 303, 102)
+>>>>>>> LabWork03
{
Airplane = new EntityAirplaneWithRadar(speed, weight, bodyColor, dopColor, radar, extraFuelTank);
}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
index 3381c72..6bf9013 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/EntityAirplane.cs
@@ -9,7 +9,7 @@ namespace AirplaneWithRadar
///
/// Класс-сущность "Самолет"
///
- internal class EntityAirplane
+ public class EntityAirplane
{
///
/// Скорость
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.Designer.cs
index b57c74d..d0040e3 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.Designer.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.Designer.cs
@@ -39,6 +39,7 @@
this.buttonDown = new System.Windows.Forms.Button();
this.buttonRight = new System.Windows.Forms.Button();
this.buttonCreateModif = new System.Windows.Forms.Button();
+ this.buttonSelectAirplane = new System.Windows.Forms.Button();
this.statusStrip.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBoxAirplane)).BeginInit();
this.SuspendLayout();
@@ -152,11 +153,22 @@
this.buttonCreateModif.UseVisualStyleBackColor = true;
this.buttonCreateModif.Click += new System.EventHandler(this.ButtonCreateModif_Click);
//
+ // buttonSelectAirplane
+ //
+ this.buttonSelectAirplane.Location = new System.Drawing.Point(529, 372);
+ this.buttonSelectAirplane.Name = "buttonSelectAirplane";
+ this.buttonSelectAirplane.Size = new System.Drawing.Size(112, 34);
+ this.buttonSelectAirplane.TabIndex = 8;
+ this.buttonSelectAirplane.Text = "Выбрать";
+ this.buttonSelectAirplane.UseVisualStyleBackColor = true;
+ this.buttonSelectAirplane.Click += new System.EventHandler(this.ButtonSelectAirplane_Click);
+ //
// FormAirplaneWithRadar
//
this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(800, 450);
+ this.Controls.Add(this.buttonSelectAirplane);
this.Controls.Add(this.buttonCreateModif);
this.Controls.Add(this.buttonRight);
this.Controls.Add(this.buttonDown);
@@ -188,5 +200,6 @@
private Button buttonDown;
private Button buttonRight;
private Button buttonCreateModif;
+ private Button buttonSelectAirplane;
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs
index 8ee0358..1e8f025 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormAirplaneWithRadar.cs
@@ -3,6 +3,11 @@ namespace AirplaneWithRadar
public partial class FormAirplaneWithRadar : Form
{
private DrawingAirplane _airplane;
+<<<<<<< HEAD
+=======
+ public DrawingAirplane SelectedAirplane { get; private set; }
+
+>>>>>>> LabWork03
public FormAirplaneWithRadar()
{
InitializeComponent();
@@ -36,12 +41,22 @@ namespace AirplaneWithRadar
private void ButtonCreate_Click(object sender, EventArgs e)
{
Random rnd = new();
- _airplane = new DrawingAirplane(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;
+ }
+ _airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), color);
SetData();
Draw();
}
///
+<<<<<<< HEAD
///
+=======
+ /// ""
+>>>>>>> LabWork03
///
///
///
@@ -73,10 +88,26 @@ namespace AirplaneWithRadar
private void ButtonCreateModif_Click(object sender, EventArgs e)
{
Random rnd = new();
- _airplane = new DrawingAirplaneWithRadar(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)));
+ 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 DrawingAirplaneWithRadar(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 ButtonSelectAirplane_Click(object sender, EventArgs e)
+ {
+ SelectedAirplane = _airplane;
+ DialogResult = DialogResult.OK;
+ }
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs
deleted file mode 100644
index a3f1674..0000000
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMap.cs
+++ /dev/null
@@ -1,102 +0,0 @@
-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 AirplaneWithRadar
-{
- public partial class FormMap : Form
- {
- private AbstractMap _abstractMap;
- public FormMap()
- {
- InitializeComponent();
- _abstractMap = new SimpleMap();
- }
- ///
- /// Заполнение информации по объекту
- ///
- ///
- private void SetData(DrawingAirplane airplane)
- {
- toolStripStatusLabelSpeed.Text = $"Скорость: {airplane.Airplane.Speed}";
- toolStripStatusLabelWeight.Text = $"Вес: {airplane.Airplane.Weight}";
- toolStripStatusLabelBodyColor.Text = $"Цвет:{airplane.Airplane.BodyColor.Name}";
- pictureBoxAirplane.Image = _abstractMap.CreateMap(pictureBoxAirplane.Width,pictureBoxAirplane.Height,new DrawingObjectAirplane(airplane));
- }
- ///
- /// Обработка нажатия кнопки "Создать"
- ///
- ///
- ///
- private void ButtonCreate_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var airplane = new DrawingAirplane(rnd.Next(100, 300), rnd.Next(1000, 2000), Color.FromArgb(rnd.Next(0, 256), rnd.Next(0, 256), rnd.Next(0, 256)));
- SetData(airplane);
- }
- ///
- /// Перемещение
- ///
- ///
- ///
- 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;
- }
- pictureBoxAirplane.Image = _abstractMap?.MoveObject(dir);
- }
- ///
- /// Обработка нажатия кнопки "Модификация"
- ///
- ///
- ///
- private void ButtonCreateModif_Click(object sender, EventArgs e)
- {
- Random rnd = new();
- var airplane = new DrawingAirplaneWithRadar(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(airplane);
- }
- ///
- /// Выбор карты
- ///
- ///
- ///
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- switch (comboBoxSelectorMap.Text)
- {
- case "Простая карта":
- _abstractMap = new SimpleMap();
- break;
- case "Карта с линиями":
- _abstractMap = new LineMap();
- break;
- case "Карта с блоками":
- _abstractMap = new BlockMap();
- break;
- }
- }
- }
-}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
new file mode 100644
index 0000000..23df6e0
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.Designer.cs
@@ -0,0 +1,212 @@
+namespace AirplaneWithRadar
+{
+ partial class FormMapWithSetAirplanes
+ {
+ ///
+ /// 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.buttonRight = new System.Windows.Forms.Button();
+ this.buttonDown = 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.buttonRight);
+ this.groupBox.Controls.Add(this.buttonDown);
+ 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(723, 0);
+ this.groupBox.Name = "groupBox";
+ this.groupBox.Size = new System.Drawing.Size(257, 526);
+ this.groupBox.TabIndex = 0;
+ this.groupBox.TabStop = false;
+ this.groupBox.Text = "Инструменты";
+ //
+ // buttonRight
+ //
+ this.buttonRight.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.right;
+ this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonRight.Location = new System.Drawing.Point(160, 433);
+ this.buttonRight.Name = "buttonRight";
+ this.buttonRight.Size = new System.Drawing.Size(30, 30);
+ this.buttonRight.TabIndex = 10;
+ this.buttonRight.UseVisualStyleBackColor = true;
+ this.buttonRight.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonDown
+ //
+ this.buttonDown.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.down;
+ this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonDown.Location = new System.Drawing.Point(124, 433);
+ this.buttonDown.Name = "buttonDown";
+ this.buttonDown.Size = new System.Drawing.Size(30, 30);
+ this.buttonDown.TabIndex = 9;
+ this.buttonDown.UseVisualStyleBackColor = true;
+ this.buttonDown.Click += new System.EventHandler(this.ButtonMove_Click);
+ //
+ // buttonLeft
+ //
+ this.buttonLeft.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.left;
+ this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonLeft.Location = new System.Drawing.Point(88, 433);
+ 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.BackgroundImage = global::AirplaneWithRadar.Properties.Resources.up;
+ this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
+ this.buttonUp.Location = new System.Drawing.Point(124, 397);
+ 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(23, 319);
+ this.buttonShowOnMap.Name = "buttonShowOnMap";
+ this.buttonShowOnMap.Size = new System.Drawing.Size(222, 34);
+ this.buttonShowOnMap.TabIndex = 6;
+ this.buttonShowOnMap.Text = "Посмотреть карту";
+ this.buttonShowOnMap.UseVisualStyleBackColor = true;
+ this.buttonShowOnMap.Click += new System.EventHandler(this.ButtonShowOnMap_Click);
+ //
+ // buttonShowStorage
+ //
+ this.buttonShowStorage.Location = new System.Drawing.Point(23, 251);
+ this.buttonShowStorage.Name = "buttonShowStorage";
+ this.buttonShowStorage.Size = new System.Drawing.Size(222, 37);
+ this.buttonShowStorage.TabIndex = 5;
+ this.buttonShowStorage.Text = "Посмотреть хранилище";
+ this.buttonShowStorage.UseVisualStyleBackColor = true;
+ this.buttonShowStorage.Click += new System.EventHandler(this.ButtonShowStorage_Click);
+ //
+ // buttonRemoveAirplane
+ //
+ this.buttonRemoveAirplane.Location = new System.Drawing.Point(23, 186);
+ this.buttonRemoveAirplane.Name = "buttonRemoveAirplane";
+ this.buttonRemoveAirplane.Size = new System.Drawing.Size(222, 34);
+ this.buttonRemoveAirplane.TabIndex = 4;
+ this.buttonRemoveAirplane.Text = "Удалить самолет";
+ this.buttonRemoveAirplane.UseVisualStyleBackColor = true;
+ this.buttonRemoveAirplane.Click += new System.EventHandler(this.ButtonRemoveAirplane_Click);
+ //
+ // maskedTextBoxPosition
+ //
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(23, 149);
+ this.maskedTextBoxPosition.Mask = "00";
+ this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
+ this.maskedTextBoxPosition.Size = new System.Drawing.Size(222, 31);
+ this.maskedTextBoxPosition.TabIndex = 3;
+ //
+ // buttonAddAirplane
+ //
+ this.buttonAddAirplane.Location = new System.Drawing.Point(23, 94);
+ this.buttonAddAirplane.Name = "buttonAddAirplane";
+ this.buttonAddAirplane.Size = new System.Drawing.Size(222, 34);
+ this.buttonAddAirplane.TabIndex = 2;
+ this.buttonAddAirplane.Text = "Добавить самолет";
+ this.buttonAddAirplane.UseVisualStyleBackColor = true;
+ this.buttonAddAirplane.Click += new System.EventHandler(this.ButtonAddAirplane_Click);
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Карта с линиями",
+ "Карта с блоками"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(23, 44);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(222, 33);
+ 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(723, 526);
+ this.pictureBox.TabIndex = 1;
+ this.pictureBox.TabStop = false;
+ //
+ // FormMapWithSetAirplanes
+ //
+ this.AutoScaleDimensions = new System.Drawing.SizeF(10F, 25F);
+ this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
+ this.ClientSize = new System.Drawing.Size(980, 526);
+ this.Controls.Add(this.pictureBox);
+ this.Controls.Add(this.groupBox);
+ this.Name = "FormMapWithSetAirplanes";
+ this.Text = "FormMapWithSetAirplanes";
+ this.groupBox.ResumeLayout(false);
+ this.groupBox.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.ResumeLayout(false);
+
+ }
+
+ #endregion
+
+ private GroupBox groupBox;
+ private Button buttonRight;
+ private Button buttonDown;
+ 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/FormMapWithSetAirplanes.cs b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
new file mode 100644
index 0000000..5c2c226
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.cs
@@ -0,0 +1,154 @@
+namespace AirplaneWithRadar
+{
+ public partial class FormMapWithSetAirplanes : Form
+ {
+ ///
+ /// Объект от класса карты с набором объектов
+ ///
+ private MapWithSetAirplanesGeneric _mapAirplanesCollectionGeneric;
+ ///
+ /// Конструктор
+ ///
+ public FormMapWithSetAirplanes()
+ {
+ InitializeComponent();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ AbstractMap map = null;
+ switch (comboBoxSelectorMap.Text)
+ {
+ case "Простая карта":
+ map = new SimpleMap();
+ break;
+ case "Карта с линиями":
+ map = new LineMap();
+ break;
+ case "Карта с блоками":
+ map = new BlockMap();
+ break;
+ }
+ if (map != null)
+ {
+ _mapAirplanesCollectionGeneric = new MapWithSetAirplanesGeneric(pictureBox.Width, pictureBox.Height, map);
+ }
+ else
+ {
+ _mapAirplanesCollectionGeneric = null;
+ }
+ }
+ ///
+ /// Добавление объекта
+ ///
+ ///
+ ///
+ private void ButtonAddAirplane_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplanesCollectionGeneric == null)
+ {
+ return;
+ }
+ FormAirplaneWithRadar form = new();
+ if (form.ShowDialog() == DialogResult.OK)
+ {
+ DrawingObjectAirplane airplane = new(form.SelectedAirplane);
+ if (_mapAirplanesCollectionGeneric + airplane != -1)
+ {
+ MessageBox.Show("Объект добавлен");
+ pictureBox.Image = _mapAirplanesCollectionGeneric.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 (_mapAirplanesCollectionGeneric - pos != null)
+ {
+ MessageBox.Show("Объект удален");
+ pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
+ }
+ else
+ {
+ MessageBox.Show("Не удалось удалить объект");
+ }
+ }
+ ///
+ /// Вывод набора
+ ///
+ ///
+ ///
+ private void ButtonShowStorage_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplanesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapAirplanesCollectionGeneric.ShowSet();
+ }
+ ///
+ /// Вывод карты
+ ///
+ ///
+ ///
+ private void ButtonShowOnMap_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplanesCollectionGeneric == null)
+ {
+ return;
+ }
+ pictureBox.Image = _mapAirplanesCollectionGeneric.ShowOnMap();
+ }
+ ///
+ /// Перемещение
+ ///
+ ///
+ ///
+ private void ButtonMove_Click(object sender, EventArgs e)
+ {
+ if (_mapAirplanesCollectionGeneric == 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 = _mapAirplanesCollectionGeneric.MoveObject(dir);
+ }
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/FormMap.resx b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.resx
similarity index 93%
rename from AirplaneWithRadar/AirplaneWithRadar/FormMap.resx
rename to AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.resx
index 2c0949d..f298a7b 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/FormMap.resx
+++ b/AirplaneWithRadar/AirplaneWithRadar/FormMapWithSetAirplanes.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/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs
index 3e8a16c..0dcd348 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/IDrawingObject.cs
@@ -1,10 +1,4 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-
-namespace AirplaneWithRadar
+namespace AirplaneWithRadar
{
///
/// Интерфейс для работы с объектом, прорисовываемым на форме
diff --git a/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs
new file mode 100644
index 0000000..059ae83
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/MapWithSetAirplanesGeneric.cs
@@ -0,0 +1,180 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirplaneWithRadar
+{
+ ///
+ /// Карта с набром объектов под нее
+ ///
+ ///
+ ///
+ internal class MapWithSetAirplanesGeneric
+ where T : class, IDrawingObject
+ where U : AbstractMap
+ {
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Размер занимаемого объектом места (ширина)
+ ///
+ private readonly int _placeSizeWidth = 314;
+ ///
+ /// Размер занимаемого объектом места (высота)
+ ///
+ private readonly int _placeSizeHeight = 128;
+ ///
+ /// Набор объектов
+ ///
+ private readonly SetAirplanesGeneric _setAirplanes;
+ ///
+ /// Карта
+ ///
+ private readonly U _map;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public MapWithSetAirplanesGeneric(int picWidth, int picHeight, U map)
+ {
+ int width = picWidth / _placeSizeWidth;
+ int height = picHeight / _placeSizeHeight;
+ _setAirplanes = new SetAirplanesGeneric(width * height);
+ _pictureWidth = picWidth;
+ _pictureHeight = picHeight;
+ _map = map;
+ }
+ ///
+ /// Перегрузка оператора сложения
+ ///
+ ///
+ ///
+ ///
+ public static int operator +(MapWithSetAirplanesGeneric map, T airplane)
+ {
+ return map._setAirplanes.Insert(airplane);
+ }
+ ///
+ /// Перегрузка оператора вычитания
+ ///
+ ///
+ ///
+ ///
+ public static T operator -(MapWithSetAirplanesGeneric map, int position)
+ {
+ return map._setAirplanes.Remove(position);
+ }
+ ///
+ /// Вывод всего набора объектов
+ ///
+ ///
+ public Bitmap ShowSet()
+ {
+ Bitmap bmp = new(_pictureWidth, _pictureHeight);
+ Graphics gr = Graphics.FromImage(bmp);
+ DrawBackground(gr);
+ DrawAirplanes(gr);
+ return bmp;
+ }
+ ///
+ /// Просмотр объекта на карте
+ ///
+ ///
+ public Bitmap ShowOnMap()
+ {
+ Shaking();
+ for (int i = 0; i < _setAirplanes.Count; i++)
+ {
+ var airplane = _setAirplanes.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 = _setAirplanes.Count - 1;
+ for (int i = 0; i < _setAirplanes.Count; i++)
+ {
+ if (_setAirplanes.Get(i) == null)
+ {
+ for (; j > i; j--)
+ {
+ var airplane = _setAirplanes.Get(j);
+ if (airplane != null)
+ {
+ _setAirplanes.Insert(airplane, i);
+ _setAirplanes.Remove(j);
+ break;
+ }
+ }
+ if (j <= i)
+ {
+ return;
+ }
+ }
+ }
+ }
+ ///
+ /// Метод отрисовки фона
+ ///
+ ///
+ private void DrawBackground(Graphics g)
+ {
+ Pen pen = new(Color.White, 5);
+ g.FillRectangle(Brushes.DimGray, 0, 0, _pictureWidth, _pictureHeight);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
+ {
+ g.DrawLine(pen, i * _placeSizeWidth, j * _placeSizeHeight, i * _placeSizeWidth + _placeSizeWidth * 4/5, j * _placeSizeHeight);
+ }
+ g.DrawLine(pen, i * _placeSizeWidth, 0, i * _placeSizeWidth, (_pictureHeight / _placeSizeHeight) * _placeSizeHeight);
+ }
+ }
+ ///
+ /// Метод прорисовки объектов
+ ///
+ ///
+ private void DrawAirplanes(Graphics g)
+ {
+ int numInRow = _pictureWidth / _placeSizeWidth;
+ int maxLeft = (numInRow - 1) * _placeSizeWidth;
+ for (int i = 0; i < _setAirplanes.Count; i++)
+ {
+ var airplane = _setAirplanes.Get(i);
+ airplane?.SetObject(maxLeft - i % numInRow * _placeSizeWidth + 5, i / numInRow * _placeSizeHeight + 10, _pictureWidth, _pictureHeight);
+ airplane?.DrawingObject(g);
+ }
+ }
+ }
+}
diff --git a/AirplaneWithRadar/AirplaneWithRadar/Program.cs b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
index e51b6fc..64c7b13 100644
--- a/AirplaneWithRadar/AirplaneWithRadar/Program.cs
+++ b/AirplaneWithRadar/AirplaneWithRadar/Program.cs
@@ -9,7 +9,7 @@ namespace AirplaneWithRadar
static void Main()
{
ApplicationConfiguration.Initialize();
- Application.Run(new FormMap());
+ Application.Run(new FormMapWithSetAirplanes());
}
}
}
\ No newline at end of file
diff --git a/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
new file mode 100644
index 0000000..2a28e06
--- /dev/null
+++ b/AirplaneWithRadar/AirplaneWithRadar/SetAirplanesGeneric.cs
@@ -0,0 +1,101 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirplaneWithRadar
+{
+ ///
+ /// Параметризованный набор объектов
+ ///
+ ///
+ internal class SetAirplanesGeneric
+ where T : class
+ {
+ ///
+ /// Массив объектов, которые храним
+ ///
+ private readonly T[] _places;
+ ///
+ /// Количество объектов в массиве
+ ///
+ public int Count => _places.Length;
+ ///
+ /// Конструктор
+ ///
+ ///
+ public SetAirplanesGeneric(int count)
+ {
+ _places = new T[count];
+ }
+ ///
+ /// Добавление объекта в набор
+ ///
+ /// Добавляемый самолет
+ ///
+ public int Insert(T airplane)
+ {
+ return Insert(airplane, 0);
+ }
+ ///
+ /// Добавление объекта в набор на конкретную позицию
+ ///
+ /// Добавляемый самолет
+ /// Позиция
+ ///
+ public int Insert(T airplane, int position)
+ {
+ int positionNullElement = position;
+ while (Get(positionNullElement) != null)
+ {
+ positionNullElement++;
+ }
+ if (positionNullElement > Count || positionNullElement < 0)
+ {
+ return -1;
+ }
+ while (positionNullElement != position)
+ {
+ _places[positionNullElement] = _places[positionNullElement - 1];
+ positionNullElement--;
+ }
+ _places[position] = airplane;
+ return position;
+ }
+ ///
+ /// Удаление объекта из набора с конкретной позиции
+ ///
+ ///
+ ///
+ public T Remove(int position)
+ {
+ if (position > Count || position < 0)
+ {
+ return null;
+ }
+ else
+ {
+ var removedObject = _places[position];
+ _places[position] = null;
+ return removedObject;
+ }
+ }
+ ///
+ /// Получение объекта из набора по позиции
+ ///
+ ///
+ ///
+ public T Get(int position)
+ {
+ if (position > Count || position < 0)
+ {
+ return null;
+ }
+ else
+ {
+ return _places[position];
+ }
+ }
+ }
+}