Выполнение задания с добавлением ИнтерДоп

This commit is contained in:
prodigygirl 2022-10-23 18:03:05 +04:00
parent 3db14138cd
commit a19996af00
5 changed files with 95 additions and 3 deletions

View File

@ -17,7 +17,7 @@ public class DrawingArmoredCar {
private int carHeight = 50;
protected DrawingCaterpillar drawingCaterpillar;
protected IDrawingCaterpillar drawingCaterpillar;
public EntityArmoredCar getArmoredCar() {
return armoredCar;
@ -26,7 +26,9 @@ public class DrawingArmoredCar {
public DrawingArmoredCar(int speed, float weight, Color bodyColor) {
this.armoredCar = new EntityArmoredCar(speed, weight, bodyColor);
Random r = new Random();
this.drawingCaterpillar = new DrawingCaterpillar(r.nextInt(4, 7), bodyColor);
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)};
this.drawingCaterpillar = realisations[r.nextInt(3)];
}
protected DrawingArmoredCar(int speed, float weight, Color bodyColor, int carWidth, int carHeight) {

View File

@ -1,6 +1,6 @@
import java.awt.*;
public class DrawingCaterpillar {
public class DrawingCaterpillar implements IDrawingCaterpillar {
private NumRinks numRinks = NumRinks.Four;
private Color color;

View File

@ -0,0 +1,43 @@
import java.awt.*;
public class DrawingCrossCaterpillar implements IDrawingCaterpillar{
private NumRinks numRinks = NumRinks.Four;
private Color color;
public DrawingCrossCaterpillar(int n, Color color) {
setNumRinks(n);
this.color = color;
}
@Override
public void setNumRinks(int n) {
switch (n) {
case 4 -> numRinks = NumRinks.Four;
case 5 -> numRinks = NumRinks.Five;
case 6 -> numRinks = NumRinks.Six;
default -> {
break;
}
}
}
@Override
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) {
color = color != null ? color : Color.YELLOW;
int size = numRinks == NumRinks.Four ? 15 : 10;
int dist = numRinks == NumRinks.Four ? 20 : 13;
startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX;
for (int i = 0; i < numRinks.val(); i++) {
g2d.setPaint(color);
g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size);
g2d.setColor(Color.BLACK);
g2d.setStroke(new BasicStroke(3));
g2d.drawLine(startPosX + dist * i, startPosY + 30, startPosX + dist * i + size, startPosY + 30 + size);
g2d.drawLine(startPosX + dist * i + size, startPosY + 30, startPosX + dist * i, startPosY + 30 + size);
}
}
}

View File

@ -0,0 +1,40 @@
import java.awt.*;
public class DrawingDoubleCaterpillar implements IDrawingCaterpillar{
private NumRinks numRinks = NumRinks.Four;
private Color color;
public DrawingDoubleCaterpillar(int n, Color color) {
setNumRinks(n);
this.color = color;
}
@Override
public void setNumRinks(int n) {
switch (n) {
case 4 -> numRinks = NumRinks.Four;
case 5 -> numRinks = NumRinks.Five;
case 6 -> numRinks = NumRinks.Six;
default -> {
break;
}
}
}
@Override
public void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY) {
color = color != null ? color : Color.YELLOW;
int size = numRinks == NumRinks.Four ? 15 : 10;
int dist = numRinks == NumRinks.Four ? 20 : 13;
startPosX = numRinks == NumRinks.Five ? startPosX + 5 : startPosX;
for (int i = 0; i < numRinks.val(); i++) {
g2d.setPaint(color);
g2d.fillOval(startPosX + dist * i, startPosY + 30, size, size);
g2d.setPaint(Color.WHITE);
g2d.fillOval(startPosX + dist * i + size/4, startPosY + 30 + size/4, size/2, size/2);
}
}
}

View File

@ -0,0 +1,7 @@
import java.awt.*;
public interface IDrawingCaterpillar {
void setNumRinks(int n);
void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY);
}