Добавление классов для продвинутого объекта, изменение модификаторов полей класса базового объекта

This commit is contained in:
prodigygirl 2022-10-22 21:56:39 +04:00
parent 4d09e5187d
commit 5e6e077ef5
3 changed files with 60 additions and 4 deletions

View File

@ -2,11 +2,11 @@ import java.awt.*;
import java.util.Random;
public class DrawingArmoredCar {
private EntityArmoredCar armoredCar;
protected EntityArmoredCar armoredCar;
private float startPosX;
protected float startPosX;
private float startPosY;
protected float startPosY;
private int pictureWidth;
@ -16,7 +16,7 @@ public class DrawingArmoredCar {
private int carHeight = 50;
private DrawingCaterpillar drawingCaterpillar;
protected DrawingCaterpillar drawingCaterpillar;
public EntityArmoredCar getArmoredCar() {
return armoredCar;

View File

@ -0,0 +1,30 @@
import java.awt.*;
public class DrawingTank extends DrawingArmoredCar{
public DrawingTank(int speed, float weight, Color bodyColor, Color dopColor,
boolean towerWeapon, boolean AMachineGun) {
super(speed, weight, bodyColor);
armoredCar = new EntityTank(speed, weight, bodyColor, dopColor, towerWeapon, AMachineGun);
}
@Override
public void DrawTransport(Graphics2D g) {
if (!(armoredCar instanceof EntityTank tank)) {
return;
}
if (tank.isTowerWeapon()) {
g.setColor(tank.getDopColor());
g.fillRect((int)startPosX + 40, (int)startPosY, 5, 20);
g.fillRect((int)startPosX + 40, (int)startPosY, 40, 5);
g.fillOval((int)startPosX + 27, (int)startPosY + 7, 30, 10);
}
if (tank.isAMachineGun()) {
g.setColor(tank.getDopColor());
g.fillRect((int)startPosX + 60, (int)startPosY + 15, 7, 10);
g.fillRect((int)startPosX + 60, (int)startPosY + 17, 20, 5);
}
startPosY += 10;
super.DrawTransport(g);
startPosY -= 10;
}
}

View File

@ -0,0 +1,26 @@
import java.awt.*;
public class EntityTank extends EntityArmoredCar{
private Color dopColor;
private boolean towerWeapon;
private boolean AMachineGun;
public Color getDopColor() {
return dopColor;
}
public boolean isTowerWeapon() {
return towerWeapon;
}
public boolean isAMachineGun() {
return AMachineGun;
}
public EntityTank(int speed, float weight, Color bodyColor, Color dopColor, boolean towerWeapon, boolean AMachineGun) {
super(speed, weight, bodyColor);
this.dopColor = dopColor;
this.towerWeapon = towerWeapon;
this.AMachineGun = AMachineGun;
}
}