Mochalov D.V. Hard LabWork06 #6
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user