package ProjectStormtrooper; import java.awt.*; import java.util.Objects; public class ExtensionDrawingPlane { public static DrawingPlane CreateDrawingPlane(String info, String separatorForObject, int width, int height) { String[] strs = info.split(separatorForObject); if (strs.length == 7) { DrawingPlane drawingPlane = new DrawingPlane( Integer.parseInt(strs[0]), Double.parseDouble(strs[1]), new Color( Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4]) ), width, height ); if (Objects.equals(strs[5], "DrawingEnginesSimple")) { drawingPlane._drawingEngines = new DrawingEnginesSimple(); } else if (Objects.equals(strs[5], "DrawingEnginesPyramid")) { drawingPlane._drawingEngines = new DrawingEnginesPyramid(); } else if (Objects.equals(strs[5], "DrawingEnginesEllipse")) { drawingPlane._drawingEngines = new DrawingEnginesEllipse(); } drawingPlane.SetEnginesCount(Integer.parseInt(strs[6])); return drawingPlane; } if (strs.length == 12) { DrawingPlane drawingPlane = new DrawingStormtrooper( Integer.parseInt(strs[0]), Double.parseDouble(strs[1]), new Color( Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4]) ), new Color( Integer.parseInt(strs[7]), Integer.parseInt(strs[8]), Integer.parseInt(strs[9]) ), Boolean.parseBoolean(strs[10]), Boolean.parseBoolean(strs[11]), width, height ); if (Objects.equals(strs[5], "DrawingEnginesSimple")) { drawingPlane._drawingEngines = new DrawingEnginesSimple(); } else if (Objects.equals(strs[5], "DrawingEnginesPyramid")) { drawingPlane._drawingEngines = new DrawingEnginesPyramid(); } else if (Objects.equals(strs[5], "DrawingEnginesEllipse")) { drawingPlane._drawingEngines = new DrawingEnginesEllipse(); } drawingPlane.SetEnginesCount(Integer.parseInt(strs[6])); return drawingPlane; } return null; } public static String GetDataForSave(DrawingPlane drawingPlane, String separatorForObject) { var plane = drawingPlane.EntityPlane; if (plane == null) { return ""; } String str = plane.Speed + separatorForObject + plane.Weight + separatorForObject + plane.BodyColor.getRed() + separatorForObject + plane.BodyColor.getGreen() + separatorForObject + plane.BodyColor.getBlue() + separatorForObject + (drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "null" : drawingPlane._drawingEngines.getClass()) + separatorForObject + (drawingPlane._drawingEngines.GetEnumEnginesCount() == null ? "0" : drawingPlane._drawingEngines.GetEnumEnginesCount().count); if (!(plane instanceof EntityStormtrooper stormtrooper)) { return str; } return str + separatorForObject + stormtrooper.AdditionalColor.getRed() + separatorForObject + stormtrooper.AdditionalColor.getGreen() + separatorForObject + stormtrooper.AdditionalColor.getBlue() + separatorForObject + stormtrooper.Bombs + separatorForObject + stormtrooper.Rockets; } }