From 29ba58c11aa92551bae758f12b3494135c6a2867 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sun, 20 Nov 2022 20:37:09 +0400 Subject: [PATCH] =?UTF-8?q?=D0=98=D0=B7=D0=BC=D0=B5=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B0=20=D1=81=D1=82=D1=80=D1=83=D0=BA=D1=82=D1=83=D1=80=D0=B0?= =?UTF-8?q?=20=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BA=D0=B0=D1=80=D1=82?= =?UTF-8?q?=D1=8B=20=D0=9B=D0=B0=D0=B1=D0=B0=206=20=D1=85=D0=B0=D1=80?= =?UTF-8?q?=D0=B4=20=D0=B3=D0=BE=D1=82=D0=BE=D0=B2=D0=B0,=20=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B0=D0=BB=D0=BE=D1=81=D1=8C=20=D0=BF=D0=BE=D0=B8=D1=81?= =?UTF-8?q?=D0=BA=D0=B0=D1=82=D1=8C=20=D0=B1=D0=B0=D0=B3=D0=B8=20=D0=B8=20?= =?UTF-8?q?=D0=BF=D0=BE=D1=87=D0=B8=D1=81=D1=82=D0=B8=D1=82=D1=8C=20=D0=BA?= =?UTF-8?q?=D0=BE=D0=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- MapsCollection.java | 29 +++++++++++++++++++---------- SetLocomotivesGeneric.java | 4 ++++ 2 files changed, 23 insertions(+), 10 deletions(-) diff --git a/MapsCollection.java b/MapsCollection.java index 1459e92..0c666b0 100644 --- a/MapsCollection.java +++ b/MapsCollection.java @@ -80,7 +80,11 @@ public class MapsCollection { } try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { bw.write("SingleMap\n"); - bw.write("" + map_name + separatorDict +map.GetData(separatorDict.charAt(0), separatorData) + "\n"); + bw.write("" + map_name + "\n"); + bw.write("" + map.getClass() + "\n"); + for (var locomotive : map._setLocomotives.GetLocomotives()) { + bw.write("" + locomotive.getInfo() + "\n"); + } } catch (IOException ex) { System.out.println(ex.getMessage()); @@ -101,16 +105,18 @@ public class MapsCollection { if (!curLine.contains("SingleMap")) { return false; } - - curLine = br.readLine(); - var elems = curLine.split(separatorDict); - if (_mapStorages.containsKey(elems[0])) { - _mapStorages.get(elems[0])._setLocomotives.Clear(); - _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); + String mapName = br.readLine(); + String mapClass = br.readLine(); + if (_mapStorages.containsKey(mapName)) { + _mapStorages.get(mapName)._setLocomotives.Clear(); + while((curLine = br.readLine()) != null) { + _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); + } + _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); return true; } AbstractMap map = null; - switch (elems[1]) + switch (mapClass) { case "class SimpleMap": map = new SimpleMap(); @@ -122,8 +128,11 @@ public class MapsCollection { map = new RailMap(); break; } - _mapStorages.put(elems[0], new MapWithSetLocomotivesGeneric(_pictureWidth, _pictureHeight, map)); - _mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); + _mapStorages.put(mapName, new MapWithSetLocomotivesGeneric<>(_pictureWidth, _pictureHeight, map)); + while((curLine = br.readLine()) != null) { + _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine)); + } + _mapStorages.get(mapName)._setLocomotives.ReversePlaces(); } catch (IOException ex) { System.out.println(ex.getMessage()); diff --git a/SetLocomotivesGeneric.java b/SetLocomotivesGeneric.java index 9aff477..07fee4a 100644 --- a/SetLocomotivesGeneric.java +++ b/SetLocomotivesGeneric.java @@ -1,4 +1,5 @@ import java.util.ArrayList; +import java.util.Collections; public class SetLocomotivesGeneric { @@ -50,4 +51,7 @@ public class SetLocomotivesGeneric { return _places; } + public void ReversePlaces() { + Collections.reverse(_places); + } }