PIBD-13 Pazushkin I.P. LabWork01 Hard #1
12
ProjectCleaningCar/src/CountWheels.java
Normal file
12
ProjectCleaningCar/src/CountWheels.java
Normal file
@ -0,0 +1,12 @@
|
||||
public enum CountWheels {
|
||||
One(1),
|
||||
Two(2),
|
||||
Three(3);
|
||||
public final int count;
|
||||
CountWheels(int count) {
|
||||
this.count = count;
|
||||
}
|
||||
public int getCountWheels() {
|
||||
return count;
|
||||
}
|
||||
}
|
@ -1,4 +1,6 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningCleaningCar {
|
||||
private EntityCleaningCar EntityCleaningCar;
|
||||
public EntityCleaningCar getEntityCleaningCar() {
|
||||
@ -8,8 +10,9 @@ public class DrawningCleaningCar {
|
||||
private Integer _pictureHeight;
|
||||
private Integer _startPosX;
|
||||
private Integer _startPosY;
|
||||
private final Integer _drawningCarWidth = 135;
|
||||
private final Integer _drawningCarHeight = 60;
|
||||
private final Integer _drawningCarWidth = 138;
|
||||
private final Integer _drawningCarHeight = 68;
|
||||
public DrawningWheels drawningWheels;
|
||||
|
||||
public void Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean tank, boolean sweepingBrush, boolean flashlight) {
|
||||
EntityCleaningCar = new EntityCleaningCar();
|
||||
@ -18,6 +21,10 @@ public class DrawningCleaningCar {
|
||||
_pictureHeight = null;
|
||||
_startPosX = null;
|
||||
_startPosY = null;
|
||||
|
||||
drawningWheels = new DrawningWheels();
|
||||
Random random = new Random();
|
||||
drawningWheels.setCountWheels(random.nextInt(1, 4));
|
||||
}
|
||||
public boolean SetPictureSize(int width, int height) {
|
||||
if (width < _drawningCarWidth || height < _drawningCarHeight) {return false;}
|
||||
@ -98,18 +105,36 @@ public class DrawningCleaningCar {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
if (EntityCleaningCar.getTank()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
g2d.drawRect(_startPosX, _startPosY, 100, 38);
|
||||
g2d.fillRect(_startPosX, _startPosY, 100, 38);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawRect(_startPosX, _startPosY, 100, 38);
|
||||
g2d.setColor(EntityCleaningCar.getBodyColor());
|
||||
g2d.fillRect(_startPosX, _startPosY + 20, 100, 10);
|
||||
}
|
||||
if (EntityCleaningCar.getSweepingBrush()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
g2d.fillOval(_startPosX + 120, _startPosY + 50, 20, 20);
|
||||
g2d.setColor(EntityCleaningCar.getBodyColor());
|
||||
g2d.fillOval(_startPosX + 125, _startPosY + 55, 10, 10);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawOval(_startPosX + 120, _startPosY + 50, 19, 19);
|
||||
g2d.drawOval(_startPosX + 125, _startPosY + 55, 9, 9);
|
||||
g2d.drawLine(_startPosX + 122, _startPosY + 48, _startPosX + 130, _startPosY + 60);
|
||||
}
|
||||
if (EntityCleaningCar.getFlashLight()) {
|
||||
g2d.setColor(EntityCleaningCar.getAdditionalColor());
|
||||
g2d.fillRect(_startPosX + 108, _startPosY + 3, 5, 8);
|
||||
}
|
||||
g2d.setColor(EntityCleaningCar.getBodyColor());
|
||||
g2d.fillRect(_startPosX, _startPosY + 40, 125, 10);
|
||||
g2d.fillRect(_startPosX + 100, _startPosY + 10, 20, 30);
|
||||
g2d.fillRect(_startPosX, _startPosY + 40, 122, 10);
|
||||
g2d.fillRect(_startPosX + 102, _startPosY + 10, 20, 30);
|
||||
|
||||
drawningWheels.DrawCleaningCarWheels(g, EntityCleaningCar.getBodyColor(), EntityCleaningCar.getAdditionalColor(), _startPosX, _startPosY);
|
||||
g2d.setColor(Color.black);
|
||||
|
||||
g2d.drawRect(_startPosX, _startPosY + 40, 122, 10);
|
||||
g2d.drawRect(_startPosX + 102, _startPosY + 10, 20, 30);
|
||||
|
||||
g2d.fillRect(_startPosX + 112, _startPosY + 15, 10, 12);
|
||||
}
|
||||
}
|
||||
|
25
ProjectCleaningCar/src/DrawningWheels.java
Normal file
25
ProjectCleaningCar/src/DrawningWheels.java
Normal file
@ -0,0 +1,25 @@
|
||||
import java.awt.*;
|
||||
|
||||
public class DrawningWheels {
|
||||
private CountWheels countWheels;
|
||||
public void setCountWheels(int numWheels) {
|
||||
for (CountWheels value : CountWheels.values()) {
|
||||
if (value.getCountWheels() == numWheels) {
|
||||
countWheels = value;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
public void DrawCleaningCarWheels(Graphics g, Color bodyColor, Color additionalColor, int startPosX, int startPosY) {
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
for (int i = 0; i < countWheels.getCountWheels(); i++) {
|
||||
g2d.setColor(bodyColor);
|
||||
g2d.fillOval(startPosX + 10 + 40 * i, startPosY + 50, 20, 20);
|
||||
g2d.setColor(additionalColor);
|
||||
g2d.fillOval(startPosX + 15 + 40 * i, startPosY + 55, 10, 10);
|
||||
g2d.setColor(Color.black);
|
||||
g2d.drawOval(startPosX + 10 + 40 * i, startPosY + 50, 19, 19);
|
||||
g2d.drawOval(startPosX + 15 + 40 * i, startPosY + 55, 9, 9);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user