Borschevskaya A.A. Lab Work 2 Hard #2
@ -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) {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawingCaterpillar {
|
||||
public class DrawingCaterpillar implements IDrawingCaterpillar {
|
||||
private NumRinks numRinks = NumRinks.Four;
|
||||
private Color color;
|
||||
|
||||
|
43
src/main/java/DrawingCrossCaterpillar.java
Normal file
43
src/main/java/DrawingCrossCaterpillar.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
40
src/main/java/DrawingDoubleCaterpillar.java
Normal file
40
src/main/java/DrawingDoubleCaterpillar.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
7
src/main/java/IDrawingCaterpillar.java
Normal file
7
src/main/java/IDrawingCaterpillar.java
Normal file
@ -0,0 +1,7 @@
|
||||
import java.awt.*;
|
||||
|
||||
public interface IDrawingCaterpillar {
|
||||
void setNumRinks(int n);
|
||||
|
||||
void DrawCaterpillar(Graphics2D g2d, int startPosX, int startPosY);
|
||||
}
|
Loading…
Reference in New Issue
Block a user
Требовалось создание объекта, а не массива объектов