3. В методы работы с данными об объекте добавлены гусеницы
This commit is contained in:
parent
a051a7a3fb
commit
2f6bbea7ba
@ -38,4 +38,14 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumRinks getNumRinks() {
|
||||
return numRinks;
|
||||
}
|
||||
}
|
||||
|
@ -44,4 +44,14 @@ public class DrawingCrossCaterpillar implements IDrawingCaterpillar{
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumRinks getNumRinks() {
|
||||
return numRinks;
|
||||
}
|
||||
}
|
||||
|
@ -41,4 +41,14 @@ public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{
|
||||
public void setColor(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumRinks getNumRinks() {
|
||||
return numRinks;
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,18 @@
|
||||
import java.awt.*;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class ExtensionArmoredClass {
|
||||
private static final String _separatorForObject = ":";
|
||||
|
||||
public static DrawingArmoredCar CreateDrawingArmoredCar(String info) {
|
||||
String[] strs = info.split(_separatorForObject);
|
||||
if (strs.length == 3)
|
||||
{
|
||||
return new DrawingArmoredCar(Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), Color.decode(strs[2]));
|
||||
}
|
||||
if (strs.length == 6)
|
||||
{
|
||||
var armoredCar = new DrawingArmoredCar(Integer.parseInt(strs[0]), Integer.parseInt(strs[1]), Color.decode(strs[2]));
|
||||
armoredCar.drawingCaterpillar = CreateIDrawingCaterpillar(String.join(_separatorForObject, Arrays.copyOfRange(strs, 3, strs.length)));
|
||||
return armoredCar;
|
||||
}
|
||||
if (strs.length == 9)
|
||||
{
|
||||
return new DrawingTank(Integer.parseInt(strs[0]),
|
||||
Integer.parseInt(strs[1]), Color.decode(strs[2]),
|
||||
@ -19,20 +22,25 @@ public class ExtensionArmoredClass {
|
||||
return null;
|
||||
}
|
||||
|
||||
// public static IDrawingCaterpillar CreateIDrawingCaterpillar(String info) {
|
||||
// String[] strs = info.split(_separatorForObject);
|
||||
// switch (strs[0]) {
|
||||
// case "": {
|
||||
// break;
|
||||
// }
|
||||
// case "": {
|
||||
// break;
|
||||
// }
|
||||
// case "": {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
public static IDrawingCaterpillar CreateIDrawingCaterpillar(String info) {
|
||||
String[] strs = info.split(_separatorForObject);
|
||||
IDrawingCaterpillar caterpillar = null;
|
||||
switch (strs[0]) {
|
||||
case "DrawingCaterpillar" -> {
|
||||
caterpillar = new DrawingCaterpillar(Color.decode(strs[1]));
|
||||
caterpillar.setNumRinks(Integer.parseInt(strs[2]));
|
||||
}
|
||||
case "DrawingCrossCaterpillar" -> {
|
||||
caterpillar = new DrawingCrossCaterpillar(Color.decode(strs[1]));
|
||||
caterpillar.setNumRinks(Integer.parseInt(strs[2]));
|
||||
}
|
||||
case "DrawingDoubleCaterpillar" -> {
|
||||
caterpillar = new DrawingDoubleCaterpillar((Color.decode(strs[1])));
|
||||
caterpillar.setNumRinks(Integer.parseInt(strs[2]));
|
||||
}
|
||||
}
|
||||
return caterpillar;
|
||||
}
|
||||
|
||||
public static String GetDataForSave(DrawingArmoredCar drawingArmoredCar)
|
||||
{
|
||||
@ -41,10 +49,11 @@ public class ExtensionArmoredClass {
|
||||
(int)armoredCar.getWeight(), _separatorForObject, armoredCar.getBodyColor().getRGB());
|
||||
if (!(armoredCar instanceof EntityTank tank))
|
||||
{
|
||||
return str;
|
||||
return String.format("%s%s%s", str, _separatorForObject, GetDataForSave(drawingArmoredCar.drawingCaterpillar));
|
||||
}
|
||||
return String.format("%s%s%d%s%s%s%s", str, _separatorForObject,
|
||||
tank.getDopColor().getRGB(), _separatorForObject, tank.isTowerWeapon(), _separatorForObject, tank.isAMachineGun());
|
||||
return String.format("%s%s%d%s%s%s%s%s%s", str, _separatorForObject,
|
||||
tank.getDopColor().getRGB(), _separatorForObject, tank.isTowerWeapon(), _separatorForObject,
|
||||
tank.isAMachineGun(), _separatorForObject, GetDataForSave(drawingArmoredCar.drawingCaterpillar));
|
||||
}
|
||||
|
||||
public static String GetDataForSave(IDrawingCaterpillar drawingCaterpillar) {
|
||||
|
@ -7,4 +7,8 @@ public interface IDrawingCaterpillar {
|
||||
|
||||
void setColor(Color color);
|
||||
|
||||
Color getColor();
|
||||
|
||||
NumRinks getNumRinks();
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user