diff --git a/AirBomber/AirBomber/MapsCollection.cs b/AirBomber/AirBomber/MapsCollection.cs index 7ba6aa9..c9aaea7 100644 --- a/AirBomber/AirBomber/MapsCollection.cs +++ b/AirBomber/AirBomber/MapsCollection.cs @@ -110,39 +110,34 @@ namespace AirBomber { throw new FileNotFoundException("Файл не найден"); } - List strs = new List(); using (StreamReader fs = new(filename)) { + if (!fs.ReadLine().Contains("MapsCollection")) + { + //если нет такой записи, то это не те данные + throw new FileFormatException("Формат данных в файле не правильный"); + } + //очищаем записи + _mapStorages.Clear(); while (!fs.EndOfStream) { - strs.Add(fs.ReadLine()); + var elem = fs.ReadLine().Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "WallMap": + map = new WallMap(); + break; + } + _mapStorages.Add(elem[0], new + MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, + StringSplitOptions.RemoveEmptyEntries)); } } - if (!strs[0].Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - throw new FileFormatException("Формат данных в файле не правильный"); - } - //очищаем записи - _mapStorages.Clear(); - for (int i = 1; i < strs.Count; ++i) - { - var elem = strs[i].Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) - { - case "SimpleMap": - map = new SimpleMap(); - break; - case "WallMap": - map = new WallMap(); - break; - } - _mapStorages.Add(elem[0], new - MapWithSetAirplanesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, - StringSplitOptions.RemoveEmptyEntries)); - } } } }