PIbd-21. Putintsev D.M. Lab work 03. Hard #4

Closed
Danil wants to merge 2 commits from Lab3 into Lab2
6 changed files with 18 additions and 16 deletions
Showing only changes of commit 6f7f3302c1 - Show all commits

View File

@ -11,12 +11,12 @@ public class DrawingRoadTrain extends DrawingTruck{
super(speed, weight, bodyColor, width, height, wheelNumber);
if (entityTruck != null)
{
entityTruck = new EntityRoadTrain(speed, weight, bodyColor,
entityTruck = new EntityRoadTrain(speed, weight, bodyColor, wheelNumber,
additionalColor, waterContainer, sweepingBrush);
}
}
public DrawingRoadTrain(EntityRoadTrain truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){
super(truck, _wheelDrawing, width, height, wheelNumber);
public DrawingRoadTrain(EntityRoadTrain truck, IDrawingWheels _wheelDrawing, int width, int height ){
super(truck, _wheelDrawing, width, height);
if (height < _truckHeight || width < _truckWidth)
return;
}

View File

@ -32,14 +32,14 @@ public class DrawingTruck {
}
protected int _truckWidth = 80;
protected int _truckHeight = 70;
public DrawingTruck(EntityTruck truck, IDrawingWheels _wheelDrawing, int width, int height, int wheelNumber ){
public DrawingTruck(EntityTruck truck, IDrawingWheels _wheelDrawing, int width, int height){
if (height < _truckHeight || width < _truckWidth)
return;
_pictureWidth = width;
_pictureHeight = height;
entityTruck = truck;
drawingWheels = _wheelDrawing;
drawingWheels.SetWheelNumber(wheelNumber);
drawingWheels.SetWheelNumber(entityTruck.Numwheel);
}
public DrawingTruck(int speed, double weight, Color mainColor, int width, int height, int wheelNumber) {
if (width < _truckWidth || height < _truckHeight) {
@ -47,7 +47,7 @@ public class DrawingTruck {
}
_pictureWidth = width;
_pictureHeight = height;
entityTruck = new EntityTruck(speed, weight, mainColor);
entityTruck = new EntityTruck(speed, weight, mainColor, wheelNumber);
Random rand = new Random();
drawingWheels = switch (rand.nextInt(0, 3)) {
case 0 -> new DrawingWheels();
@ -67,7 +67,7 @@ public class DrawingTruck {
_pictureHeight = height;
_truckWidth = truckWidth;
_truckHeight = truckHeight;
entityTruck = new EntityTruck(speed, weight, mainColor);
entityTruck = new EntityTruck(speed, weight, mainColor, wheelNumber);
Random rand = new Random();
drawingWheels = switch (rand.nextInt(0, 3)) {
case 0 -> new DrawingWheels();

View File

@ -12,9 +12,9 @@ public class EntityRoadTrain extends EntityTruck {
return SweepingBrush;
}
public EntityRoadTrain(int speed, double weight, Color bodyColor, Color
public EntityRoadTrain(int speed, double weight, Color bodyColor, int numwheel, Color
additionalColor, boolean waterContainer, boolean sweepingBrush) {
super(speed, weight, bodyColor);
super(speed, weight, bodyColor, numwheel);
AdditionalColor = additionalColor;
WaterContainer = waterContainer;
SweepingBrush = sweepingBrush;

View File

@ -18,14 +18,16 @@ public class EntityTruck {
public Color GetBodyColor() {
return BodyColor;
}
public int Numwheel;
public double GetStep() {
return (double) Speed * 100 / Weight;
}
public EntityTruck(int speed, double weight, Color bodyColor) {
public EntityTruck(int speed, double weight, Color bodyColor, int numwheel) {
Speed = speed;
Weight = weight;
BodyColor = bodyColor;
Numwheel = numwheel;
}
}

View File

@ -61,10 +61,10 @@ public class GenericDopClass<T extends EntityTruck, U extends IDrawingWheels> {
}
DrawingTruck drawingTruck;
if (truck instanceof EntityRoadTrain){
drawingTruck = new DrawingRoadTrain((EntityRoadTrain)truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3));
drawingTruck = new DrawingRoadTrain((EntityRoadTrain)truck, wheel, _pictureWidth, _pictureHeight);
}
else{
drawingTruck = new DrawingTruck(truck, wheel, _pictureWidth, _pictureHeight, random.nextInt(3));
drawingTruck = new DrawingTruck(truck, wheel, _pictureWidth, _pictureHeight);
}
return drawingTruck;
}

View File

@ -40,10 +40,10 @@ public class FormGenericDopClass extends JFrame {
canv.setBounds(0,0,pictureBoxWidth, pictureBoxHeight);
genericDopClass = new GenericDopClass<>(100, 100, pictureBoxWidth, pictureBoxHeight);
genericDopClass.add(new EntityTruck(100, 100, Color.BLUE));
genericDopClass.add(new EntityTruck(100, 100, Color.RED));
genericDopClass.add(new EntityTruck(100, 100, Color.GRAY));
genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, Color.ORANGE, true, true));
genericDopClass.add(new EntityTruck(100, 100, Color.BLUE, 1));
genericDopClass.add(new EntityTruck(100, 100, Color.RED, 2));
genericDopClass.add(new EntityTruck(100, 100, Color.GRAY, 1));
genericDopClass.add(new EntityRoadTrain(100, 100, Color.BLUE, 3, Color.ORANGE, true, true));
genericDopClass.add(new DrawingOneLineWheels());
genericDopClass.add(new DrawingTwoLineWheels());