From 31b12793cdc12f146529f71c312daac32d687af2 Mon Sep 17 00:00:00 2001 From: "d.agil" Date: Wed, 2 Nov 2022 13:02:42 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA?= =?UTF-8?q?=D0=B0=20=D0=BA=D0=B0=D1=80=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AirBomber/MapWithSetAirplanesGeneric.cs | 5 ++ AirBomber/AirBomber/MapsCollection.cs | 46 ++++++++++--------- AirBomber/AirBomber/SetAirplanesGeneric.cs | 5 ++ 3 files changed, 35 insertions(+), 21 deletions(-) diff --git a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs index caeeeae..387b58d 100644 --- a/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/MapWithSetAirplanesGeneric.cs @@ -180,6 +180,11 @@ namespace AirBomber } } + public void Clear() + { + SetAirplanes.Clear(); + } + /// /// Получение данных в виде строки /// diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index 5b23807..acc92a8 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -140,7 +140,14 @@ namespace AirBomber map = new WallMap(); break; } - _mapStorages[nameMapStorage] = new(_pictureWidth, _pictureHeight, map); + if (_mapStorages.ContainsKey(nameMapStorage)) + { + _mapStorages[nameMapStorage].Clear(); + } + else + { + _mapStorages[nameMapStorage] = new(_pictureWidth, _pictureHeight, map); + } _mapStorages[nameMapStorage].LoadData(lineData.Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } @@ -154,32 +161,29 @@ namespace AirBomber { throw new FileNotFoundException("Файл не найден"); } - List strs = new List(); using (StreamReader fs = new(filename)) { + var formatData = fs.ReadLine() ?? string.Empty; + bool isNotMapsCollection = !formatData.Contains("MapsCollection"); + if (formatData.Contains("Map") && isNotMapsCollection) + { + var nameMap = fs.ReadLine().Replace("Name: ", ""); + var elem = fs.ReadLine().Split(separatorDict); + LoadMap(nameMap, elem[0], elem[1]); + } + if (isNotMapsCollection) + { + //если нет такой записи, то это не те данные + throw new FileFormatException("Формат данных в файле не правильный"); + } + //очищаем записи + _mapStorages.Clear(); while (!fs.EndOfStream) { - strs.Add(fs.ReadLine()); + var elem = fs.ReadLine().Split(separatorDict); + LoadMap(elem[0], elem[1], elem[2]); } } - bool isNotMapsCollection = !strs[0].Contains("MapsCollection"); - if (strs[0].Contains("Map") && isNotMapsCollection) - { - var elem = strs[2].Split(separatorDict); - LoadMap(strs[1].Replace("Name: ", ""), elem[0], elem[1]); - } - else if (isNotMapsCollection) - { - //если нет такой записи, то это не те данные - throw new FileFormatException("Формат данных в файле не правильный"); - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Count; ++i) - { - var elem = strs[i].Split(separatorDict); - LoadMap(elem[0], elem[1], elem[2]); - } } } } diff --git a/AirBomber/AirBomber/SetAirplanesGeneric.cs b/AirBomber/AirBomber/SetAirplanesGeneric.cs index 2830350..69c97ee 100644 --- a/AirBomber/AirBomber/SetAirplanesGeneric.cs +++ b/AirBomber/AirBomber/SetAirplanesGeneric.cs @@ -113,5 +113,10 @@ namespace AirBomber } } + + public void Clear() + { + _places.Clear(); + } } }