diff --git a/WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs b/WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs index 9788743..54991f0 100644 --- a/WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs +++ b/WarmlyLocomotive/WarmlyLocomotive/MapsCollection.cs @@ -123,43 +123,31 @@ namespace WarmlyLocomotive } using (StreamReader sr = new(filename)) { - bool isFirst = true; - string str; - while((str = sr.ReadLine()) != null) + string str = sr.ReadLine(); + if (!str.Contains("MapsCollection")) { - if (isFirst) + //если нет такой записи, то это не те данные + return false; + } + _mapStorages.Clear(); + while ((str = sr.ReadLine()) != null) + { + var elem = str.Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) { - if (!str.Contains("MapsCollection")) - { - //если нет такой записи, то это не те данные - return false; - } - else - { - //очищаем записи - _mapStorages.Clear(); - } - isFirst = false; - } - else - { - var elem = str.Split(separatorDict); - AbstractMap map = null; - switch (elem[1]) - { - case "SimpleMap": - map = new SimpleMap(); - break; - case "BigBarriersMap": - map = new BigBarriersMap(); - break; - case "CirclesMap": - map = new CirclesMap(); - break; - } - _mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); + case "SimpleMap": + map = new SimpleMap(); + break; + case "BigBarriersMap": + map = new BigBarriersMap(); + break; + case "CirclesMap": + map = new CirclesMap(); + break; } + _mapStorages.Add(elem[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } } return true;