Изменена структура файла сохранения карты

Лаба 6 хард готова, осталось поискать баги и почистить код
This commit is contained in:
Данила Мочалов 2022-11-20 20:37:09 +04:00
parent f329788ce7
commit 29ba58c11a
2 changed files with 23 additions and 10 deletions

View File

@ -80,7 +80,11 @@ public class MapsCollection {
} }
try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { try(BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) {
bw.write("SingleMap\n"); 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) { catch (IOException ex) {
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());
@ -101,16 +105,18 @@ public class MapsCollection {
if (!curLine.contains("SingleMap")) { if (!curLine.contains("SingleMap")) {
return false; return false;
} }
String mapName = br.readLine();
curLine = br.readLine(); String mapClass = br.readLine();
var elems = curLine.split(separatorDict); if (_mapStorages.containsKey(mapName)) {
if (_mapStorages.containsKey(elems[0])) { _mapStorages.get(mapName)._setLocomotives.Clear();
_mapStorages.get(elems[0])._setLocomotives.Clear(); while((curLine = br.readLine()) != null) {
_mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); _mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine));
}
_mapStorages.get(mapName)._setLocomotives.ReversePlaces();
return true; return true;
} }
AbstractMap map = null; AbstractMap map = null;
switch (elems[1]) switch (mapClass)
{ {
case "class SimpleMap": case "class SimpleMap":
map = new SimpleMap(); map = new SimpleMap();
@ -122,8 +128,11 @@ public class MapsCollection {
map = new RailMap(); map = new RailMap();
break; break;
} }
_mapStorages.put(elems[0], new MapWithSetLocomotivesGeneric<IDrawningObject, AbstractMap>(_pictureWidth, _pictureHeight, map)); _mapStorages.put(mapName, new MapWithSetLocomotivesGeneric<>(_pictureWidth, _pictureHeight, map));
_mapStorages.get(elems[0]).LoadData(elems[2].split(Character.toString(separatorData))); while((curLine = br.readLine()) != null) {
_mapStorages.get(mapName)._setLocomotives.Insert(DrawningObjectLocomotive.Create(curLine));
}
_mapStorages.get(mapName)._setLocomotives.ReversePlaces();
} catch (IOException ex) { } catch (IOException ex) {
System.out.println(ex.getMessage()); System.out.println(ex.getMessage());

View File

@ -1,4 +1,5 @@
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
public class SetLocomotivesGeneric <T> public class SetLocomotivesGeneric <T>
{ {
@ -50,4 +51,7 @@ public class SetLocomotivesGeneric <T>
{ {
return _places; return _places;
} }
public void ReversePlaces() {
Collections.reverse(_places);
}
} }