From 86430cf93cfd14e3dc2770da12e01ecda8475fd1 Mon Sep 17 00:00:00 2001 From: "evasina2312@gmail.com" Date: Thu, 8 Dec 2022 14:06:44 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=206?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProjectMachine/MapsCollection.cs | 50 ++++++++----------- 1 file changed, 20 insertions(+), 30 deletions(-) diff --git a/ProjectMachine/ProjectMachine/MapsCollection.cs b/ProjectMachine/ProjectMachine/MapsCollection.cs index 0d1235b..0d56a23 100644 --- a/ProjectMachine/ProjectMachine/MapsCollection.cs +++ b/ProjectMachine/ProjectMachine/MapsCollection.cs @@ -122,41 +122,31 @@ namespace ProjectMachine { return false; } - string bufferTextFromFile = ""; - using (FileStream fs = new(filename, FileMode.Open)) + using (StreamReader f = new(filename)) { - byte[] b = new byte[fs.Length]; - UTF8Encoding temp = new(true); - while (fs.Read(b, 0, b.Length) > 0) + if (!f.ReadLine().Contains("MapsCollection")) { - bufferTextFromFile += temp.GetString(b); + //если нет такой записи, то это не те данные + throw new Exception("Формат данных в файле не правильный"); } - } - 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 (!f.EndOfStream) { - case "SimpleMap": - map = new SimpleMap(); - break; - case "TownMap": - map = new TownMap(); - break; + var elem = f.ReadLine().Split(separatorDict); + AbstractMap map = null; + switch (elem[1]) + { + case "SimpleMap": + map = new SimpleMap(); + break; + case "TownMap": + map = new TownMap(); + break; + } + _mapStorages.Add(elem[0], new MapWithSetTankGeneric(_pictureWidth, _pictureHeight, map)); + _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData, StringSplitOptions.RemoveEmptyEntries)); } - _mapStorages.Add(elem[0], new - MapWithSetTankGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages[elem[0]].LoadData(elem[2].Split(separatorData,StringSplitOptions.RemoveEmptyEntries)); } return true; }