Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
c32f353cf0 |
77
ProjectBulldozer/AbstractStrategy.java
Normal file
77
ProjectBulldozer/AbstractStrategy.java
Normal 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;
|
||||
}
|
||||
}
|
7
ProjectBulldozer/DirectionBulldozer.java
Normal file
7
ProjectBulldozer/DirectionBulldozer.java
Normal file
@ -0,0 +1,7 @@
|
||||
public enum DirectionBulldozer {
|
||||
Up,
|
||||
Down,
|
||||
Left,
|
||||
Right
|
||||
|
||||
}
|
145
ProjectBulldozer/DrawningBulldozer.java
Normal file
145
ProjectBulldozer/DrawningBulldozer.java
Normal file
@ -0,0 +1,145 @@
|
||||
import java.awt.*;
|
||||
import java.util.Random;
|
||||
|
||||
public class DrawningBulldozer {
|
||||
private EntityBulldozer entityBulldozer;
|
||||
public EntityBulldozer getEntityBulldozer() {
|
||||
return entityBulldozer;
|
||||
}
|
||||
protected void setEntityBulldozer(EntityBulldozer entityBulldozer) {
|
||||
this.entityBulldozer = entityBulldozer;
|
||||
}
|
||||
private IDrawningWheels drawningWheels;
|
||||
private int _pictureWidth;
|
||||
private int _pictureHeight;
|
||||
protected int _startPosX;
|
||||
protected int _startPosY;
|
||||
private int _bulldozerWidth = 160;
|
||||
private 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;
|
||||
}
|
||||
_pictureWidth = width;
|
||||
_pictureHeight = height;
|
||||
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);
|
||||
}
|
||||
public void SetPosition(int x, int y)
|
||||
{
|
||||
if (x < 0 || x + _bulldozerWidth > _pictureWidth) { x = 0; }
|
||||
if (y < 0 || y + _bulldozerHeight > _pictureHeight) { y = 0; }
|
||||
_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 (!CanMove(direction) || entityBulldozer == null) return;
|
||||
switch (direction) {
|
||||
//влево
|
||||
case Left:
|
||||
if (_startPosX - entityBulldozer.getStep() > 0)
|
||||
{
|
||||
_startPosX -= (int)entityBulldozer.getStep();
|
||||
}
|
||||
break;
|
||||
//вверх
|
||||
case Up:
|
||||
if (_startPosY - entityBulldozer.getStep() > 0)
|
||||
{
|
||||
_startPosY -= (int)entityBulldozer.getStep();
|
||||
}
|
||||
break;
|
||||
//вправо
|
||||
case Right:
|
||||
if (_startPosX + _bulldozerWidth + entityBulldozer.getStep() < _pictureWidth)
|
||||
{
|
||||
_startPosX += (int)entityBulldozer.getStep();
|
||||
}
|
||||
break;
|
||||
//вниз
|
||||
case Down:
|
||||
if (_startPosY + _bulldozerHeight + entityBulldozer.getStep() < _pictureHeight)
|
||||
{
|
||||
_startPosY += (int)entityBulldozer.getStep();
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
public void DrawTransport(Graphics2D g2D)
|
||||
{
|
||||
if (entityBulldozer == null) {
|
||||
return;
|
||||
}
|
||||
g2D.setStroke(new BasicStroke(3));
|
||||
g2D.setPaint(entityBulldozer.getBodyColor());
|
||||
g2D.fillRect(_startPosX + 25, _startPosY + 20, 110, 30);
|
||||
g2D.fillRect(_startPosX+60, _startPosY, 10, 30);
|
||||
int x = _startPosX + 30; // начальная позиция X
|
||||
int y = _startPosY; // начальная позиция Y
|
||||
int width = 110; // ширина прямоугольника
|
||||
int height = 30; // высота прямоугольника
|
||||
int radius = 20; // радиус закругления углов
|
||||
// Рисуем закругленный прямоугольник
|
||||
g2D.setColor(Color.BLACK);
|
||||
g2D.drawArc(x - 5, y + 50, radius * 2, radius * 2, 180, 90); // верхний левый угол
|
||||
g2D.drawLine(x + radius - 5, y + 50, x + width - radius - 5, y + 50); // верхняя горизонталь
|
||||
g2D.drawArc(x + width - radius * 2 - 5, y + 50, radius * 2, radius * 2, 270, 90); // верхний правый угол
|
||||
g2D.drawArc(x + width - radius * 2 - 5, y + height - radius * 2 + 60, radius * 2, radius * 2, 0, 90); // нижний правый угол
|
||||
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.getBodyColor());
|
||||
g2D.fillRect(_startPosX + 105, _startPosY, 30, 20);
|
||||
//Колёса
|
||||
drawningWheels.drawWheels(g2D, Color.BLACK, _startPosX, _startPosY);
|
||||
}
|
||||
}
|
34
ProjectBulldozer/DrawningFastBulldozer.java
Normal file
34
ProjectBulldozer/DrawningFastBulldozer.java
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
31
ProjectBulldozer/DrawningObjectBulldozer.java
Normal file
31
ProjectBulldozer/DrawningObjectBulldozer.java
Normal 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);
|
||||
}
|
||||
}
|
79
ProjectBulldozer/DrawningWheels.java
Normal file
79
ProjectBulldozer/DrawningWheels.java
Normal file
@ -0,0 +1,79 @@
|
||||
import java.awt.*;
|
||||
public class DrawningWheels 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);
|
||||
g2D.drawOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 56, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 84, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 110, _startPosY + 60, wheelRadius * 2, wheelRadius * 2);
|
||||
}
|
||||
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);
|
||||
g2D.drawOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 69, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 94, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
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);
|
||||
g2D.drawOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 58, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 82, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.fillOval(_startPosX + 105, _startPosY + 65, wheelRadius * 2, wheelRadius * 2);
|
||||
g2D.drawOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
|
||||
g2D.fillOval(_startPosX + 115, _startPosY + 54, wheelRadius, wheelRadius);
|
||||
}
|
||||
}
|
98
ProjectBulldozer/DrawningWheelsCircles.java
Normal file
98
ProjectBulldozer/DrawningWheelsCircles.java
Normal 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);
|
||||
}
|
||||
}
|
97
ProjectBulldozer/DrawningWheelsStar.java
Normal file
97
ProjectBulldozer/DrawningWheelsStar.java
Normal 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);
|
||||
}
|
||||
}
|
23
ProjectBulldozer/EntityBulldozer.java
Normal file
23
ProjectBulldozer/EntityBulldozer.java
Normal file
@ -0,0 +1,23 @@
|
||||
import java.awt.*;
|
||||
public class EntityBulldozer {
|
||||
private int Speed;
|
||||
public int getSpeed() {
|
||||
return Speed;
|
||||
}
|
||||
private double Weight;
|
||||
public double getWeight() {
|
||||
return Weight;
|
||||
}
|
||||
private Color BodyColor;
|
||||
public Color getBodyColor() {
|
||||
return BodyColor;
|
||||
}
|
||||
public double getStep() {
|
||||
return (double)Speed * 100 / Weight;
|
||||
}
|
||||
public EntityBulldozer(int speed, double weight, Color bodyColor) {
|
||||
Speed = speed;
|
||||
Weight = weight;
|
||||
BodyColor = bodyColor;
|
||||
}
|
||||
}
|
26
ProjectBulldozer/EntityFastBulldozer.java
Normal file
26
ProjectBulldozer/EntityFastBulldozer.java
Normal 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;
|
||||
}
|
||||
}
|
12
ProjectBulldozer/FrameBulldozer.java
Normal file
12
ProjectBulldozer/FrameBulldozer.java
Normal file
@ -0,0 +1,12 @@
|
||||
import javax.swing.*;
|
||||
public class FrameBulldozer extends JFrame {
|
||||
private PictureBoxBulldozer pictureBoxBulldozer;
|
||||
public FrameBulldozer() {
|
||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
pictureBoxBulldozer = new PictureBoxBulldozer();
|
||||
add(pictureBoxBulldozer);
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
setVisible(true);
|
||||
}
|
||||
}
|
6
ProjectBulldozer/IDrawningWheels.java
Normal file
6
ProjectBulldozer/IDrawningWheels.java
Normal 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
ProjectBulldozer/IMoveableObject.java
Normal file
6
ProjectBulldozer/IMoveableObject.java
Normal file
@ -0,0 +1,6 @@
|
||||
public interface IMoveableObject {
|
||||
ObjectParameters getObjectsPosition();
|
||||
int getStep();
|
||||
boolean checkCanMove(DirectionBulldozer direction);
|
||||
void moveObject(DirectionBulldozer direction);
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
|
||||
FrameBulldozer frameBulldozer = new FrameBulldozer();
|
||||
}
|
||||
}
|
||||
}
|
32
ProjectBulldozer/MoveToBorder.java
Normal file
32
ProjectBulldozer/MoveToBorder.java
Normal 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
ProjectBulldozer/MoveToCenter.java
Normal file
36
ProjectBulldozer/MoveToCenter.java
Normal 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
ProjectBulldozer/ObjectParameters.java
Normal file
30
ProjectBulldozer/ObjectParameters.java
Normal 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;
|
||||
}
|
||||
}
|
163
ProjectBulldozer/PictureBoxBulldozer.java
Normal file
163
ProjectBulldozer/PictureBoxBulldozer.java
Normal file
@ -0,0 +1,163 @@
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
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.setFocusable(false);
|
||||
buttonCreateBulldozer.setBounds(12, 415, 150, 30);
|
||||
add(buttonCreateBulldozer);
|
||||
buttonCreateBulldozer.addActionListener(e -> {
|
||||
Random random = new Random();
|
||||
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(),
|
||||
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 -> {
|
||||
if (drawningBulldozer == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
String buttonName = ((JButton) e.getSource()).getName();
|
||||
|
||||
switch (buttonName) {
|
||||
case ("buttonUp"):
|
||||
drawningBulldozer.MoveTransport(DirectionBulldozer.Up);
|
||||
break;
|
||||
case ("buttonDown"):
|
||||
drawningBulldozer.MoveTransport(DirectionBulldozer.Down);
|
||||
break;
|
||||
case ("buttonLeft"):
|
||||
drawningBulldozer.MoveTransport(DirectionBulldozer.Left);
|
||||
break;
|
||||
case ("buttonRight"):
|
||||
drawningBulldozer.MoveTransport(DirectionBulldozer.Right);
|
||||
break;
|
||||
}
|
||||
repaint();
|
||||
};
|
||||
buttonLeft = new JButton();
|
||||
buttonLeft.setName("buttonLeft");
|
||||
buttonLeft.setFocusable(false);
|
||||
buttonLeft.setPreferredSize(new Dimension(30, 30));
|
||||
buttonLeft.setIcon(new ImageIcon("Resources/left.png"));
|
||||
buttonLeft.addActionListener(buttonMoveListener);
|
||||
buttonLeft.setBounds(686, 408, 30, 30);
|
||||
add(buttonLeft);
|
||||
buttonRight = new JButton();
|
||||
buttonRight.setName("buttonRight");
|
||||
buttonRight.setFocusable(false);
|
||||
buttonRight.setPreferredSize(new Dimension(30, 30));
|
||||
buttonRight.setIcon(new ImageIcon("Resources/right.png"));
|
||||
buttonRight.addActionListener(buttonMoveListener);
|
||||
buttonRight.setBounds(758, 408, 30, 30);
|
||||
add(buttonRight);
|
||||
buttonDown = new JButton();
|
||||
buttonDown.setName("buttonDown");
|
||||
buttonDown.setFocusable(false);
|
||||
buttonDown.setPreferredSize(new Dimension(30, 30));
|
||||
buttonDown.setIcon(new ImageIcon("Resources/down.png"));
|
||||
buttonDown.addActionListener(buttonMoveListener);
|
||||
buttonDown.setBounds(722, 408, 30, 30);
|
||||
add(buttonDown);
|
||||
buttonUp = new JButton();
|
||||
buttonUp.setName("buttonUp");
|
||||
buttonUp.setFocusable(false);
|
||||
buttonUp.setPreferredSize(new Dimension(30, 30));
|
||||
buttonUp.setIcon(new ImageIcon("Resources/up.png"));
|
||||
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
|
||||
protected void paintComponent(Graphics g) {
|
||||
if (drawningBulldozer == null) {
|
||||
return;
|
||||
}
|
||||
super.paintComponent(g);
|
||||
Graphics2D g2d = (Graphics2D) g;
|
||||
drawningBulldozer.DrawTransport(g2d);
|
||||
}
|
||||
}
|
@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||
<module type="JAVA_MODULE" version="4">
|
||||
<component name="NewModuleRootManager" inherit-compiler-output="true">
|
||||
<exclude-output />
|
||||
<content url="file://$MODULE_DIR$">
|
||||
|
BIN
ProjectBulldozer/Resources/down.png
Normal file
BIN
ProjectBulldozer/Resources/down.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
ProjectBulldozer/Resources/left.png
Normal file
BIN
ProjectBulldozer/Resources/left.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
ProjectBulldozer/Resources/right.png
Normal file
BIN
ProjectBulldozer/Resources/right.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
BIN
ProjectBulldozer/Resources/up.png
Normal file
BIN
ProjectBulldozer/Resources/up.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.6 KiB |
5
ProjectBulldozer/Status.java
Normal file
5
ProjectBulldozer/Status.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum Status {
|
||||
NotInit,
|
||||
InProgress,
|
||||
Finish
|
||||
}
|
5
ProjectBulldozer/WheelNumber.java
Normal file
5
ProjectBulldozer/WheelNumber.java
Normal file
@ -0,0 +1,5 @@
|
||||
public enum WheelNumber {
|
||||
Four,
|
||||
Five,
|
||||
Six
|
||||
}
|
Loading…
Reference in New Issue
Block a user