2023-09-26 19:51:49 +04:00
|
|
|
import java.awt.*;
|
|
|
|
|
2023-11-04 14:33:13 +04:00
|
|
|
public class DrawTanker {
|
2023-10-18 12:33:39 +04:00
|
|
|
protected BaseTanker GasolineTanker;
|
|
|
|
public BaseTanker GetGasolineTanker() {return GasolineTanker;}
|
|
|
|
private IWheelDraw wheelsDrawing;
|
|
|
|
protected int _pictureWidth;
|
|
|
|
protected int _pictureHeight;
|
|
|
|
protected int _startPosX;
|
|
|
|
protected int _startPosY;
|
|
|
|
protected final int _carWidth = 110;
|
|
|
|
protected final int _carHeight = 120;
|
|
|
|
public int GetPosX() {return _startPosX;}
|
|
|
|
public int GetPosY() {return _startPosY;}
|
|
|
|
public int GetWidth() {return _carWidth;}
|
|
|
|
public int GetHeight() {return _carHeight;}
|
|
|
|
|
|
|
|
public boolean CanMove(Direction direction)
|
|
|
|
{
|
|
|
|
if (GasolineTanker == null)
|
|
|
|
return false;
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case Left -> {
|
|
|
|
return _startPosX - GasolineTanker.Step > 0; }
|
|
|
|
case Up -> {
|
|
|
|
return _startPosY - GasolineTanker.Step > 0; }
|
|
|
|
case Right -> {
|
|
|
|
return _startPosX + _carWidth + GasolineTanker.Step < _pictureWidth; }
|
|
|
|
case Down -> {
|
|
|
|
return _startPosY + _carHeight + GasolineTanker.Step < _pictureHeight; }
|
|
|
|
default -> {
|
|
|
|
return false; }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2023-11-04 14:33:13 +04:00
|
|
|
public DrawTanker(int speed, double weight, Color bodyColor, int width, int height, int wheelCount, int wheelMode)
|
2023-09-26 19:51:49 +04:00
|
|
|
{
|
|
|
|
_pictureHeight = height;
|
|
|
|
_pictureWidth = width;
|
2023-10-18 12:33:39 +04:00
|
|
|
GasolineTanker = new BaseTanker(speed, weight, bodyColor);
|
|
|
|
int mode = wheelMode % 3;
|
|
|
|
switch (mode)
|
|
|
|
{
|
|
|
|
case 0 -> {wheelsDrawing = new DrawWheelCircle();}
|
|
|
|
case 1 -> {wheelsDrawing = new DrawWheelSquare();}
|
|
|
|
case 2 -> {wheelsDrawing = new DrawWheelClassic();}
|
|
|
|
}
|
2023-09-26 19:51:49 +04:00
|
|
|
wheelsDrawing.setWheelCount(wheelCount);
|
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
|
2023-11-04 14:33:13 +04:00
|
|
|
public DrawTanker(BaseTanker tanker, int width, int height, IWheelDraw wheels)
|
|
|
|
{
|
|
|
|
GasolineTanker = tanker;
|
|
|
|
_pictureHeight = height;
|
|
|
|
_pictureWidth = width;
|
|
|
|
wheelsDrawing = wheels;
|
|
|
|
}
|
|
|
|
|
2023-09-26 19:51:49 +04:00
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
{
|
|
|
|
_startPosX = x;
|
|
|
|
_startPosY = y;
|
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
|
2023-09-26 19:51:49 +04:00
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
{
|
2023-10-18 12:33:39 +04:00
|
|
|
if (!CanMove(direction) || GasolineTanker == null)
|
2023-09-26 19:51:49 +04:00
|
|
|
return;
|
|
|
|
switch (direction)
|
|
|
|
{
|
2023-10-18 12:33:39 +04:00
|
|
|
case Left:
|
|
|
|
{
|
|
|
|
_startPosX -= (int)GasolineTanker.Step;
|
2023-09-26 19:51:49 +04:00
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
break;
|
|
|
|
case Up:
|
|
|
|
{
|
|
|
|
_startPosY -= (int)GasolineTanker.Step;
|
2023-09-26 19:51:49 +04:00
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
break;
|
|
|
|
case Right:
|
|
|
|
{
|
|
|
|
_startPosX += (int)GasolineTanker.Step;
|
2023-09-26 19:51:49 +04:00
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
break;
|
|
|
|
case Down:
|
|
|
|
{
|
|
|
|
_startPosY += (int)GasolineTanker.Step;
|
2023-09-26 19:51:49 +04:00
|
|
|
|
2023-10-18 12:33:39 +04:00
|
|
|
}
|
|
|
|
break;
|
2023-09-26 19:51:49 +04:00
|
|
|
}
|
|
|
|
}
|
2023-10-18 12:33:39 +04:00
|
|
|
|
2023-09-26 19:51:49 +04:00
|
|
|
public void DrawTransport(Graphics g)
|
|
|
|
{
|
|
|
|
if (GasolineTanker == null)
|
|
|
|
return;
|
|
|
|
var g2d = (Graphics2D) g;
|
|
|
|
g2d.setColor(GasolineTanker.getBodyColor());
|
|
|
|
// Отрисовка корпуса
|
|
|
|
g2d.fillRect(10 + _startPosX, 40 + _startPosY, 90, 20);
|
|
|
|
g2d.fillRect(80 + _startPosX, 10 + _startPosY, 20, 40);
|
|
|
|
// Отрисовка колесиков
|
|
|
|
wheelsDrawing.DrawWheels(_startPosX, _startPosY, GasolineTanker.getBodyColor(), g2d);
|
|
|
|
|
|
|
|
}
|
2023-11-04 14:33:13 +04:00
|
|
|
|
|
|
|
public IMoveableObject GetMoveableObject() {return new DrawingObjectTanker(this);}
|
2023-09-26 19:51:49 +04:00
|
|
|
}
|