2022-11-05 22:34:57 +04:00
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
// Класс, отвечающий за прорисовку и перемещение объекта-сущности
|
|
|
|
public class DrawningTracktor {
|
2022-11-07 00:26:51 +04:00
|
|
|
protected EntityTracktor Tracktor; // Класс-сущность
|
2022-11-05 22:34:57 +04:00
|
|
|
public EntityTracktor getTracktor(){
|
|
|
|
return Tracktor;
|
|
|
|
}
|
2022-11-07 00:26:51 +04:00
|
|
|
protected float _startPosX; // Левая координата отрисовки трактора
|
|
|
|
protected float _startPosY; // Верхняя кооридната отрисовки трактора
|
2022-11-05 22:34:57 +04:00
|
|
|
private Integer _pictureWidth = null; // Ширина окна отрисовки
|
|
|
|
private Integer _pictureHeight = null; // Высота окна отрисовки
|
2022-11-07 00:26:51 +04:00
|
|
|
protected int _tracktorWidth = 110; // Ширина отрисовки трактора
|
|
|
|
protected int _tracktorHeight = 87; // Высота отрисовки трактора
|
2022-11-05 22:34:57 +04:00
|
|
|
|
2022-11-05 23:24:05 +04:00
|
|
|
private DrawningRollers drawningRollers;
|
|
|
|
|
2022-11-05 22:34:57 +04:00
|
|
|
// Инициализация свойств
|
2022-11-07 00:26:51 +04:00
|
|
|
public DrawningTracktor(int speed, float weight, Color bodyColor, int countRollers)
|
2022-11-05 22:34:57 +04:00
|
|
|
{
|
2022-11-07 00:26:51 +04:00
|
|
|
Tracktor = new EntityTracktor(speed, weight, bodyColor);
|
|
|
|
drawningRollers = new DrawningRollers(countRollers, bodyColor);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected DrawningTracktor(int speed, float weight, Color bodyColor, int countRollers, int tracktorWidth, int tracktorHeight){
|
|
|
|
this(speed, weight, bodyColor, countRollers);
|
|
|
|
_tracktorWidth = tracktorWidth;
|
|
|
|
_tracktorHeight = tracktorHeight;
|
2022-11-05 22:34:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Установка позиции Трактора
|
|
|
|
public void SetPosition(int x, int y, int width, int height)
|
|
|
|
{
|
|
|
|
if (x + _tracktorWidth > width ||
|
|
|
|
x < 0 ||
|
|
|
|
y + _tracktorHeight > height ||
|
|
|
|
y < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
_startPosX = x;
|
|
|
|
_startPosY = y;
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Изменение направления перемещения
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
{
|
|
|
|
if (_pictureWidth == null || _pictureHeight == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
// вправо
|
|
|
|
case Right:
|
|
|
|
if (_startPosX + _tracktorWidth + Tracktor.getStep() < _pictureWidth)
|
|
|
|
{
|
|
|
|
_startPosX += Tracktor.getStep();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//влево
|
|
|
|
case Left:
|
|
|
|
if (_startPosX - Tracktor.getStep() > 0)
|
|
|
|
{
|
|
|
|
_startPosX -= Tracktor.getStep();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//вверх
|
|
|
|
case Up:
|
|
|
|
if (_startPosY - Tracktor.getStep() > 0)
|
|
|
|
{
|
|
|
|
_startPosY -= Tracktor.getStep();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
//вниз
|
|
|
|
case Down:
|
|
|
|
if (_startPosY + _tracktorHeight + Tracktor.getStep() < _pictureHeight)
|
|
|
|
{
|
|
|
|
_startPosY += Tracktor.getStep();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2022-11-05 23:32:00 +04:00
|
|
|
|
2022-11-05 22:34:57 +04:00
|
|
|
// Отрисовка Трактора
|
2022-11-07 00:26:51 +04:00
|
|
|
public void DrawTransport(Graphics2D g)
|
2022-11-05 22:34:57 +04:00
|
|
|
{
|
|
|
|
if (_startPosX < 0 || _startPosY < 0 || _pictureHeight == null || _pictureWidth == null)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
Color penColor = Color.BLACK;
|
|
|
|
|
|
|
|
// корпус
|
|
|
|
Color br = Tracktor!=null ? Tracktor.getBodyColor() : Color.GRAY ;
|
|
|
|
g.setColor(br);
|
|
|
|
g.fillRect((int)_startPosX + 10, (int)_startPosY + 30, 90, 25);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawRect((int)_startPosX + 10, (int)_startPosY + 30, 90, 25);
|
|
|
|
|
|
|
|
// окно
|
|
|
|
g.setColor(Color.CYAN);
|
|
|
|
g.fillRect((int)_startPosX + 65, (int)_startPosY + 1, 30, 29);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawRect((int)_startPosX + 65, (int)_startPosY + 1, 30, 29);
|
|
|
|
|
|
|
|
// труба
|
|
|
|
g.setColor(Color.RED);
|
|
|
|
g.fillRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 20);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawRect((int)_startPosX + 30, (int)_startPosY + 10, 10, 20);
|
|
|
|
|
|
|
|
// гусеница
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
|
|
g.fillOval((int)_startPosX + 1, (int)_startPosY + 57, 20, 20);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawOval((int)_startPosX + 1, (int)_startPosY + 57, 20, 20);
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
|
|
g.fillOval((int)_startPosX + 1, (int)_startPosY + 65, 20, 20);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawOval((int)_startPosX + 1, (int)_startPosY + 65, 20, 20);
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
|
|
g.fillOval((int)_startPosX + 90, (int)_startPosY + 57, 20, 20);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawOval((int)_startPosX + 90, (int)_startPosY + 57, 20, 20);
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
|
|
g.fillOval((int)_startPosX + 90, (int)_startPosY + 65, 20, 20);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawOval((int)_startPosX + 90, (int)_startPosY + 65, 20, 20);
|
|
|
|
g.setColor(Color.DARK_GRAY);
|
|
|
|
g.fillRect((int)_startPosX + 10, (int)_startPosY + 57, 90, 30);
|
|
|
|
g.fillRect((int)_startPosX + 1, (int)_startPosY + 65, 110, 10);
|
|
|
|
g.setColor(penColor);
|
|
|
|
g.drawLine((int)_startPosX + 10, (int)_startPosY + 57, (int)_startPosX + 100, (int)_startPosY + 57);
|
|
|
|
g.drawLine((int)_startPosX + 10, (int)_startPosY + 86, (int)_startPosX + 100, (int)_startPosY + 86);
|
|
|
|
g.drawLine((int)_startPosX + 1, (int)_startPosY + 65, (int)_startPosX + 1, (int)_startPosY + 75);
|
|
|
|
g.drawLine((int)_startPosX + 110, (int)_startPosY + 65, (int)_startPosX + 110, (int)_startPosY + 75);
|
|
|
|
|
2022-11-05 23:24:05 +04:00
|
|
|
drawningRollers.DrawRollers(g,_startPosX, _startPosY);
|
2022-11-05 22:34:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Смена границ формы отрисовки
|
|
|
|
public void ChangeBorders(int width, int height)
|
|
|
|
{
|
|
|
|
_pictureWidth = width;
|
|
|
|
_pictureHeight = height;
|
|
|
|
if (_pictureWidth <= _tracktorWidth || _pictureHeight <= _tracktorHeight)
|
|
|
|
{
|
|
|
|
_pictureWidth = null;
|
|
|
|
_pictureHeight = null;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (_startPosX + _tracktorWidth > _pictureWidth)
|
|
|
|
{
|
|
|
|
_startPosX = _pictureWidth - _tracktorWidth;
|
|
|
|
}
|
|
|
|
if (_startPosY + _tracktorHeight > _pictureHeight)
|
|
|
|
{
|
|
|
|
_startPosY = _pictureHeight - _tracktorHeight;
|
|
|
|
}
|
|
|
|
}
|
2022-11-07 00:26:51 +04:00
|
|
|
|
|
|
|
public float[] getCurrentPosition() {
|
|
|
|
return new float[] { _startPosX, _startPosX + _tracktorWidth - 1, _startPosY, _startPosY + _tracktorHeight - 1 };
|
|
|
|
// Left - 0
|
|
|
|
// Right - 1
|
|
|
|
// Top - 2
|
|
|
|
// Bottom - 3
|
|
|
|
}
|
2022-11-05 22:34:57 +04:00
|
|
|
}
|