diff --git a/ProjectPlane/ProjectPlane/DrawingWarPlane.cs b/ProjectPlane/ProjectPlane/DrawingWarPlane.cs
index 7dfe2d2..becfa64 100644
--- a/ProjectPlane/ProjectPlane/DrawingWarPlane.cs
+++ b/ProjectPlane/ProjectPlane/DrawingWarPlane.cs
@@ -11,21 +11,20 @@ namespace ProjectPlane
///
/// Инициализация свойств
///
- /// Скорость
- /// Вес автомобиля
- /// Цвет кузова
+ /// Скорость
+ /// Вес самолета
+ /// Цвет корпуса
/// Дополнительный цвет
- /// Признак наличия обвеса
- /// Признак наличия антикрыла
- /// Признак наличия гоночной полосы
- public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool isBomber, bool isFighter, bool superTurbine) :
+ /// Признак наличия доп отсека
+ /// Признак наличия супертурбины
+ public DrawingWarPlane(int speed, float weight, Color bodyColor, Color dopColor, bool extraCell, bool superTurbine) :
base(speed, weight, bodyColor, 110, 60)
{
- Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, isFighter, superTurbine);
+ Plane = new EntityWarPlane(speed, weight, bodyColor, dopColor, extraCell, superTurbine);
}
+
public override void DrawTransport(Graphics g)
{
-
if (Plane is not EntityWarPlane warplane)
{
diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
index a5413d9..239d1ca 100644
--- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
+++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.Designer.cs
@@ -39,9 +39,15 @@
this.buttonShowStorage = new System.Windows.Forms.Button();
this.buttonShowOnMap = new System.Windows.Forms.Button();
this.buttonAddPlane = new System.Windows.Forms.Button();
+ this.groupBoxMaps = new System.Windows.Forms.GroupBox();
+ this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.buttonDeleteMap = new System.Windows.Forms.Button();
+ this.listBoxMaps = new System.Windows.Forms.ListBox();
+ this.ButtonAddMap = new System.Windows.Forms.Button();
this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
this.groupBoxTools.SuspendLayout();
+ this.groupBoxMaps.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.SuspendLayout();
//
@@ -56,58 +62,66 @@
this.groupBoxTools.Controls.Add(this.buttonShowStorage);
this.groupBoxTools.Controls.Add(this.buttonShowOnMap);
this.groupBoxTools.Controls.Add(this.buttonAddPlane);
- this.groupBoxTools.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxTools.Controls.Add(this.groupBoxMaps);
this.groupBoxTools.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBoxTools.Location = new System.Drawing.Point(811, 0);
+ this.groupBoxTools.Location = new System.Drawing.Point(680, 0);
this.groupBoxTools.Name = "groupBoxTools";
- this.groupBoxTools.Size = new System.Drawing.Size(204, 554);
+ this.groupBoxTools.Size = new System.Drawing.Size(204, 590);
this.groupBoxTools.TabIndex = 0;
this.groupBoxTools.TabStop = false;
this.groupBoxTools.Text = "Tools";
//
// buttonRight
//
+ this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::ProjectPlane.Properties.Resources.right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(135, 495);
+ this.buttonRight.Location = new System.Drawing.Point(133, 529);
this.buttonRight.Name = "buttonRight";
- this.buttonRight.Size = new System.Drawing.Size(48, 47);
- this.buttonRight.TabIndex = 9;
+ this.buttonRight.Size = new System.Drawing.Size(50, 49);
+ this.buttonRight.TabIndex = 14;
+ 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::ProjectPlane.Properties.Resources.down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(81, 495);
+ this.buttonDown.Location = new System.Drawing.Point(77, 529);
this.buttonDown.Name = "buttonDown";
- this.buttonDown.Size = new System.Drawing.Size(48, 47);
- this.buttonDown.TabIndex = 8;
+ this.buttonDown.Size = new System.Drawing.Size(50, 49);
+ this.buttonDown.TabIndex = 13;
+ this.buttonDown.UseVisualStyleBackColor = true;
this.buttonDown.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::ProjectPlane.Properties.Resources.left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(27, 495);
+ this.buttonLeft.Location = new System.Drawing.Point(21, 529);
this.buttonLeft.Name = "buttonLeft";
- this.buttonLeft.Size = new System.Drawing.Size(48, 47);
- this.buttonLeft.TabIndex = 7;
+ this.buttonLeft.Size = new System.Drawing.Size(50, 49);
+ this.buttonLeft.TabIndex = 12;
+ 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::ProjectPlane.Properties.Resources.up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(81, 445);
+ this.buttonUp.Location = new System.Drawing.Point(77, 472);
this.buttonUp.Name = "buttonUp";
- this.buttonUp.Size = new System.Drawing.Size(48, 47);
- this.buttonUp.TabIndex = 6;
+ this.buttonUp.Size = new System.Drawing.Size(50, 49);
+ this.buttonUp.TabIndex = 11;
+ this.buttonUp.UseVisualStyleBackColor = true;
this.buttonUp.Click += new System.EventHandler(this.ButtonMove_Click);
//
// maskedTextBoxPosition
//
- this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 166);
+ this.maskedTextBoxPosition.Location = new System.Drawing.Point(17, 320);
this.maskedTextBoxPosition.Mask = "00";
this.maskedTextBoxPosition.Name = "maskedTextBoxPosition";
this.maskedTextBoxPosition.Size = new System.Drawing.Size(175, 23);
@@ -116,7 +130,7 @@
//
// buttonRemovePlane
//
- this.buttonRemovePlane.Location = new System.Drawing.Point(17, 195);
+ this.buttonRemovePlane.Location = new System.Drawing.Point(17, 349);
this.buttonRemovePlane.Name = "buttonRemovePlane";
this.buttonRemovePlane.Size = new System.Drawing.Size(175, 35);
this.buttonRemovePlane.TabIndex = 3;
@@ -126,7 +140,7 @@
//
// buttonShowStorage
//
- this.buttonShowStorage.Location = new System.Drawing.Point(17, 287);
+ this.buttonShowStorage.Location = new System.Drawing.Point(17, 390);
this.buttonShowStorage.Name = "buttonShowStorage";
this.buttonShowStorage.Size = new System.Drawing.Size(175, 35);
this.buttonShowStorage.TabIndex = 4;
@@ -136,7 +150,7 @@
//
// buttonShowOnMap
//
- this.buttonShowOnMap.Location = new System.Drawing.Point(17, 391);
+ this.buttonShowOnMap.Location = new System.Drawing.Point(17, 431);
this.buttonShowOnMap.Name = "buttonShowOnMap";
this.buttonShowOnMap.Size = new System.Drawing.Size(175, 35);
this.buttonShowOnMap.TabIndex = 5;
@@ -146,7 +160,7 @@
//
// buttonAddPlane
//
- this.buttonAddPlane.Location = new System.Drawing.Point(17, 106);
+ this.buttonAddPlane.Location = new System.Drawing.Point(17, 279);
this.buttonAddPlane.Name = "buttonAddPlane";
this.buttonAddPlane.Size = new System.Drawing.Size(175, 35);
this.buttonAddPlane.TabIndex = 1;
@@ -154,6 +168,57 @@
this.buttonAddPlane.UseVisualStyleBackColor = true;
this.buttonAddPlane.Click += new System.EventHandler(this.ButtonAddPlane_Click);
//
+ // groupBoxMaps
+ //
+ this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
+ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
+ this.groupBoxMaps.Controls.Add(this.listBoxMaps);
+ this.groupBoxMaps.Controls.Add(this.ButtonAddMap);
+ this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxMaps.Location = new System.Drawing.Point(6, 22);
+ this.groupBoxMaps.Name = "groupBoxMaps";
+ this.groupBoxMaps.Size = new System.Drawing.Size(192, 251);
+ this.groupBoxMaps.TabIndex = 10;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Maps";
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(11, 22);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(175, 23);
+ this.textBoxNewMapName.TabIndex = 12;
+ //
+ // buttonDeleteMap
+ //
+ this.buttonDeleteMap.Location = new System.Drawing.Point(11, 206);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(175, 35);
+ this.buttonDeleteMap.TabIndex = 5;
+ this.buttonDeleteMap.Text = "Delete map";
+ this.buttonDeleteMap.UseVisualStyleBackColor = true;
+ this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
+ //
+ // listBoxMaps
+ //
+ this.listBoxMaps.FormattingEnabled = true;
+ this.listBoxMaps.ItemHeight = 15;
+ this.listBoxMaps.Location = new System.Drawing.Point(11, 121);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(175, 79);
+ this.listBoxMaps.TabIndex = 4;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
+ //
+ // ButtonAddMap
+ //
+ this.ButtonAddMap.Location = new System.Drawing.Point(11, 80);
+ this.ButtonAddMap.Name = "ButtonAddMap";
+ this.ButtonAddMap.Size = new System.Drawing.Size(175, 35);
+ this.ButtonAddMap.TabIndex = 11;
+ this.ButtonAddMap.Text = "Add map";
+ this.ButtonAddMap.UseVisualStyleBackColor = true;
+ this.ButtonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ //
// comboBoxSelectorMap
//
this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
@@ -161,18 +226,17 @@
this.comboBoxSelectorMap.Items.AddRange(new object[] {
"Simple map",
"Sky map"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 32);
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(11, 51);
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.Size = new System.Drawing.Size(680, 590);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
@@ -180,13 +244,15 @@
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(1015, 554);
+ this.ClientSize = new System.Drawing.Size(884, 590);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBoxTools);
this.Name = "FormMapWithSetPlanes";
this.Text = "Map with object sets";
this.groupBoxTools.ResumeLayout(false);
this.groupBoxTools.PerformLayout();
+ this.groupBoxMaps.ResumeLayout(false);
+ this.groupBoxMaps.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.ResumeLayout(false);
@@ -202,9 +268,14 @@
private Button buttonShowStorage;
private Button buttonRemovePlane;
private MaskedTextBox maskedTextBoxPosition;
- private Button buttonUp;
+ private GroupBox groupBoxMaps;
+ private Button ButtonAddMap;
+ private Button buttonDeleteMap;
+ private ListBox listBoxMaps;
+ private TextBox textBoxNewMapName;
private Button buttonRight;
private Button buttonDown;
private Button buttonLeft;
+ private Button buttonUp;
}
}
\ No newline at end of file
diff --git a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
index 5436a47..7bcd5fa 100644
--- a/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
+++ b/ProjectPlane/ProjectPlane/FormMapWithSetPlanes.cs
@@ -12,16 +12,56 @@ namespace ProjectPlane
{
public partial class FormMapWithSetPlanes : Form
{
+ ///
+ /// Словарь для выпадающего списка
+ ///
+ private readonly Dictionary _mapsDict = new()
+ {
+ { "Simple Map", new SimpleMap() },
+ { "Sky Map", new SkyMap() }
+ };
+ ///
+ /// Объект от коллекции карт
+ ///
+ private readonly MapsCollection _mapsCollection;
+ ///
+ /// Заполнение listBoxMaps
+ ///
+ private void ReloadMaps()
+ {
+ int index = listBoxMaps.SelectedIndex;
+
+ listBoxMaps.Items.Clear();
+ for (int i = 0; i < _mapsCollection.Keys.Count; i++)
+ {
+ listBoxMaps.Items.Add(_mapsCollection.Keys[i]);
+ }
+
+ if (listBoxMaps.Items.Count > 0 && (index == -1 || index >= listBoxMaps.Items.Count))
+ {
+ listBoxMaps.SelectedIndex = 0;
+ }
+ else if (listBoxMaps.Items.Count > 0 && index > -1 && index < listBoxMaps.Items.Count)
+ {
+ listBoxMaps.SelectedIndex = index;
+ }
+ }
///
/// Объект от класса карты с набором объектов
///
- private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric;
+ //private MapWithSetPlanesGeneric _mapPlanesCollectionGeneric = null;
///
/// Конструктор
///
public FormMapWithSetPlanes()
{
InitializeComponent();
+ _mapsCollection = new MapsCollection(pictureBox.Width, pictureBox.Height);
+ comboBoxSelectorMap.Items.Clear();
+ foreach (var elem in _mapsDict)
+ {
+ comboBoxSelectorMap.Items.Add(elem.Key);
+ }
}
///
@@ -29,29 +69,7 @@ namespace ProjectPlane
///
///
///
- private void ComboBoxSelectorMap_SelectedIndexChanged(object sender, EventArgs e)
- {
- AbstractMap map = null;
- switch (comboBoxSelectorMap.Text)
- {
- case "Simple map":
- map = new SimpleMap();
- break;
- case "Sky map":
- map = new SkyMap();
- break;
- }
- if (map != null)
- {
- _mapPlanesCollectionGeneric = new MapWithSetPlanesGeneric(
- pictureBox.Width, pictureBox.Height, map);
- }
- else
- {
- _mapPlanesCollectionGeneric = null;
- }
- }
///
/// Добавление объекта
///
@@ -59,7 +77,7 @@ namespace ProjectPlane
///
private void ButtonAddPlane_Click(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -67,10 +85,10 @@ namespace ProjectPlane
if (form.ShowDialog() == DialogResult.OK)
{
DrawingObject Plane = new(form.SelectedPlane);
- if (_mapPlanesCollectionGeneric + Plane != -1)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] + Plane != -1)
{
MessageBox.Show("Object added");
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -85,6 +103,10 @@ namespace ProjectPlane
///
private void ButtonRemovePlane_Click(object sender, EventArgs e)
{
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
if (string.IsNullOrEmpty(maskedTextBoxPosition.Text))
{
return;
@@ -94,10 +116,10 @@ namespace ProjectPlane
return;
}
int pos = Convert.ToInt32(maskedTextBoxPosition.Text);
- if (_mapPlanesCollectionGeneric - pos is not null)
+ if (_mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty] - pos != null)
{
MessageBox.Show("Object removed");
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
else
{
@@ -111,11 +133,11 @@ namespace ProjectPlane
///
private void ButtonShowStorage_Click(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowSet();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
}
///
/// Вывод карты
@@ -124,11 +146,11 @@ namespace ProjectPlane
///
private void ButtonShowOnMap_Click(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
- pictureBox.Image = _mapPlanesCollectionGeneric.ShowOnMap();
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowOnMap();
}
///
/// Перемещение
@@ -137,7 +159,7 @@ namespace ProjectPlane
///
private void ButtonMove_Click(object sender, EventArgs e)
{
- if (_mapPlanesCollectionGeneric == null)
+ if (listBoxMaps.SelectedIndex == -1)
{
return;
}
@@ -159,7 +181,51 @@ namespace ProjectPlane
dir = Direction.Right;
break;
}
- pictureBox.Image = _mapPlanesCollectionGeneric.MoveObject(dir);
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].MoveObject(dir);
}
+
+ private void ButtonAddMap_Click(object sender, EventArgs e)
+ {
+ if (comboBoxSelectorMap.SelectedIndex == -1 || string.IsNullOrEmpty(textBoxNewMapName.Text))
+ {
+ MessageBox.Show("Data is not all completed", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ if (!_mapsDict.ContainsKey(comboBoxSelectorMap.Text))
+ {
+ MessageBox.Show("This map doesn't exist", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
+ return;
+ }
+ _mapsCollection.AddMap(textBoxNewMapName.Text, _mapsDict[comboBoxSelectorMap.Text]);
+ ReloadMaps();
+ }
+ ///
+ /// Выбор карты
+ ///
+ ///
+ ///
+ private void ListBoxMaps_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ pictureBox.Image = _mapsCollection[listBoxMaps.SelectedItem?.ToString() ?? string.Empty].ShowSet();
+ }
+ ///
+ /// Удаление карты
+ ///
+ ///
+ ///
+ private void ButtonDeleteMap_Click(object sender, EventArgs e)
+ {
+ if (listBoxMaps.SelectedIndex == -1)
+ {
+ return;
+ }
+
+ if (MessageBox.Show($"Delete {listBoxMaps.SelectedItem}?", "Deleting", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
+ {
+ _mapsCollection.DelMap(listBoxMaps.SelectedItem?.ToString() ?? string.Empty);
+ ReloadMaps();
+ }
+ }
+
}
}
diff --git a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
index ddcf57b..1ded118 100644
--- a/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
+++ b/ProjectPlane/ProjectPlane/MapWithSetPlanesGeneric.cs
@@ -89,14 +89,9 @@ namespace ProjectPlane
public Bitmap ShowOnMap()
{
Shaking();
- for (int i = 0; i < _setPlanes.Count; i++)
- {
- var plane = _setPlanes.Get(i);
- if (plane != null)
- {
- return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
- }
- }
+ foreach (var plane in _setPlanes.GetPlanes())
+ return _map.CreateMap(_pictureWidth, _pictureHeight, plane);
+
return new(_pictureWidth, _pictureHeight);
}
///
@@ -120,11 +115,11 @@ namespace ProjectPlane
int j = _setPlanes.Count - 1;
for (int i = 0; i < _setPlanes.Count; i++)
{
- if (_setPlanes.Get(i) == null)
+ if (_setPlanes[i] == null)
{
for (; j > i; j--)
{
- var plane = _setPlanes.Get(j);
+ var plane = _setPlanes[j];
if (plane != null)
{
_setPlanes.Insert(plane, i);
@@ -169,10 +164,10 @@ namespace ProjectPlane
int width = _pictureWidth / _placeSizeWidth - 1;
int height = _pictureHeight / _placeSizeHeight - 1;
- for (int i = 0; i < _setPlanes.Count; i++)
+ foreach (var plane in _setPlanes.GetPlanes())
{
- _setPlanes.Get(i)?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
- _setPlanes.Get(i)?.DrawingObject(g);
+ plane?.SetObject((width) * _placeSizeWidth + 10, (height) * _placeSizeHeight + 15, _pictureWidth, _pictureHeight);
+ plane?.DrawingObject(g);
if (width <= 0)
{
diff --git a/ProjectPlane/ProjectPlane/MapsCollection.cs b/ProjectPlane/ProjectPlane/MapsCollection.cs
new file mode 100644
index 0000000..bab6984
--- /dev/null
+++ b/ProjectPlane/ProjectPlane/MapsCollection.cs
@@ -0,0 +1,68 @@
+namespace ProjectPlane
+{
+ ///
+ /// Класс для хранения коллекции карт
+ ///
+ internal class MapsCollection
+ {
+ ///
+ /// Словарь (хранилище) с картами
+ ///
+ readonly Dictionary> _mapStorages;
+ ///
+ /// Возвращение списка названий карт
+ ///
+ public List Keys => _mapStorages.Keys.ToList();
+ ///
+ /// Ширина окна отрисовки
+ ///
+ private readonly int _pictureWidth;
+ ///
+ /// Высота окна отрисовки
+ ///
+ private readonly int _pictureHeight;
+ ///
+ /// Конструктор
+ ///
+ ///
+ ///
+ public MapsCollection(int pictureWidth, int pictureHeight)
+ {
+ _mapStorages = new Dictionary>();
+ _pictureWidth = pictureWidth;
+ _pictureHeight = pictureHeight;
+ }
+ ///
+ /// Добавление карты
+ ///
+ /// Название карты
+ /// Карта
+ public void AddMap(string name, AbstractMap map)
+ {
+ if (!_mapStorages.ContainsKey(name))
+ _mapStorages.Add(name, new MapWithSetPlanesGeneric(_pictureWidth, _pictureHeight, map));
+ }
+ ///
+ /// Удаление карты
+ ///
+ /// Название карты
+ public void DelMap(string name)
+ {
+ if (_mapStorages.ContainsKey(name))
+ _mapStorages.Remove(name);
+ }
+ ///
+ /// Доступ к парковке
+ ///
+ ///
+ ///
+ public MapWithSetPlanesGeneric this[string ind]
+ {
+ get
+ {
+ if (_mapStorages.ContainsKey(ind)) return _mapStorages[ind];
+ return null;
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs
index e84b88a..2f299af 100644
--- a/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs
+++ b/ProjectPlane/ProjectPlane/SetPlanesGeneric.cs
@@ -9,20 +9,22 @@ namespace ProjectPlane
internal class SetPlanesGeneric where T : class
{
///
- /// Массив объектов, которые храним
+ /// Список объектов, которые храним
///
- private readonly T[] _places;
+ private readonly List _places;
///
- /// Количество объектов в массиве
+ /// Количество объектов в списке
///
- public int Count => _places.Length;
+ public int Count => _places.Count;
+ private readonly int _maxCount;
///
/// Конструктор
///
///
public SetPlanesGeneric(int count)
{
- _places = new T[count];
+ _maxCount = count;
+ _places = new List();
}
///
/// Добавление объекта в набор
@@ -41,35 +43,8 @@ namespace ProjectPlane
///
public int Insert(T plane, int position)
{
- bool isNull = false;
- int nullElem = 0;
- if (position < 0 || position >= Count)
- {
- return -1;
- }
- if (_places[position] == null)
- {
- _places[position] = plane;
- return position;
- }
- for (int i = position + 1; i < Count; i ++)
- {
- if (_places[i] == null)
- {
- isNull = true;
- nullElem = i;
- break;
- }
- }
- if (!isNull)
- {
- return -1;
- }
- for (int i = nullElem; i > position; i--)
- {
- _places[i] = _places[i - 1];
- }
- _places[position] = plane;
+ if (position < 0 || position >= _maxCount) return -1;
+ _places.Insert(position, plane);
return position;
}
///
@@ -79,12 +54,9 @@ namespace ProjectPlane
///
public T Remove(int position)
{
- if (position < 0 || position >= Count)
- {
- return null;
- }
+ if (position < 0 || position >= _maxCount) return null;
T temp = _places[position];
- _places[position] = null;
+ _places.RemoveAt(position);
return temp;
}
///
@@ -92,13 +64,40 @@ namespace ProjectPlane
///
///
///
- public T Get(int position)
+ public T this[int position]
{
- if (position < 0 || position >= Count)
+ get
{
- return null;
+ if (position < 0 || position >= _maxCount)
+ return null;
+
+ return _places[position];
+ }
+ set
+ {
+ if (position < 0 || position >= _maxCount)
+ return;
+
+ Insert(value, position);
+ }
+ }
+ ///
+ /// Проход по набору до первого пустого
+ ///
+ ///
+ public IEnumerable GetPlanes()
+ {
+ foreach (var plane in _places)
+ {
+ if (plane != null)
+ {
+ yield return plane;
+ }
+ else
+ {
+ yield break;
+ }
}
- return _places[position];
}
}
}