146 lines
6.1 KiB
Java

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);
}
}