diff --git a/DrawningLocomotive.java b/DrawningLocomotive.java index 015f2ef..e20d0ca 100644 --- a/DrawningLocomotive.java +++ b/DrawningLocomotive.java @@ -150,4 +150,57 @@ public class DrawningLocomotive { { return new float[] {/*UP*/_startPosY, /*RIGHT*/ _startPosX + _locomotiveWidth, /*DOWN*/ _startPosY + _locomotiveHeight, /*LEFT*/ _startPosX}; } + + private static final char _separatorForObject = ':'; + public String getDataForSave() + { + var str = "" + Locomotive.getSpeed() + _separatorForObject + + Locomotive.getWeight() + _separatorForObject + + Locomotive.getBodyColor().getRed() + _separatorForObject + + Locomotive.getBodyColor().getGreen() + _separatorForObject + + Locomotive.getBodyColor().getBlue() + _separatorForObject + + drawningExtra.TypeString() + _separatorForObject + + drawningExtra.getWheelsCount(); + if (!(Locomotive instanceof EntityWarmlyLocomotive)) + { + return str; + } + return str + _separatorForObject + + ((EntityWarmlyLocomotive) Locomotive).ExtraColor.getRed() + _separatorForObject + + ((EntityWarmlyLocomotive) Locomotive).ExtraColor.getGreen() + _separatorForObject + + ((EntityWarmlyLocomotive) Locomotive).ExtraColor.getBlue() + _separatorForObject + + ((EntityWarmlyLocomotive) Locomotive).Pipe + _separatorForObject + + ((EntityWarmlyLocomotive) Locomotive).FuelStorage; + } + + public static DrawningLocomotive createDrawningLocomotive(String info) { + IDrawningExtra drawningExtra = null; + EntityLocomotive Locomotive = null; + String[] strs = info.split(Character.toString(_separatorForObject)); + if (strs[5] == "Simple") drawningExtra = new ExtraWheelsDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor()); + if (strs[5] == "Star") drawningExtra = new ExtraStarWheelDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor()); + if (strs[5] == "Round") drawningExtra = new ExtraRoundWheelDraw(Integer.parseInt(strs[6]), Locomotive.getBodyColor()); + if (drawningExtra == null) + if (strs.length == 7) + { + Locomotive = new EntityLocomotive( + Integer.parseInt(strs[0]), + Float.parseFloat(strs[1]), + new Color(Integer.parseInt(strs[2]), Integer.parseInt(strs[3]), Integer.parseInt(strs[4])) + ); + return new DrawningLocomotive(Locomotive, drawningExtra); + } + if (strs.length == 12) { + Locomotive = new EntityWarmlyLocomotive( + Integer.parseInt(strs[0]), + Float.parseFloat(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.getBoolean(strs[11]) + ); + return new DrawningWarmlyLocomotive(Locomotive, drawningExtra); + } + return null; + } } diff --git a/ExtraRoundWheelDraw.java b/ExtraRoundWheelDraw.java index 669ef3c..8824c27 100644 --- a/ExtraRoundWheelDraw.java +++ b/ExtraRoundWheelDraw.java @@ -19,6 +19,15 @@ public class ExtraRoundWheelDraw implements IDrawningExtra{ } } + public String TypeString() { + return "Round"; + } + public int getWheelsCount() { + if (wheelsCount == WheelsCount.Two) return 2; + if (wheelsCount == WheelsCount.Three) return 3; + else return 4; + } + public ExtraRoundWheelDraw (int num, Color bodyColor) { setExtraNum(num); extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor); diff --git a/ExtraStarWheelDraw.java b/ExtraStarWheelDraw.java index 17a8b33..a1ca0d5 100644 --- a/ExtraStarWheelDraw.java +++ b/ExtraStarWheelDraw.java @@ -19,6 +19,16 @@ public class ExtraStarWheelDraw implements IDrawningExtra{ } } + public String TypeString() { + return "Star"; + } + + public int getWheelsCount() { + if (wheelsCount == WheelsCount.Two) return 2; + if (wheelsCount == WheelsCount.Three) return 3; + else return 4; + } + public ExtraStarWheelDraw (int num, Color bodyColor) { setExtraNum(num); extraWheelsDraw = new ExtraWheelsDraw(num, bodyColor); diff --git a/ExtraWheelsDraw.java b/ExtraWheelsDraw.java index eb37d42..5af3526 100644 --- a/ExtraWheelsDraw.java +++ b/ExtraWheelsDraw.java @@ -26,6 +26,16 @@ public class ExtraWheelsDraw implements IDrawningExtra{ this.color = color; } + public String TypeString() { + return "Simple"; + } + + public int getWheelsCount() { + if (wheelsCount == WheelsCount.Two) return 2; + if (wheelsCount == WheelsCount.Three) return 3; + else return 4; + } + public void DrawExtra(int startPosX, int startPosY, Graphics2D g) { g.setColor(Color.BLACK); g.drawOval(startPosX, startPosY + 30, 20, 20); diff --git a/IDrawningExtra.java b/IDrawningExtra.java index fc9cf41..ce860f0 100644 --- a/IDrawningExtra.java +++ b/IDrawningExtra.java @@ -4,4 +4,6 @@ public interface IDrawningExtra { void setExtraNum(int num); void DrawExtra(int startPosX, int startPosY, Graphics2D g); void SetColor(Color color); + String TypeString(); + int getWheelsCount(); }