diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs
index 8aef755..1cca3fd 100644
--- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AbstractCompany.cs
@@ -15,7 +15,7 @@ public abstract class AbstractCompany
///
/// Размер места (высота)
///
- protected readonly int _placeSizeHeight = 100;
+ protected readonly int _placeSizeHeight = 86;
///
/// Ширина окна
@@ -57,9 +57,9 @@ public abstract class AbstractCompany
/// Компания
/// Добавляемый объект
///
- public static bool operator +(AbstractCompany company, DrawningAirCraft aircraft)
+ public static int operator +(AbstractCompany company, DrawningAirCraft aircraft)
{
- return company._collection?.Insert(aircraft) ?? false;
+ return company._collection.Insert(aircraft);
}
///
@@ -68,9 +68,9 @@ public abstract class AbstractCompany
/// Компания
/// Номер удаляемого объекта
///
- public static bool operator -(AbstractCompany company, int position)
+ public static DrawningAirCraft? operator -(AbstractCompany company, int position)
{
- return company._collection?.Remove(position) ?? false;
+ return company._collection?.Remove(position);
}
///
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs
new file mode 100644
index 0000000..b4ced2c
--- /dev/null
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftAngar.cs
@@ -0,0 +1,62 @@
+using ProjectAirFighter.Drawnings;
+
+namespace ProjectAirFighter.CollectionGenericObjects;
+
+///
+/// Реализация абстрактной компании - СимбирФлот
+///
+public class AirCraftAngar : AbstractCompany
+{
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ ///
+ public AirCraftAngar(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
+ {
+ }
+ ///
+ /// Отрисовка хранилища
+ ///
+ /// Графика
+ int pamat_i = 0;
+ protected override void DrawBackgound(Graphics g)
+ {
+ Pen pen = new(Color.Black, 4);
+ for (int i = 0; i < _pictureWidth / _placeSizeWidth; i++)
+ {
+ pamat_i = i;
+ for (int j = 0; j < _pictureHeight / _placeSizeHeight; j++)
+ {
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * j));
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * j), new(_placeSizeWidth * i, _placeSizeHeight * (j + 1)));
+ }
+ g.DrawLine(pen, new(_placeSizeWidth * i, _placeSizeHeight * (_pictureHeight / _placeSizeHeight)), new((int)(_placeSizeWidth * (i + 0.5f)), _placeSizeHeight * (_pictureHeight / _placeSizeHeight)));
+ }
+
+
+ }
+ ///
+ /// Установка объекта в Ангар
+ ///
+ protected override void SetObjectsPosition()
+ {
+ int currentIndex = -1;
+ for (int j = 0 ; j < _pictureHeight / _placeSizeHeight; j++)
+ {
+ for (int i = pamat_i; i >= 0; i--)
+ {
+ currentIndex++;
+ if (_collection?.Get(currentIndex) == null) continue;
+
+ _collection.Get(currentIndex)?.SetPictureSize(_pictureWidth, _pictureHeight);
+ _collection.Get(currentIndex)?.SetPosition(i * _placeSizeWidth + 5, j * _placeSizeHeight + 5);
+ }
+ }
+ }
+}
+
+
+
+
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftSharingService.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftSharingService.cs
deleted file mode 100644
index fe18316..0000000
--- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/AirCraftSharingService.cs
+++ /dev/null
@@ -1,84 +0,0 @@
-using ProjectAirFighter.Drawnings;
-
-namespace ProjectAirFighter.CollectionGenericObjects;
-
-///
-/// Реализация абстрактной компании - СимбирФлот
-///
-public class AirCraftSharingService : AbstractCompany
-{
- ///
- /// Конструктор
- ///
- ///
- ///
- ///
- public AirCraftSharingService(int picWidth, int picHeight, ICollectionGenericObjects collection) : base(picWidth, picHeight, collection)
- {
- }
- private int doroga = 40;
- ///
- /// Отрисовка хранилища
- ///
- /// Графика
- protected override void DrawBackgound(Graphics g)
- {
- Pen pen = new Pen(Color.Black);
-
- int X_max = (_pictureWidth / _placeSizeWidth);
- int Y_max = (_pictureHeight / _placeSizeHeight);
-
- for (int i = 0; i < X_max; i++)
- {
- for (int j = 0; j < Y_max; j++)
- {
- Point[] angars_1 = new Point[] {
- new Point { X = i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight},
- new Point { X = _placeSizeWidth + i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight}
- };
- g.DrawPolygon(pen, angars_1);
-
- Point[] angars_2 = new Point[] {
- new Point { X = i * doroga + i * _placeSizeWidth, Y = j * _placeSizeHeight},
- new Point { X = i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight}
- };
- g.DrawPolygon(pen, angars_2);
-
- Point[] angars_3 = new Point[] {
- new Point { X = i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight},
- new Point { X = _placeSizeWidth + i * doroga + i * _placeSizeWidth, Y = _placeSizeHeight + j * _placeSizeHeight}
- };
- g.DrawPolygon(pen, angars_3);
- }
- }
- }
- ///
- /// Установка объекта в хранилища
- ///
- protected override void SetObjectsPosition()
- {
- int X_max = (_pictureWidth / _placeSizeWidth);
- int Y_max = (_pictureHeight / _placeSizeHeight);
-
- int granicaX = 10;
- int granicaY = 10;
- int num_ang = 0;
-
- for (int j = 0; j < Y_max; j++)
- {
- for (int i = 0; i < X_max; i++)
- {
-
- if (_collection?.Get(num_ang) == null)
- {
- num_ang++;
- continue;
- }
-
- _collection.Get(num_ang)?.SetPictureSize(_pictureWidth, _pictureHeight);
- _collection.Get(num_ang)?.SetPosition(granicaX + i * _placeSizeWidth + i * doroga, granicaY + j * _placeSizeHeight);
- num_ang++;
- }
- }
- }
-}
\ No newline at end of file
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
index b0c6992..e5c620d 100644
--- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/ICollectionGenericObjects.cs
@@ -1,5 +1,9 @@
namespace ProjectAirFighter.CollectionGenericObjects;
+///
+/// Интерфейс описания действий для набора хранимых объектов
+///
+/// Параметр: ограничение - ссылочный тип
///
/// Интерфейс описания действий для набора хранимых объектов
///
@@ -22,7 +26,7 @@ public interface ICollectionGenericObjects
///
/// Добавляемый объект
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj);
+ int Insert(T obj);
///
/// Добавление объекта в коллекцию на конкретную позицию
@@ -30,14 +34,14 @@ public interface ICollectionGenericObjects
/// Добавляемый объект
/// Позиция
/// true - вставка прошла удачно, false - вставка не удалась
- bool Insert(T obj, int position);
+ int Insert(T obj, int position);
///
/// Удаление объекта из коллекции с конкретной позиции
///
/// Позиция
/// true - удаление прошло удачно, false - удаление не удалось
- bool Remove(int position);
+ T? Remove(int position);
///
/// Получение объекта по позиции
@@ -46,3 +50,4 @@ public interface ICollectionGenericObjects
/// Объект
T? Get(int position);
}
+
diff --git a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
index e1251b7..db6fef0 100644
--- a/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
+++ b/ProjectAirFighter/ProjectAirFighter/CollectionGenericObjects/MassiveGenericObjects.cs
@@ -43,55 +43,74 @@ public class MassiveGenericObjects : ICollectionGenericObjects
public T? Get(int position)
{
- if (position < 0 || position >= _collection.Length)
+ if (position >= 0 && position < Count)
+ {
+ return _collection[position];
+ }
+
+ return null;
+ }
+
+ public int Insert(T obj)
+ {
+ return Insert(obj, 0);
+ }
+
+ public int Insert(T obj, int position)
+ {
+
+ if (position < 0 || position >= Count)
+ {
+ return -1;
+ }
+
+ if (_collection[position] != null)
+ {
+ bool pushed = false;
+ for (int index = position + 1; index < Count; index++)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+
+ if (!pushed)
+ {
+ for (int index = position - 1; index >= 0; index--)
+ {
+ if (_collection[index] == null)
+ {
+ position = index;
+ pushed = true;
+ break;
+ }
+ }
+ }
+
+ if (!pushed)
+ {
+ return position;
+ }
+ }
+
+ _collection[position] = obj;
+ return position;
+ }
+
+ public T? Remove(int position)
+ {
+ if (position < 0 || position >= Count)
{
return null;
}
- return _collection[position];
- }
-
- public bool Insert(T obj)
- {
- for (int i = 0; i < _collection.Length; i++)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return true;
- }
- }
- return false;
- }
-
- public bool Insert(T obj, int position)
- {
- for (int i = position; i < Count; i++)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return false;
- }
- }
- for (int i = position - 1; i >= 0; --i)
- {
- if (_collection[i] == null)
- {
- _collection[i] = obj;
- return true;
- }
- }
- return false;
- }
- public bool Remove(int position)
- {
- if (position < 0 || position >= _collection.Length)
- {
- return false;
- }
+ if (_collection[position] == null) return null;
+ T? temp = _collection[position];
_collection[position] = null;
- return true;
+ return temp;
}
}
diff --git a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs
index 745fcff..c082092 100644
--- a/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs
+++ b/ProjectAirFighter/ProjectAirFighter/Drawnings/DrawningAirFighter.cs
@@ -16,7 +16,7 @@ public class DrawningAirFighter : DrawningAirCraft
/// Дополнительный цвет
/// Признак наличия ПГО
/// Признак наличия ракет
- public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(76, 80)
+ public DrawningAirFighter(int speed, double weight, Color bodyColor, Color additionalColor, bool pgo, bool rockets) : base(66, 74)
{
EntityAirCraft = new EntityAirFighter(speed, weight, bodyColor, additionalColor, pgo, rockets);
}
diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs
index abc1f07..0df1b57 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.Designer.cs
@@ -118,7 +118,7 @@
buttonAddAirCraft.Name = "buttonAddAirCraft";
buttonAddAirCraft.Size = new Size(186, 49);
buttonAddAirCraft.TabIndex = 1;
- buttonAddAirCraft.Text = "Добавление самолёта";
+ buttonAddAirCraft.Text = "Добавление военного самолёта";
buttonAddAirCraft.UseVisualStyleBackColor = true;
buttonAddAirCraft.Click += ButtonAddAirCraft_Click;
//
@@ -127,7 +127,7 @@
comboBoxSelectorCompany.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
comboBoxSelectorCompany.DropDownStyle = ComboBoxStyle.DropDownList;
comboBoxSelectorCompany.FormattingEnabled = true;
- comboBoxSelectorCompany.Items.AddRange(new object[] { "Хранилище" });
+ comboBoxSelectorCompany.Items.AddRange(new object[] { "Ангар" });
comboBoxSelectorCompany.Location = new Point(17, 26);
comboBoxSelectorCompany.Name = "comboBoxSelectorCompany";
comboBoxSelectorCompany.Size = new Size(186, 28);
diff --git a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs
index 1209648..6906aa9 100644
--- a/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs
+++ b/ProjectAirFighter/ProjectAirFighter/FormAirCraftCollection.cs
@@ -30,8 +30,8 @@ public partial class FormAirCraftCollection : Form
{
switch (comboBoxSelectorCompany.Text)
{
- case "Хранилище":
- _company = new AirCraftSharingService(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
+ case "Ангар":
+ _company = new AirCraftAngar(pictureBox.Width, pictureBox.Height, new MassiveGenericObjects());
break;
}
}
@@ -79,14 +79,14 @@ public partial class FormAirCraftCollection : Form
return;
}
- if (_company + drawningAirCraft)
+ if (_company + drawningAirCraft != -1)
{
MessageBox.Show("Объект добавлен");
pictureBox.Image = _company.Show();
}
else
{
- MessageBox.Show("Не удалось добавить объект");
+ _ = MessageBox.Show(drawningAirCraft.ToString());
}
}
@@ -125,7 +125,7 @@ public partial class FormAirCraftCollection : Form
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_company - pos)
+ if (_company - pos != null)
{
MessageBox.Show("Объект удален");
pictureBox.Image = _company.Show();