diff --git a/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs index 0b186b6..7c3bdc8 100644 --- a/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs +++ b/WarPlanes/WarPlanes/DrawningObjectWarPlane.cs @@ -28,7 +28,7 @@ void IDrawningObject.DrawningObject(Graphics g) { - _warplane.DrawTransport(g); + _warplane?.DrawTransport(g); } public string GetInfo() => _warplane?.GetDataForSave(); diff --git a/WarPlanes/WarPlanes/ExtentionWarPlane.cs b/WarPlanes/WarPlanes/ExtentionWarPlane.cs index a391048..113fb16 100644 --- a/WarPlanes/WarPlanes/ExtentionWarPlane.cs +++ b/WarPlanes/WarPlanes/ExtentionWarPlane.cs @@ -22,7 +22,7 @@ return new DrawningWarPlane(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2])); } - if (strs.Length == 7) + if (strs.Length == 6) { return new DrawningFighter(Convert.ToInt32(strs[0]), Convert.ToInt32(strs[1]), Color.FromName(strs[2]), @@ -44,7 +44,7 @@ { return str; } - return $"{str}{_separatorForObject}{Fighter.DopColor.Name}{_separatorForObject}{_separatorForObject}{Fighter.Wing}{_separatorForObject}"; + return $"{str}{_separatorForObject}{Fighter.DopColor.Name}{_separatorForObject}{Fighter.Rocket}{_separatorForObject}{Fighter.Wing}"; } } } \ No newline at end of file diff --git a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs index 03348d1..13456c0 100644 --- a/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs +++ b/WarPlanes/WarPlanes/FormMapWithSetWarPlanes.cs @@ -232,17 +232,16 @@ private void LoadToolStripMenuItem_Click(object sender, EventArgs e) { - if (openFileDialog.ShowDialog() == DialogResult.OK) + if(openFileDialog.ShowDialog() == DialogResult.OK) { - try + if (_mapsCollection.LoadData(openFileDialog.FileName)) { - _mapsCollection.LoadData(openFileDialog.FileName); - MessageBox.Show("Открытие прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); + MessageBox.Show("Сохранение прошло успешно", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Information); ReloadMaps(); } - catch (Exception ex) + else { - MessageBox.Show($"Не удалось открыть: {ex.Message}", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); + MessageBox.Show("Не сохранилось", "Результат", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } diff --git a/WarPlanes/WarPlanes/MapsCollection.cs b/WarPlanes/WarPlanes/MapsCollection.cs index 7ad6e0e..edafeb7 100644 --- a/WarPlanes/WarPlanes/MapsCollection.cs +++ b/WarPlanes/WarPlanes/MapsCollection.cs @@ -10,7 +10,7 @@ namespace AirFighter /// /// Словарь (хранилище) с картами /// - readonly Dictionary> _mapStorages; + readonly Dictionary> _mapStorages; /// /// Возвращение списка названий карт /// @@ -38,7 +38,7 @@ namespace AirFighter /// public MapsCollection(int pictureWidth, int pictureHeight) { - _mapStorages = new Dictionary>(); + _mapStorages = new Dictionary>(); _pictureWidth = pictureWidth; _pictureHeight = pictureHeight; } @@ -63,9 +63,6 @@ namespace AirFighter { _mapStorages.Remove(name); } - - - /// /// Метод записи информации в файл /// @@ -87,17 +84,16 @@ namespace AirFighter { File.Delete(filename); } - using (FileStream fs = new(filename, FileMode.Create)) + using (StreamWriter fs = new(filename)) { - WriteToFile($"MapsCollection{Environment.NewLine}", fs); + fs.Write($"MapsCollection{Environment.NewLine}"); foreach (var storage in _mapStorages) { - WriteToFile($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}", fs); + fs.Write($"{storage.Key}{separatorDict}{storage.Value.GetData(separatorDict, separatorData)}{Environment.NewLine}"); } } return true; } - /// /// Загрузка нформации по самолётам на парковках из файла /// @@ -109,46 +105,40 @@ namespace AirFighter { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader fs = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + if (!fs.ReadLine().Contains("MapsCollection")) { - bufferTextFromFile += temp.GetString(b); + //если нет такой записи, то это не те данные + return false; } - } - var strs = bufferTextFromFile.Split(new char[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries); - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - return false; - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Length; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) + //очищаем записи + _mapStorages.Clear(); + while (!fs.EndOfStream) { - case "SimpleMap": - map = new SimpleMap(); - break; + var elem = fs.ReadLine().Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "CloseMap": + map = new CloseMap(); + break; + } + _mapStorages.Add(elem[0], new MapWithSetWarPlanesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } - //_mapStorages.Add(elem[0], new MapWithSetWarPlanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } return true; } - /// /// Доступ к парковке /// /// /// - public MapWithSetWarPlanesGeneric this[string ind] + public MapWithSetWarPlanesGeneric this[string ind] { get {