Исправления: добавлен вызов метода для передачи параметра количества катков #3
@ -25,10 +25,14 @@ public class DrawingArmoredCar {
|
||||
|
||||
public DrawingArmoredCar(int speed, float weight, Color bodyColor) {
|
||||
this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
|
||||
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{
|
||||
new DrawingCaterpillar(bodyColor),
|
||||
new DrawingCrossCaterpillar(bodyColor),
|
||||
new DrawingDoubleCaterpillar(bodyColor)};
|
||||
Random r = new Random();
|
||||
IDrawingCaterpillar[] realisations = new IDrawingCaterpillar[]{new DrawingCaterpillar(r.nextInt(4, 7), bodyColor),
|
||||
new DrawingCrossCaterpillar(r.nextInt(4, 7), bodyColor), new DrawingDoubleCaterpillar(r.nextInt(4, 7), bodyColor)};
|
||||
int num = r.nextInt(4, 7);
|
||||
this.drawingCaterpillar = realisations[r.nextInt(3)];
|
||||
drawingCaterpillar.setNumRinks(num);
|
||||
}
|
||||
|
||||
protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) {
|
||||
|
@ -4,11 +4,10 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingCaterpillar(int n, Color color) {
|
||||
setNumRinks(n);
|
||||
public DrawingCaterpillar(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setNumRinks(int n) {
|
||||
switch (n) {
|
||||
case 4 -> numRinks = NumRinks.Four;
|
||||
@ -22,7 +21,7 @@ public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY)
|
||||
{
|
||||
color = color != null ? color : Color.YELLOW;
|
||||
|
@ -4,8 +4,7 @@ public class DrawingCrossCaterpillar implements IDrawingCaterpillar{
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingCrossCaterpillar(int n, Color color) {
|
||||
setNumRinks(n);
|
||||
public DrawingCrossCaterpillar(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
@ -4,8 +4,7 @@ public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
public DrawingDoubleCaterpillar(int n, Color color) {
|
||||
setNumRinks(n);
|
||||
public DrawingDoubleCaterpillar(Color color) {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user