PIbd-21_Potapov_N.S._Stormt.../ProjectStormtrooper/ExtensionDrawingPlane.java

46 lines
1.6 KiB
Java
Raw Normal View History

package ProjectStormtrooper;
import java.awt.*;
public class ExtensionDrawingPlane {
public static DrawingPlane CreateDrawingPlane(String info, String separatorForObject, int width, int height) {
String[] strs = info.split(separatorForObject);
if (strs.length == 3)
{
return new DrawingPlane(
Integer.parseInt(strs[0]),
Integer.parseInt(strs[1]),
Color.getColor(strs[2]),
width, height
);
}
if (strs.length == 6)
{
return new DrawingStormtrooper(
Integer.parseInt(strs[0]),
Integer.parseInt(strs[1]),
Color.getColor(strs[2]),
Color.getColor(strs[3]),
Boolean.parseBoolean(strs[4]),
Boolean.parseBoolean(strs[5]),
width, height
);
}
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.toString();
if (!(plane instanceof EntityStormtrooper stormtrooper))
{
return str;
}
return str + separatorForObject + stormtrooper.AdditionalColor + separatorForObject + stormtrooper.Bombs + separatorForObject + stormtrooper.Rockets;
}
}