From 1812efd16ec14d86fb1db8caebe1e94f4fabe9f0 Mon Sep 17 00:00:00 2001 From: Danila_Mochalov Date: Sat, 19 Nov 2022 12:51:23 +0400 Subject: [PATCH] =?UTF-8?q?=D0=A1=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D1=8B=20?= =?UTF-8?q?=D0=BC=D0=B5=D1=82=D0=BE=D0=B4=D1=8B=20=D0=B2=20DrawningLocomot?= =?UTF-8?q?ive=20=D0=B4=D0=BB=D1=8F=20=D1=81=D0=BE=D1=85=D1=80=D0=B0=D0=BD?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=B0=D0=BD=D0=BD=D1=8B=D1=85?= =?UTF-8?q?=20=D0=BE=D0=B1=20=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B5=20?= =?UTF-8?q?=D0=B8=20=D0=B7=D0=B0=D0=B3=D1=80=D1=83=D0=B7=D0=BA=D0=B8=20?= =?UTF-8?q?=D0=BE=D0=B1=D1=8A=D0=B5=D0=BA=D1=82=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DrawningLocomotive.java | 53 ++++++++++++++++++++++++++++++++++++++++ ExtraRoundWheelDraw.java | 9 +++++++ ExtraStarWheelDraw.java | 10 ++++++++ ExtraWheelsDraw.java | 10 ++++++++ IDrawningExtra.java | 2 ++ 5 files changed, 84 insertions(+) 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(); }