diff --git a/AirFighter/AirFighter/DrawningObjectAirFighter.cs b/AirFighter/AirFighter/DrawningObjectAirFighter.cs
index 3e5f997..4b73d56 100644
--- a/AirFighter/AirFighter/DrawningObjectAirFighter.cs
+++ b/AirFighter/AirFighter/DrawningObjectAirFighter.cs
@@ -34,5 +34,9 @@ namespace AirFighter
{
_airFighter?.SetPosition(x, y, width, height);
}
+
+ public string GetInfo() => _airFighter?.GetDataForSave();
+
+ public static IDrawningObject Create(string data) => new DrawningObjectAirFighter(data.CreateDrawningCar());
}
}
diff --git a/AirFighter/AirFighter/ExtentionAirFighter.cs b/AirFighter/AirFighter/ExtentionAirFighter.cs
new file mode 100644
index 0000000..1b70cd8
--- /dev/null
+++ b/AirFighter/AirFighter/ExtentionAirFighter.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace AirFighter
+{
+ ///
+ /// Расширение для класса DrawningAirFighter
+ ///
+ internal static class ExtentionAirFighter
+ {
+ ///
+ /// Разделитель для записи информации по объекту в файл
+ ///
+ private static readonly char _separatorForObject = ':';
+ ///
+ /// Создание объекта из строки
+ ///
+ ///
+ ///
+ public static DrawningAirFighter CreateDrawningCar(this string info)
+ {
+ string[] strs = info.Split(_separatorForObject);
+
+ if (strs.Length == 3)
+ {
+ return new DrawningAirFighter(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]));
+ }
+ if (strs.Length == 6)
+ {
+ return new DrawningUpgradeAirFighter(Convert.ToInt32(strs[0]),
+ Convert.ToInt32(strs[1]), Color.FromName(strs[2]),
+ Color.FromName(strs[3]), Convert.ToBoolean(strs[4]),
+ Convert.ToBoolean(strs[5]));
+ }
+ return null;
+ }
+ ///
+ /// Получение данных для сохранения в файл
+ ///
+ ///
+ ///
+ public static string GetDataForSave(this DrawningAirFighter drawningAirFighter)
+ {
+ var airFighter = drawningAirFighter.AirFighter;
+ var str =
+ $"{airFighter.Speed}{_separatorForObject}{airFighter.Weight}{_separatorForObject}{airFighter.BodyColor.Name}";
+ if (airFighter is not EntityUpgradeAirFighter upgradeAirFighter)
+ {
+ return str;
+ }
+ return
+ $"{str}{_separatorForObject}{upgradeAirFighter.DopColor.Name}{_separatorForObject}{upgradeAirFighter.DopWing}{_separatorForObject}{upgradeAirFighter.Rocket}";
+ }
+
+ }
+}
diff --git a/AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs b/AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs
index 04e373c..d286579 100644
--- a/AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs
+++ b/AirFighter/AirFighter/FormMapWithSetAirFighters.Designer.cs
@@ -29,6 +29,12 @@
private void InitializeComponent()
{
this.groupBox = new System.Windows.Forms.GroupBox();
+ this.groupBoxMaps = new System.Windows.Forms.GroupBox();
+ this.buttonDeleteMap = new System.Windows.Forms.Button();
+ this.listBoxMaps = new System.Windows.Forms.ListBox();
+ this.buttonAddMap = new System.Windows.Forms.Button();
+ this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.buttonUp = new System.Windows.Forms.Button();
this.buttonDown = new System.Windows.Forms.Button();
this.buttonLeft = new System.Windows.Forms.Button();
@@ -38,16 +44,17 @@
this.buttonRemoveAirFighter = new System.Windows.Forms.Button();
this.maskedTextBoxPosition = new System.Windows.Forms.MaskedTextBox();
this.buttonAddAirFighter = new System.Windows.Forms.Button();
- this.comboBoxSelectorMap = new System.Windows.Forms.ComboBox();
this.pictureBox = new System.Windows.Forms.PictureBox();
- this.groupBoxMaps = new System.Windows.Forms.GroupBox();
- this.buttonDeleteMap = new System.Windows.Forms.Button();
- this.listBoxMaps = new System.Windows.Forms.ListBox();
- this.buttonAddMap = new System.Windows.Forms.Button();
- this.textBoxNewMapName = new System.Windows.Forms.TextBox();
+ this.menuStrip = new System.Windows.Forms.MenuStrip();
+ this.FileToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.SaveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.LoadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
+ this.openFileDialog = new System.Windows.Forms.OpenFileDialog();
+ this.saveFileDialog = new System.Windows.Forms.SaveFileDialog();
this.groupBox.SuspendLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
this.groupBoxMaps.SuspendLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).BeginInit();
+ this.menuStrip.SuspendLayout();
this.SuspendLayout();
//
// groupBox
@@ -63,19 +70,82 @@
this.groupBox.Controls.Add(this.maskedTextBoxPosition);
this.groupBox.Controls.Add(this.buttonAddAirFighter);
this.groupBox.Dock = System.Windows.Forms.DockStyle.Right;
- this.groupBox.Location = new System.Drawing.Point(732, 0);
+ this.groupBox.Location = new System.Drawing.Point(732, 28);
this.groupBox.Name = "groupBox";
- this.groupBox.Size = new System.Drawing.Size(250, 555);
+ this.groupBox.Size = new System.Drawing.Size(250, 561);
this.groupBox.TabIndex = 0;
this.groupBox.TabStop = false;
this.groupBox.Text = "Инструменты";
//
+ // groupBoxMaps
+ //
+ this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
+ this.groupBoxMaps.Controls.Add(this.listBoxMaps);
+ this.groupBoxMaps.Controls.Add(this.buttonAddMap);
+ this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
+ this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
+ this.groupBoxMaps.Location = new System.Drawing.Point(0, 12);
+ this.groupBoxMaps.Name = "groupBoxMaps";
+ this.groupBoxMaps.Size = new System.Drawing.Size(250, 278);
+ this.groupBoxMaps.TabIndex = 6;
+ this.groupBoxMaps.TabStop = false;
+ this.groupBoxMaps.Text = "Карты";
+ //
+ // buttonDeleteMap
+ //
+ this.buttonDeleteMap.Location = new System.Drawing.Point(17, 244);
+ this.buttonDeleteMap.Name = "buttonDeleteMap";
+ this.buttonDeleteMap.Size = new System.Drawing.Size(210, 29);
+ this.buttonDeleteMap.TabIndex = 4;
+ this.buttonDeleteMap.Text = "Удалить карту";
+ this.buttonDeleteMap.UseVisualStyleBackColor = true;
+ this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
+ //
+ // listBoxMaps
+ //
+ this.listBoxMaps.FormattingEnabled = true;
+ this.listBoxMaps.ItemHeight = 20;
+ this.listBoxMaps.Location = new System.Drawing.Point(17, 154);
+ this.listBoxMaps.Name = "listBoxMaps";
+ this.listBoxMaps.Size = new System.Drawing.Size(210, 84);
+ this.listBoxMaps.TabIndex = 3;
+ this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
+ //
+ // buttonAddMap
+ //
+ this.buttonAddMap.Location = new System.Drawing.Point(17, 119);
+ this.buttonAddMap.Name = "buttonAddMap";
+ this.buttonAddMap.Size = new System.Drawing.Size(210, 29);
+ this.buttonAddMap.TabIndex = 2;
+ this.buttonAddMap.Text = "Добавить карту";
+ this.buttonAddMap.UseVisualStyleBackColor = true;
+ this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ //
+ // textBoxNewMapName
+ //
+ this.textBoxNewMapName.Location = new System.Drawing.Point(17, 36);
+ this.textBoxNewMapName.Name = "textBoxNewMapName";
+ this.textBoxNewMapName.Size = new System.Drawing.Size(210, 27);
+ this.textBoxNewMapName.TabIndex = 1;
+ //
+ // comboBoxSelectorMap
+ //
+ this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
+ this.comboBoxSelectorMap.FormattingEnabled = true;
+ this.comboBoxSelectorMap.Items.AddRange(new object[] {
+ "Простая карта",
+ "Карта шторма"});
+ this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 75);
+ this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
+ this.comboBoxSelectorMap.Size = new System.Drawing.Size(210, 28);
+ this.comboBoxSelectorMap.TabIndex = 0;
+ //
// buttonUp
//
this.buttonUp.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonUp.BackgroundImage = global::AirFighter.Properties.Resources.Up;
this.buttonUp.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonUp.Location = new System.Drawing.Point(135, 475);
+ this.buttonUp.Location = new System.Drawing.Point(135, 481);
this.buttonUp.Name = "buttonUp";
this.buttonUp.Size = new System.Drawing.Size(30, 30);
this.buttonUp.TabIndex = 2;
@@ -87,7 +157,7 @@
this.buttonDown.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonDown.BackgroundImage = global::AirFighter.Properties.Resources.Down;
this.buttonDown.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonDown.Location = new System.Drawing.Point(135, 513);
+ this.buttonDown.Location = new System.Drawing.Point(135, 519);
this.buttonDown.Name = "buttonDown";
this.buttonDown.Size = new System.Drawing.Size(30, 30);
this.buttonDown.TabIndex = 3;
@@ -99,7 +169,7 @@
this.buttonLeft.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonLeft.BackgroundImage = global::AirFighter.Properties.Resources.Left;
this.buttonLeft.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonLeft.Location = new System.Drawing.Point(99, 513);
+ this.buttonLeft.Location = new System.Drawing.Point(99, 519);
this.buttonLeft.Name = "buttonLeft";
this.buttonLeft.Size = new System.Drawing.Size(30, 30);
this.buttonLeft.TabIndex = 4;
@@ -111,7 +181,7 @@
this.buttonRight.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.buttonRight.BackgroundImage = global::AirFighter.Properties.Resources.Right;
this.buttonRight.BackgroundImageLayout = System.Windows.Forms.ImageLayout.Stretch;
- this.buttonRight.Location = new System.Drawing.Point(171, 513);
+ this.buttonRight.Location = new System.Drawing.Point(171, 519);
this.buttonRight.Name = "buttonRight";
this.buttonRight.Size = new System.Drawing.Size(30, 30);
this.buttonRight.TabIndex = 5;
@@ -166,93 +236,76 @@
this.buttonAddAirFighter.UseVisualStyleBackColor = true;
this.buttonAddAirFighter.Click += new System.EventHandler(this.ButtonAddAirFighter_Click);
//
- // comboBoxSelectorMap
- //
- this.comboBoxSelectorMap.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
- this.comboBoxSelectorMap.FormattingEnabled = true;
- this.comboBoxSelectorMap.Items.AddRange(new object[] {
- "Простая карта",
- "Карта шторма"});
- this.comboBoxSelectorMap.Location = new System.Drawing.Point(17, 75);
- this.comboBoxSelectorMap.Name = "comboBoxSelectorMap";
- this.comboBoxSelectorMap.Size = new System.Drawing.Size(210, 28);
- this.comboBoxSelectorMap.TabIndex = 0;
- //
// pictureBox
//
this.pictureBox.Dock = System.Windows.Forms.DockStyle.Fill;
- this.pictureBox.Location = new System.Drawing.Point(0, 0);
+ this.pictureBox.Location = new System.Drawing.Point(0, 28);
this.pictureBox.Name = "pictureBox";
- this.pictureBox.Size = new System.Drawing.Size(732, 555);
+ this.pictureBox.Size = new System.Drawing.Size(732, 561);
this.pictureBox.TabIndex = 1;
this.pictureBox.TabStop = false;
//
- // groupBoxMaps
+ // menuStrip
//
- this.groupBoxMaps.Controls.Add(this.buttonDeleteMap);
- this.groupBoxMaps.Controls.Add(this.listBoxMaps);
- this.groupBoxMaps.Controls.Add(this.buttonAddMap);
- this.groupBoxMaps.Controls.Add(this.textBoxNewMapName);
- this.groupBoxMaps.Controls.Add(this.comboBoxSelectorMap);
- this.groupBoxMaps.Location = new System.Drawing.Point(0, 12);
- this.groupBoxMaps.Name = "groupBoxMaps";
- this.groupBoxMaps.Size = new System.Drawing.Size(250, 278);
- this.groupBoxMaps.TabIndex = 6;
- this.groupBoxMaps.TabStop = false;
- this.groupBoxMaps.Text = "Карты";
+ this.menuStrip.ImageScalingSize = new System.Drawing.Size(20, 20);
+ this.menuStrip.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.FileToolStripMenuItem});
+ this.menuStrip.Location = new System.Drawing.Point(0, 0);
+ this.menuStrip.Name = "menuStrip";
+ this.menuStrip.Size = new System.Drawing.Size(982, 28);
+ this.menuStrip.TabIndex = 2;
//
- // buttonDeleteMap
+ // FileToolStripMenuItem
//
- this.buttonDeleteMap.Location = new System.Drawing.Point(17, 244);
- this.buttonDeleteMap.Name = "buttonDeleteMap";
- this.buttonDeleteMap.Size = new System.Drawing.Size(210, 29);
- this.buttonDeleteMap.TabIndex = 4;
- this.buttonDeleteMap.Text = "Удалить карту";
- this.buttonDeleteMap.UseVisualStyleBackColor = true;
- this.buttonDeleteMap.Click += new System.EventHandler(this.ButtonDeleteMap_Click);
+ this.FileToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
+ this.SaveToolStripMenuItem,
+ this.LoadToolStripMenuItem});
+ this.FileToolStripMenuItem.Name = "FileToolStripMenuItem";
+ this.FileToolStripMenuItem.Size = new System.Drawing.Size(59, 24);
+ this.FileToolStripMenuItem.Text = "Файл";
//
- // listBoxMaps
+ // SaveToolStripMenuItem
//
- this.listBoxMaps.FormattingEnabled = true;
- this.listBoxMaps.ItemHeight = 20;
- this.listBoxMaps.Location = new System.Drawing.Point(17, 154);
- this.listBoxMaps.Name = "listBoxMaps";
- this.listBoxMaps.Size = new System.Drawing.Size(210, 84);
- this.listBoxMaps.TabIndex = 3;
- this.listBoxMaps.SelectedIndexChanged += new System.EventHandler(this.ListBoxMaps_SelectedIndexChanged);
+ this.SaveToolStripMenuItem.Name = "SaveToolStripMenuItem";
+ this.SaveToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.SaveToolStripMenuItem.Text = "Сохранение";
+ this.SaveToolStripMenuItem.Click += new System.EventHandler(this.SaveToolStripMenuItem_Click);
//
- // buttonAddMap
+ // LoadToolStripMenuItem
//
- this.buttonAddMap.Location = new System.Drawing.Point(17, 119);
- this.buttonAddMap.Name = "buttonAddMap";
- this.buttonAddMap.Size = new System.Drawing.Size(210, 29);
- this.buttonAddMap.TabIndex = 2;
- this.buttonAddMap.Text = "Добавить карту";
- this.buttonAddMap.UseVisualStyleBackColor = true;
- this.buttonAddMap.Click += new System.EventHandler(this.ButtonAddMap_Click);
+ this.LoadToolStripMenuItem.Name = "LoadToolStripMenuItem";
+ this.LoadToolStripMenuItem.Size = new System.Drawing.Size(224, 26);
+ this.LoadToolStripMenuItem.Text = "Загрузка";
+ this.LoadToolStripMenuItem.Click += new System.EventHandler(this.LoadToolStripMenuItem_Click);
//
- // textBoxNewMapName
+ // openFileDialog
//
- this.textBoxNewMapName.Location = new System.Drawing.Point(17, 36);
- this.textBoxNewMapName.Name = "textBoxNewMapName";
- this.textBoxNewMapName.Size = new System.Drawing.Size(210, 27);
- this.textBoxNewMapName.TabIndex = 1;
+ this.openFileDialog.Filter = "txt file | *.txt";
+ //
+ // saveFileDialog
+ //
+ this.saveFileDialog.Filter = "txt file | *.txt";
//
// FormMapWithSetAirFighters
//
this.AutoScaleDimensions = new System.Drawing.SizeF(8F, 20F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
- this.ClientSize = new System.Drawing.Size(982, 555);
+ this.ClientSize = new System.Drawing.Size(982, 589);
this.Controls.Add(this.pictureBox);
this.Controls.Add(this.groupBox);
+ this.Controls.Add(this.menuStrip);
+ this.MainMenuStrip = this.menuStrip;
this.Name = "FormMapWithSetAirFighters";
this.Text = "FormMapWithSetAirFighters";
this.groupBox.ResumeLayout(false);
this.groupBox.PerformLayout();
- ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
this.groupBoxMaps.ResumeLayout(false);
this.groupBoxMaps.PerformLayout();
+ ((System.ComponentModel.ISupportInitialize)(this.pictureBox)).EndInit();
+ this.menuStrip.ResumeLayout(false);
+ this.menuStrip.PerformLayout();
this.ResumeLayout(false);
+ this.PerformLayout();
}
@@ -275,5 +328,11 @@
private ListBox listBoxMaps;
private Button buttonAddMap;
private TextBox textBoxNewMapName;
+ private MenuStrip menuStrip;
+ private ToolStripMenuItem FileToolStripMenuItem;
+ private ToolStripMenuItem SaveToolStripMenuItem;
+ private ToolStripMenuItem LoadToolStripMenuItem;
+ private OpenFileDialog openFileDialog;
+ private SaveFileDialog saveFileDialog;
}
}
\ No newline at end of file
diff --git a/AirFighter/AirFighter/FormMapWithSetAirFighters.cs b/AirFighter/AirFighter/FormMapWithSetAirFighters.cs
index 616da9e..83514e4 100644
--- a/AirFighter/AirFighter/FormMapWithSetAirFighters.cs
+++ b/AirFighter/AirFighter/FormMapWithSetAirFighters.cs
@@ -229,5 +229,47 @@ namespace AirFighter
ReloadMaps();
}
}
+ ///
+ /// Обработка нажатия "Сохранение"
+ ///
+ ///
+ /// Обработка нажатия "Загрузка"
+ ///
+ ///
+ ///
+ private void LoadToolStripMenuItem_Click(object sender, EventArgs e)
+ {
+ if (openFileDialog.ShowDialog() == DialogResult.OK)
+ {
+ if (_mapsCollection.LoadData(openFileDialog.FileName))
+ {
+ MessageBox.Show("Загрузка прошла успешно", "Результат",
+ MessageBoxButtons.OK, MessageBoxIcon.Information);
+ ReloadMaps();
+ }
+ else
+ {
+ MessageBox.Show("Загрузка не удалась", "Результат",
+ MessageBoxButtons.OK, MessageBoxIcon.Error);
+ }
+ }
+ }
}
}
diff --git a/AirFighter/AirFighter/FormMapWithSetAirFighters.resx b/AirFighter/AirFighter/FormMapWithSetAirFighters.resx
index f298a7b..985a3e4 100644
--- a/AirFighter/AirFighter/FormMapWithSetAirFighters.resx
+++ b/AirFighter/AirFighter/FormMapWithSetAirFighters.resx
@@ -57,4 +57,13 @@
System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
+
+ 17, 17
+
+
+ 144, 17
+
+
+ 311, 17
+
\ No newline at end of file
diff --git a/AirFighter/AirFighter/IDrawningObject.cs b/AirFighter/AirFighter/IDrawningObject.cs
index 8f8230b..5f09481 100644
--- a/AirFighter/AirFighter/IDrawningObject.cs
+++ b/AirFighter/AirFighter/IDrawningObject.cs
@@ -37,8 +37,12 @@ namespace AirFighter
/// Получение текущей позиции объекта
///
///
- (float Left, float Right, float Top, float Bottom)
- GetCurrentPosition();
+ (float Left, float Right, float Top, float Bottom)GetCurrentPosition();
+ ///
+ /// Получение информации по объекту
+ ///
+ ///
+ string GetInfo();
}
}
diff --git a/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs b/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
index 3fc878b..47afcee 100644
--- a/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
+++ b/AirFighter/AirFighter/MapWithSetAirFightersGeneric.cs
@@ -114,6 +114,31 @@ namespace AirFighter
return new(_pictureWidth, _pictureHeight);
}
///
+ /// Получение данных в виде строки
+ ///
+ ///
+ ///
+ public string GetData(char separatorType, char separatorData)
+ {
+ string data = $"{_map.GetType().Name}{separatorType}";
+ foreach (var airFighter in _setAirFighters.GetAirFighters())
+ {
+ data += $"{airFighter.GetInfo()}{separatorData}";
+ }
+ return data;
+ }
+ ///
+ /// Загрузка списка из массива строк
+ ///
+ ///
+ public void LoadData(string[] records)
+ {
+ foreach (var rec in records)
+ {
+ _setAirFighters.Insert(DrawningObjectAirFighter.Create(rec) as T);
+ }
+ }
+ ///
/// "Взбалтываем" набор, чтобы все элементы оказались в начале
///
private void Shaking()
diff --git a/AirFighter/AirFighter/MapsCollection.cs b/AirFighter/AirFighter/MapsCollection.cs
index ff24c26..9f35ac0 100644
--- a/AirFighter/AirFighter/MapsCollection.cs
+++ b/AirFighter/AirFighter/MapsCollection.cs
@@ -14,7 +14,7 @@ namespace AirFighter
///
/// Словарь (хранилище) с картами
///
- readonly Dictionary> _mapStorages;
+ readonly Dictionary> _mapStorages;
///
/// Возвращение списка названий карт
///
@@ -24,6 +24,14 @@ namespace AirFighter
///
private readonly int _pictureWidth;
///
+ /// Разделитель для записи информации по элементу словаря в файл
+ ///
+ private readonly char separatorDict = '|';
+ ///
+ /// Разделитель для записей коллекции данных в файл
+ ///
+ private readonly char separatorData = ';';
+ ///
/// Высота окна отрисовки
///
private readonly int _pictureHeight;
@@ -34,7 +42,7 @@ namespace AirFighter
///
public MapsCollection(int pictureWidth, int pictureHeight)
{
- _mapStorages = new Dictionary>();
+ _mapStorages = new Dictionary>();
_pictureWidth = pictureWidth;
_pictureHeight = pictureHeight;
}
@@ -47,7 +55,7 @@ namespace AirFighter
{
if (!string.IsNullOrEmpty(name) && map != null && !Keys.Contains(name))
{
- _mapStorages.Add(name, new MapWithSetAirFightersGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages.Add(name, new MapWithSetAirFightersGeneric(_pictureWidth, _pictureHeight, map));
}
}
///
@@ -66,11 +74,11 @@ namespace AirFighter
///
///
///
- public MapWithSetAirFightersGeneric this[string ind]
+ public MapWithSetAirFightersGeneric this[string ind]
{
get
{
- MapWithSetAirFightersGeneric _map;
+ MapWithSetAirFightersGeneric _map;
if (_mapStorages.TryGetValue(ind, out _map))
{
return _map;
@@ -79,5 +87,69 @@ namespace AirFighter
return null;
}
}
+ ///
+ /// Сохранение информации по самолетам в хранилище в файл
+ ///
+ /// Путь и имя файла
+ ///
+ public bool SaveData(string filename)
+ {
+ if (File.Exists(filename))
+ {
+ File.Delete(filename);
+ }
+ using (StreamWriter sw = new(filename))
+ {
+ sw.Write($"MapsCollection{Environment.NewLine}");
+ foreach (var storage in _mapStorages)
+ {
+
+ sw.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}");
+ }
+ }
+ return true;
+ }
+ ///
+ /// Загрузка нформации по самолетам на парковках из файла
+ ///
+ /// param >
+ /// < returns > returns >
+ public bool LoadData(string filename)
+ {
+ if (!File.Exists(filename))
+ {
+ return false;
+ }
+ string bufferTextFromFile = "";
+ using (StreamReader sr = new(filename))
+ {
+ string checkMap = sr.ReadLine();
+ if (!checkMap.Contains("MapsCollection"))
+ {
+ return false;
+ }
+ bufferTextFromFile = sr.ReadLine();
+ _mapStorages.Clear();
+ while (bufferTextFromFile != null)
+ {
+ var strs = bufferTextFromFile.Split(separatorDict);
+ AbstractMap map = null;
+ switch (strs[1])
+ {
+ case "SimpleMap":
+ map = new SimpleMap();
+ break;
+ case "StormMap":
+ map = new StormMap();
+ break;
+ }
+ _mapStorages.Add(strs[0], new MapWithSetAirFightersGeneric(_pictureWidth, _pictureHeight, map));
+ _mapStorages[strs[0]].LoadData(strs[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries));
+ bufferTextFromFile = sr.ReadLine();
+ }
+ }
+ return true;
+ }
}
}
+