77 lines
3.5 KiB
Java
77 lines
3.5 KiB
Java
import java.awt.*;
|
|
|
|
public class ExtentionDrawingTanker {
|
|
public static DrawTanker CreateDrawingTanker(String info, String separatorForObject, int width, int height)
|
|
{
|
|
String[] strs = info.split(separatorForObject);
|
|
if (strs.length == 5)
|
|
{
|
|
String[] colorValues = strs[2].split(",");
|
|
|
|
DrawTanker drawTanker = new DrawTanker(Integer.parseInt(strs[0]), (double)Integer.parseInt(strs[1]),
|
|
new Color(
|
|
Integer.parseInt(colorValues[0].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues[1].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues[2].replaceAll("\\D", ""))
|
|
),
|
|
width, height,
|
|
Integer.parseInt(strs[4]));
|
|
try{
|
|
drawTanker.wheelsDrawing = (IWheelDraw)Class.forName(strs[3]).getDeclaredConstructor().newInstance();
|
|
drawTanker.wheelsDrawing.setWheelCount(Integer.parseInt(strs[4]));
|
|
}
|
|
catch(Exception e){
|
|
return null;
|
|
}
|
|
return drawTanker;
|
|
}
|
|
if (strs.length == 9)
|
|
{
|
|
String[] colorValues = strs[2].split(",");
|
|
String[] colorValues2 = strs[5].split(",");
|
|
DrawGasolineTanker drawGasoline = new DrawGasolineTanker(
|
|
Integer.parseInt(strs[0]),
|
|
(double)Integer.parseInt(strs[1]),
|
|
new Color(
|
|
Integer.parseInt(colorValues[0].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues[1].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues[2].replaceAll("\\D", ""))
|
|
),
|
|
new Color(
|
|
Integer.parseInt(colorValues2[0].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues2[1].replaceAll("\\D", "")),
|
|
Integer.parseInt(colorValues2[2].replaceAll("\\D", ""))
|
|
),
|
|
strs[6].equals("true"),
|
|
strs[7].equals("true"),
|
|
strs[8].equals("true"),
|
|
width, height,
|
|
Integer.parseInt(strs[4]));
|
|
try{
|
|
drawGasoline.wheelsDrawing = (IWheelDraw)Class.forName(strs[3]).getDeclaredConstructor().newInstance();
|
|
drawGasoline.wheelsDrawing.setWheelCount(Integer.parseInt(strs[4]));
|
|
}
|
|
catch(Exception e){
|
|
return null;
|
|
}
|
|
return drawGasoline;
|
|
}
|
|
return null;
|
|
}
|
|
public static String GetDataForSave(DrawTanker drawningTanker, String separatorForObject)
|
|
{
|
|
BaseTanker tanker = drawningTanker.GasolineTanker;
|
|
if (tanker == null)
|
|
{
|
|
return null;
|
|
}
|
|
String str = "" + tanker.getSpeed() + separatorForObject + (int)tanker.getWeight() + separatorForObject + tanker.getBodyColor() + separatorForObject + drawningTanker.wheelsDrawing.getClass().getName() + separatorForObject + drawningTanker.wheelsDrawing.getWheelCount();
|
|
if (!(tanker instanceof GasolineTanker))
|
|
{
|
|
return str;
|
|
}
|
|
return str+separatorForObject+((GasolineTanker)tanker).GetAdditionalColor().toString()+separatorForObject+((GasolineTanker)tanker).GetBodyKit()+separatorForObject+((GasolineTanker)tanker).GetWing()+separatorForObject+((GasolineTanker)tanker).GetSportLine();
|
|
}
|
|
|
|
}
|