This commit is contained in:
[USERNAME] 2023-12-20 00:20:12 +04:00
parent 0073a12bad
commit 207be331fb
18 changed files with 637 additions and 72 deletions

77
src/AbstractStrategy.java Normal file
View File

@ -0,0 +1,77 @@
public abstract class AbstractStrategy {
private IMoveableObject moveableObject;
private Status state = Status.NotInit;
private int fieldWidth;
protected int getFieldWidth() {
return fieldWidth;
}
private int fieldHeight;
protected int getFieldHeight() {
return fieldHeight;
}
public Status getStatus() {
return state;
}
public void setData(IMoveableObject moveableObject, int width, int height) {
if (moveableObject == null) {
state = Status.NotInit;
return;
}
state = Status.InProgress;
this.moveableObject = moveableObject;
fieldWidth = width;
fieldHeight = height;
}
public void makeStep() {
if (state != Status.InProgress) {
return;
}
if (isTargetDestination()) {
state = Status.Finish;
return;
}
moveToTarget();
}
protected boolean moveLeft() {
return moveTo(DirectionBulldozer.Left);
}
protected boolean moveRight() {
return moveTo(DirectionBulldozer.Right);
}
protected boolean moveUp() {
return moveTo(DirectionBulldozer.Up);
}
protected boolean moveDown() {
return moveTo(DirectionBulldozer.Down);
}
protected ObjectParameters getObjectParameters() {
if (moveableObject == null) {
return null;
}
return moveableObject.getObjectsPosition();
}
protected Integer getStep() {
if (state != Status.InProgress) {
return null;
}
if (moveableObject == null) {
return null;
}
return moveableObject.getStep();
}
protected abstract void moveToTarget();
protected abstract boolean isTargetDestination();
private boolean moveTo(DirectionBulldozer directionBulldozer) {
if (state != Status.InProgress) {
return false;
}
if (moveableObject == null) {
return false;
}
if (moveableObject.checkCanMove(directionBulldozer)) {
moveableObject.moveObject(directionBulldozer);
return true;
}
return false;
}
}

View File

@ -3,5 +3,4 @@ public enum DirectionBulldozer {
Down,
Left,
Right
}

View File

@ -1,28 +1,65 @@
import java.awt.*;
import java.util.Random;
public class DrawningBulldozer {
private EntityBulldozer entityBulldozer;
public EntityBulldozer getEntityBulldozer() {
return entityBulldozer;
}
private DrawningWheels drawningWheels;
protected void setEntityBulldozer(EntityBulldozer entityBulldozer) {
this.entityBulldozer = entityBulldozer;
}
private IDrawningWheels drawningWheels;
private int _pictureWidth;
private int _pictureHeight;
private int _startPosX;
private int _startPosY;
private int _bulldozerWidth = 160;
private int _bulldozerHeight = 80;
public boolean Init(int speed, double weight, Color bulldozerColor, Color cabinColor, Color covshColor, boolean hasMoldboardfront, boolean hasRipper, int width, int height, int wheelNumber)
protected int _startPosX;
protected int _startPosY;
protected int _bulldozerWidth = 160;
protected int _bulldozerHeight = 90;
public int getPosX() {
return _startPosX;
}
public int getPosY() {
return _startPosY;
}
public int getWidth() {
return _bulldozerWidth;
}
public int getHeight() {
return _bulldozerHeight;
}
public DrawningBulldozer(int speed, double weight, Color bodyColor, boolean covsh, boolean rearbucket, Color covshColor, Color rearbucketColor, int width, int height, int wheelNumber)
{
if (height < _bulldozerHeight || width < _bulldozerWidth) {
return false;
return;
}
_pictureWidth = width;
_pictureHeight = height;
entityBulldozer = new EntityBulldozer();
entityBulldozer.Init(speed, weight, bulldozerColor, cabinColor, covshColor, hasMoldboardfront, hasRipper);
drawningWheels = new DrawningWheels();
entityBulldozer = new EntityBulldozer(speed, weight, bodyColor);
Random random = new Random();
drawningWheels = switch (random.nextInt(0, 3)) {
case 0 -> new DrawningWheels();
case 1 -> new DrawningWheelsStar();
case 2 -> new DrawningWheelsCircles();
default -> new DrawningWheels();
};
drawningWheels.setWheelNumber(wheelNumber);
}
protected DrawningBulldozer(int speed, double weight, Color bodyColor, int width, int height, int bulldozerWidth, int bulldozerHeight, int wheelNumber)
{
if (width < bulldozerWidth || height < bulldozerHeight) return;
_pictureWidth = width;
_pictureHeight = height;
_bulldozerWidth = bulldozerWidth;
_bulldozerHeight = bulldozerHeight;
entityBulldozer = new EntityBulldozer(speed, weight, bodyColor);
Random random = new Random();
drawningWheels = switch (random.nextInt(0, 3)) {
case 0 -> new DrawningWheels();
case 1 -> new DrawningWheelsStar();
case 2 -> new DrawningWheelsCircles();
default -> new DrawningWheels();
};
drawningWheels.setWheelNumber(wheelNumber);
return true;
}
public void SetPosition(int x, int y)
{
@ -31,8 +68,21 @@ public class DrawningBulldozer {
_startPosX = x;
_startPosY = y;
}
public boolean CanMove(DirectionBulldozer direction) {
if (entityBulldozer == null) {
return false;
}
return switch (direction) {
case Left -> _startPosX - entityBulldozer.getStep() > 0;
case Up -> _startPosY - entityBulldozer.getStep() > 0;
case Right -> _startPosX + _bulldozerWidth + entityBulldozer.getStep() < _pictureWidth;
case Down -> _startPosY + _bulldozerHeight + entityBulldozer.getStep() < _pictureHeight;
default -> false;
};
}
public void MoveTransport(DirectionBulldozer direction) {
if (entityBulldozer == null) return;
if (!CanMove(direction) || entityBulldozer == null) return;
switch (direction) {
//влево
case Left:
@ -70,7 +120,7 @@ public class DrawningBulldozer {
return;
}
g2D.setStroke(new BasicStroke(3));
g2D.setPaint(entityBulldozer.getBulldozerColor());
g2D.setPaint(entityBulldozer.getBodyColor());
g2D.fillRect(_startPosX + 25, _startPosY + 20, 110, 30);
g2D.fillRect(_startPosX+60, _startPosY, 10, 30);
int x = _startPosX + 30; // начальная позиция X
@ -87,24 +137,9 @@ public class DrawningBulldozer {
g2D.drawLine(x + width - radius - 5, y + height + 60, x + radius - 5, y + height + 60); // нижняя горизонталь
g2D.drawArc(x - 5, y + height - radius * 2 + 60, radius * 2, radius * 2, 90, 90); // нижний левый угол
// Кабина
g2D.setPaint(entityBulldozer.getCabinColor());
g2D.setPaint(entityBulldozer.getBodyColor());
g2D.fillRect(_startPosX + 105, _startPosY, 30, 20);
//Колёса
drawningWheels.drawWheels(g2D, Color.BLACK, _startPosX, _startPosY);
if (entityBulldozer.getHasMoldboardfront())
{
g2D.setPaint(entityBulldozer.getCabinColor());
int[] xPoints = {_startPosX + 25, _startPosX + 25, _startPosX};
int[] yPoints = {_startPosY + 30, _startPosY + 80, _startPosY + 80};
Polygon triangle = new Polygon(xPoints, yPoints, 3);
g2D.drawPolygon(triangle);
}
if (entityBulldozer.getHasRipper())
{
int[] xPoints2 = {_startPosX + 130, _startPosX + 160, _startPosX + 160};
int[] yPoints2 = {_startPosY + 50, _startPosY + 50, _startPosY + 80};
Polygon triangle2 = new Polygon(xPoints2, yPoints2, 3);
g2D.drawPolygon(triangle2);
}
}
}

View File

@ -0,0 +1,34 @@
import java.awt.*;
public class DrawningFastBulldozer extends DrawningBulldozer {
public DrawningFastBulldozer(int speed, double weight, Color bodyColor, boolean covsh, boolean rearbucket, Color covshColor, Color rearbucketColor, int width, int height, int wheelNumber)
{
super(speed, weight, bodyColor, width, height, 160, 90, wheelNumber);
if (getEntityBulldozer() != null)
{
setEntityBulldozer(new EntityFastBulldozer(speed, weight, bodyColor, covsh, rearbucket, covshColor, rearbucketColor));
}
}
@Override
public void DrawTransport(Graphics2D g2D) {
if (!(getEntityBulldozer() instanceof EntityFastBulldozer fastBulldozer)) {
return;
}
super.DrawTransport(g2D);
if (fastBulldozer.getCovsh())
{
g2D.setPaint(fastBulldozer.getCovshColor());
int[] xPoints = {_startPosX + 25, _startPosX + 25, _startPosX};
int[] yPoints = {_startPosY + 30, _startPosY + 80, _startPosY + 80};
Polygon triangle = new Polygon(xPoints, yPoints, 3);
g2D.drawPolygon(triangle);
}
if (fastBulldozer.getRearbucket() && fastBulldozer.getCovsh())
{
g2D.setPaint(fastBulldozer.getRearbucketColor());
int[] xPoints2 = {_startPosX + 130, _startPosX + 160, _startPosX + 160};
int[] yPoints2 = {_startPosY + 50, _startPosY + 50, _startPosY + 80};
Polygon triangle2 = new Polygon(xPoints2, yPoints2, 3);
g2D.drawPolygon(triangle2);
}
}
}

View File

@ -0,0 +1,31 @@
public class DrawningObjectBulldozer implements IMoveableObject{
private DrawningBulldozer drawningBulldozer = null;
public DrawningObjectBulldozer(DrawningBulldozer drawningBulldozer) {
this.drawningBulldozer = drawningBulldozer;
}
@Override
public ObjectParameters getObjectsPosition() {
if (drawningBulldozer == null || drawningBulldozer.getEntityBulldozer() == null) {
return null;
}
return new ObjectParameters(drawningBulldozer.getPosX(), drawningBulldozer.getPosY(),
drawningBulldozer.getWidth(), drawningBulldozer.getHeight());
}
@Override
public int getStep() {
if (drawningBulldozer == null)
return 0;
return (int) ((drawningBulldozer.getEntityBulldozer() != null) ? drawningBulldozer.getEntityBulldozer().getStep() : 0);
}
@Override
public boolean checkCanMove(DirectionBulldozer direction) {
if (drawningBulldozer == null)
return false;
return drawningBulldozer.CanMove(direction);
}
@Override
public void moveObject(DirectionBulldozer direction) {
if (drawningBulldozer != null)
drawningBulldozer.MoveTransport(direction);
}
}

View File

@ -1,6 +1,11 @@
import java.awt.*;
public class DrawningWheels {
public class DrawningWheels implements IDrawningWheels {
private WheelNumber wheelNumber;
@Override
public WheelNumber getWheelNumber() {
return wheelNumber;
}
@Override
public void setWheelNumber(int number) {
switch (number) {
case 1:
@ -15,16 +20,17 @@ public class DrawningWheels {
default: wheelNumber = WheelNumber.Four;
}
}
public void drawWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
@Override
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
switch (wheelNumber) {
case Four:
drawFourWheels(g2D, color, _startPosX, _startPosY);
drawFourWheels(g2d, color, startPosX, startPosY);
break;
case Five:
drawFiveWheels(g2D, color, _startPosX, _startPosY);
drawFiveWheels(g2d, color, startPosX, startPosY);
break;
case Six:
drawSixWheels(g2D, color, _startPosX, _startPosY);
drawSixWheels(g2d, color, startPosX, startPosY);
break;
}
}
@ -70,4 +76,4 @@ public class DrawningWheels {
g2D.drawOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
}
}
}

View File

@ -0,0 +1,98 @@
import java.awt.*;
public class DrawningWheelsCircles implements IDrawningWheels {
private WheelNumber wheelNumber;
@Override
public WheelNumber getWheelNumber() {
return wheelNumber;
}
@Override
public void setWheelNumber(int number) {
switch (number) {
case 1:
wheelNumber = WheelNumber.Four;
break;
case 2:
wheelNumber = WheelNumber.Five;
break;
case 3:
wheelNumber = WheelNumber.Six;
break;
default: wheelNumber = WheelNumber.Four;
}
}
@Override
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
switch (wheelNumber) {
case Four:
drawFourWheels(g2d, color, startPosX, startPosY);
break;
case Five:
drawFiveWheels(g2d, color, startPosX, startPosY);
break;
case Six:
drawSixWheels(g2d, color, startPosX, startPosY);
break;
}
}
private void drawFourWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 30, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 30, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 30, _startPosY + 60);
g2D.drawOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 56, _startPosY + 60);
g2D.drawOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 84, _startPosY + 60);
g2D.drawOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 110, _startPosY + 60);
}
private void drawFiveWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 34, _startPosY + 55, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 34, _startPosY + 55, wheelRadius, wheelRadius);
g2D.drawOval(_startPosX + 45, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 45, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 45, _startPosY + 65);
g2D.drawOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 69, _startPosY + 65);
g2D.drawOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 94, _startPosY + 65);
g2D.drawOval(_startPosX + 115, _startPosY + 55, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 115, _startPosY + 55, wheelRadius, wheelRadius);
}
private void drawSixWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 34, _startPosY + 54, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 34, _startPosY + 54, wheelRadius, wheelRadius);
g2D.drawOval(_startPosX + 35, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 35, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 35, _startPosY + 65);
g2D.drawOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 58, _startPosY + 65);
g2D.drawOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 82, _startPosY + 65);
g2D.drawOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 105, _startPosY + 65);
g2D.drawOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
}
private void drawPattern(Graphics2D g2D, int x, int y){
g2D.setColor(Color.WHITE);
g2D.setStroke(new BasicStroke(1));
g2D.drawOval(x + 6, y + 6, 8, 8);
g2D.setStroke(new BasicStroke(1));
g2D.drawOval(x + 3, y + 3, 14, 14);
g2D.setColor(Color.BLACK);
}
}

View File

@ -0,0 +1,97 @@
import java.awt.*;
public class DrawningWheelsStar implements IDrawningWheels {
private WheelNumber wheelNumber;
@Override
public WheelNumber getWheelNumber() {
return wheelNumber;
}
@Override
public void setWheelNumber(int number) {
switch (number) {
case 1:
wheelNumber = WheelNumber.Four;
break;
case 2:
wheelNumber = WheelNumber.Five;
break;
case 3:
wheelNumber = WheelNumber.Six;
break;
default: wheelNumber = WheelNumber.Four;
}
}
@Override
public void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY) {
switch (wheelNumber) {
case Four:
drawFourWheels(g2d, color, startPosX, startPosY);
break;
case Five:
drawFiveWheels(g2d, color, startPosX, startPosY);
break;
case Six:
drawSixWheels(g2d, color, startPosX, startPosY);
break;
}
}
private void drawFourWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 30, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 30, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 30, _startPosY + 60);
g2D.drawOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 56, _startPosY + 60);
g2D.drawOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 84, _startPosY + 60);
g2D.drawOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 110, _startPosY + 60);
}
private void drawFiveWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 34, _startPosY + 55, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 34, _startPosY + 55, wheelRadius, wheelRadius);
g2D.drawOval(_startPosX + 45, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 45, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 45, _startPosY + 65);
g2D.drawOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 69, _startPosY + 65);
g2D.drawOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 94, _startPosY + 65);
g2D.drawOval(_startPosX + 115, _startPosY + 55, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 115, _startPosY + 55, wheelRadius, wheelRadius);
}
private void drawSixWheels(Graphics2D g2D, Color color, int _startPosX, int _startPosY) {
g2D.setColor(color);
int wheelRadius = 10;
g2D.drawOval(_startPosX + 34, _startPosY + 54, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 34, _startPosY + 54, wheelRadius, wheelRadius);
g2D.drawOval(_startPosX + 35, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 35, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 35, _startPosY + 65);
g2D.drawOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 58, _startPosY + 65);
g2D.drawOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 82, _startPosY + 65);
g2D.drawOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
g2D.fillOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
drawPattern(g2D, _startPosX + 105, _startPosY + 65);
g2D.drawOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
g2D.fillOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
}
private void drawPattern(Graphics2D g2D, int x, int y){
g2D.setColor(Color.WHITE);
g2D.setStroke(new BasicStroke(2));
g2D.drawLine(x + 10, y + 3, x + 10, y + 17);
g2D.drawLine(x + 3, y + 10, x + 17, y + 10);
g2D.setColor(Color.BLACK);
}
}

View File

@ -8,34 +8,16 @@ public class EntityBulldozer {
public double getWeight() {
return Weight;
}
private Color BulldozerColor;
public Color getBulldozerColor() {
return BulldozerColor;
}
private Color CabinColor;
public Color getCabinColor() {
return CabinColor;
}
private Color CovshColor;
public Color getCovshColor() {return CovshColor;}
private boolean HasMoldboardfront;
public boolean getHasMoldboardfront() {
return HasMoldboardfront;
}
private boolean HasRipper;
public boolean getHasRipper() {
return HasRipper;
private Color BodyColor;
public Color getBodyColor() {
return BodyColor;
}
public double getStep() {
return (double)Speed * 800 / Weight;
return (double)Speed * 100 / Weight;
}
public void Init(int speed, double weight, Color bulldozerColor, Color cabinColor, Color covshColor, boolean hasMoldboardfront, boolean hasRipper) {
public EntityBulldozer(int speed, double weight, Color bodyColor) {
Speed = speed;
Weight = weight;
BulldozerColor = bulldozerColor;
CabinColor = cabinColor;
CovshColor = covshColor;
HasMoldboardfront = hasMoldboardfront;
HasRipper = hasRipper;
BodyColor = bodyColor;
}
}

View File

@ -0,0 +1,26 @@
import java.awt.*;
public class EntityFastBulldozer extends EntityBulldozer{
private boolean Covsh; //передний ковш
public boolean getCovsh() {
return Covsh;
}
private boolean Rearbucket; // задний ковш
public boolean getRearbucket() {
return Rearbucket;
}
private Color CovshColor;
public Color getCovshColor() {
return CovshColor;
}
private Color RearbucketColor;
public Color getRearbucketColor() {
return RearbucketColor;
}
public EntityFastBulldozer(int speed, double weight, Color bodyColor, boolean covsh, boolean rearbucket, Color covshColor, Color rearbucketColor) {
super(speed, weight, bodyColor);
Covsh = covsh;
Rearbucket = rearbucket;
CovshColor = covshColor;
RearbucketColor = rearbucketColor;
}
}

6
src/IDrawningWheels.java Normal file
View File

@ -0,0 +1,6 @@
import java.awt.*;
public interface IDrawningWheels {
void setWheelNumber(int number);
WheelNumber getWheelNumber();
void drawWheels(Graphics2D g2d, Color color, int startPosX, int startPosY);
}

6
src/IMoveableObject.java Normal file
View File

@ -0,0 +1,6 @@
public interface IMoveableObject {
ObjectParameters getObjectsPosition();
int getStep();
boolean checkCanMove(DirectionBulldozer direction);
void moveObject(DirectionBulldozer direction);
}

32
src/MoveToBorder.java Normal file
View File

@ -0,0 +1,32 @@
public class MoveToBorder extends AbstractStrategy {
@Override
protected boolean isTargetDestination() {
var objParams = getObjectParameters();
if (objParams == null) {
return false;
}
return objParams.rightBorder() <= getFieldWidth() &&
objParams.rightBorder() + getStep() >= getFieldWidth() &&
objParams.downBorder() <= getFieldHeight() &&
objParams.downBorder() + getStep() >= getFieldHeight();
}
@Override
protected void moveToTarget() {
var objParams = getObjectParameters();
if (objParams == null) {
return;
}
var diffX = objParams.objectMiddleHorizontal() - getFieldWidth();
if (Math.abs(diffX) > getStep()) {
if (diffX < 0) {
moveRight();
}
}
var diffY = objParams.objectMiddleVertical() - getFieldHeight();
if (Math.abs(diffY) > getStep()) {
if (diffY < 0) {
moveDown();
}
}
}
}

36
src/MoveToCenter.java Normal file
View File

@ -0,0 +1,36 @@
public class MoveToCenter extends AbstractStrategy {
@Override
protected boolean isTargetDestination() {
var objParams = getObjectParameters();
if (objParams == null) {
return false;
}
return objParams.objectMiddleHorizontal() <= getFieldWidth() / 2 &&
objParams.objectMiddleHorizontal() + getStep() >= getFieldWidth() / 2 &&
objParams.objectMiddleVertical() <= getFieldHeight() / 2 &&
objParams.objectMiddleVertical() + getStep() >= getFieldHeight() / 2;
}
@Override
protected void moveToTarget() {
var objParams = getObjectParameters();
if (objParams == null) {
return;
}
var diffX = objParams.objectMiddleHorizontal() - getFieldWidth() / 2;
if (Math.abs(diffX) > getStep()) {
if (diffX > 0) {
moveLeft();
} else {
moveRight();
}
}
var diffY = objParams.objectMiddleVertical() - getFieldHeight() / 2;
if (Math.abs(diffY) > getStep()) {
if (diffY > 0) {
moveUp();
} else {
moveDown();
}
}
}
}

30
src/ObjectParameters.java Normal file
View File

@ -0,0 +1,30 @@
public class ObjectParameters {
private final int x;
private final int y;
private final int width;
private final int height;
public int leftBorder() {
return x;
}
public int topBorder() {
return y;
}
public int rightBorder() {
return x + width;
}
public int downBorder() {
return y + height;
}
public int objectMiddleHorizontal() {
return x + width / 2;
}
public int objectMiddleVertical() {
return y + height / 2;
}
public ObjectParameters(int x, int y, int width, int height) {
this.x = x;
this.y = y;
this.width = width;
this.height = height;
}
}

View File

@ -4,29 +4,54 @@ import java.awt.event.ActionListener;
import java.util.Random;
public class PictureBoxBulldozer extends JPanel {
private DrawningBulldozer drawningBulldozer;
private AbstractStrategy abstractStrategy;
private JButton buttonLeft;
private JButton buttonUp;
private JButton buttonRight;
private JButton buttonDown;
private JButton buttonCreateFastBulldozer;
private JButton buttonCreateBulldozer;
private JComboBox comboBoxStrategy;
private JButton buttonStep;
public PictureBoxBulldozer() {
setLayout(null);
setBounds(0, 0, 800, 450);
buttonCreateBulldozer = new JButton("Создать");
buttonCreateBulldozer = new JButton("Создать трактор");
buttonCreateBulldozer.setFocusable(false);
buttonCreateBulldozer.setBounds(12, 415, 100, 30);
buttonCreateBulldozer.setBounds(12, 415, 150, 30);
add(buttonCreateBulldozer);
buttonCreateBulldozer.addActionListener(e -> {
Random random = new Random();
drawningBulldozer = new DrawningBulldozer();
drawningBulldozer.Init(random.nextInt(100)+100,
random.nextInt(2000)+1000,
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
new Color(random.nextInt(256), random.nextInt(256), random.nextInt(256)),
drawningBulldozer = new DrawningBulldozer((random.nextInt(200, 300)),
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
random.nextBoolean(), random.nextBoolean(),
this.getWidth(), this.getHeight(), random.nextInt(3) + 1);
drawningBulldozer.SetPosition(random.nextInt(90) + 10, random.nextInt(90) + 10);
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
this.getWidth(), this.getHeight(), random.nextInt(2, 5));
drawningBulldozer.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
repaint();
});
buttonCreateFastBulldozer = new JButton("Создать трактор с ковшами");
buttonCreateFastBulldozer.setFocusable(false);
buttonCreateFastBulldozer.setBounds(180, 415, 200, 30);
add(buttonCreateFastBulldozer);
buttonCreateFastBulldozer.addActionListener(e -> {
Random random = new Random();
drawningBulldozer = new DrawningFastBulldozer((random.nextInt(200, 300)),
random.nextInt(1000, 3000),
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
random.nextBoolean(), random.nextBoolean(),
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
new Color(random.nextInt(0, 256), random.nextInt(0, 256),
random.nextInt(0, 256)),
this.getWidth(), this.getHeight(), random.nextInt(2, 5));
drawningBulldozer.SetPosition(random.nextInt(10, 100), random.nextInt(10, 100));
repaint();
});
ActionListener buttonMoveListener = e -> {
@ -84,6 +109,46 @@ public class PictureBoxBulldozer extends JPanel {
buttonUp.addActionListener(buttonMoveListener);
buttonUp.setBounds(722, 372, 30, 30);
add(buttonUp);
String[] items = {
"0",
"1"
};
comboBoxStrategy = new JComboBox(items);
comboBoxStrategy.setBounds(667, 10, 120, 25);
buttonStep = new JButton("Шаг");
buttonStep.setFocusable(false);
buttonStep.setBounds(710, 40, 75, 30);
buttonStep.addActionListener(e -> {
if (drawningBulldozer == null) {
return;
}
if (comboBoxStrategy.isEnabled()) {
abstractStrategy = switch (comboBoxStrategy.getSelectedIndex()) {
case 0 -> new MoveToCenter();
case 1 -> new MoveToBorder();
default -> null;
};
if (abstractStrategy == null)
{
return;
}
abstractStrategy.setData(new DrawningObjectBulldozer(drawningBulldozer), this.getWidth(), this.getHeight());
}
if (abstractStrategy == null)
{
return;
}
comboBoxStrategy.setEnabled(false);
abstractStrategy.makeStep();
repaint();
if (abstractStrategy.getStatus() == Status.Finish)
{
comboBoxStrategy.setEnabled(true);
abstractStrategy = null;
}
});
add(comboBoxStrategy);
add(buttonStep);
setPreferredSize(new Dimension(800, 450));
}
@Override
@ -95,4 +160,4 @@ public class PictureBoxBulldozer extends JPanel {
Graphics2D g2d = (Graphics2D) g;
drawningBulldozer.DrawTransport(g2d);
}
}
}

5
src/Status.java Normal file
View File

@ -0,0 +1,5 @@
public enum Status {
NotInit,
InProgress,
Finish
}

View File

@ -2,4 +2,4 @@ public enum WheelNumber {
Four,
Five,
Six
}
}