2023-12-19 22:51:32 +04:00
|
|
|
|
|
2023-12-14 13:43:13 +04:00
|
|
|
|
import java.awt.*;
|
|
|
|
|
|
|
|
|
|
public class DrawingRoadTrain {
|
2023-12-19 22:51:32 +04:00
|
|
|
|
private WheelDrawing wheelDrawing;
|
2023-12-14 13:43:13 +04:00
|
|
|
|
public EntityRoadTrain EntityRoadTrain;
|
|
|
|
|
private int _pictureWidth;
|
|
|
|
|
private int _pictureHeight;
|
|
|
|
|
private int _startPosX;
|
|
|
|
|
private int _startPosY;
|
|
|
|
|
private int _roadTrainWidth = 200;
|
|
|
|
|
private int _roadTrainHeight = 100;
|
|
|
|
|
public boolean Init(int speed, double weight, Color bodyColor, Color
|
2023-12-19 22:51:32 +04:00
|
|
|
|
additionalColor, boolean wheel, boolean door, boolean light, int numWheel, int width, int height)
|
2023-12-14 13:43:13 +04:00
|
|
|
|
{
|
|
|
|
|
_pictureWidth = width;
|
|
|
|
|
_pictureHeight = height;
|
|
|
|
|
if (_pictureHeight < _roadTrainHeight || _pictureWidth < _roadTrainWidth)
|
|
|
|
|
return false;
|
|
|
|
|
EntityRoadTrain = new EntityRoadTrain();
|
2023-12-19 22:51:32 +04:00
|
|
|
|
EntityRoadTrain.Init(speed, weight, bodyColor, additionalColor,wheel, door, light, numWheel);
|
2023-12-14 13:43:13 +04:00
|
|
|
|
|
2023-12-19 22:51:32 +04:00
|
|
|
|
wheelDrawing = new WheelDrawing();
|
|
|
|
|
wheelDrawing.setNumWheel(numWheel);
|
2023-12-14 13:43:13 +04:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
public void SetPosition(int x, int y)
|
|
|
|
|
{
|
|
|
|
|
_startPosX = Math.min(x, _pictureWidth-_roadTrainWidth);
|
|
|
|
|
_startPosY = Math.min(y, _pictureHeight- _roadTrainHeight);
|
|
|
|
|
}
|
|
|
|
|
public void MoveTransport(Direction direction)
|
|
|
|
|
{
|
|
|
|
|
if (EntityRoadTrain == null){
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case Left:
|
|
|
|
|
if (_startPosX - EntityRoadTrain.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosX -= (int) EntityRoadTrain.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Up:
|
|
|
|
|
if (_startPosY - EntityRoadTrain.Step > 0)
|
|
|
|
|
{
|
|
|
|
|
_startPosY -= (int) EntityRoadTrain.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Right:
|
|
|
|
|
if (_startPosX + _roadTrainWidth + EntityRoadTrain.Step < _pictureWidth)
|
|
|
|
|
{
|
|
|
|
|
_startPosX += (int) EntityRoadTrain.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
case Down:
|
|
|
|
|
if (_startPosY + _roadTrainHeight + EntityRoadTrain.Step < _pictureHeight)
|
|
|
|
|
{
|
|
|
|
|
_startPosY += (int) EntityRoadTrain.Step;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
public void DrawTransport(Graphics2D g) {
|
|
|
|
|
if (EntityRoadTrain == null) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// машина
|
|
|
|
|
g.drawRect(_startPosX, _startPosY + 50, 160, 20); // кузов
|
|
|
|
|
g.drawRect(_startPosX + 120, _startPosY + 10, 40, 40); // кабина
|
|
|
|
|
g.drawRect(_startPosX + 10, _startPosY, 90, 50); // бак с водой
|
|
|
|
|
g.drawRect(_startPosX + 130, _startPosY + 20, 30, 20); // окно
|
|
|
|
|
g.drawLine(_startPosX + 160, _startPosY + 70, _startPosX + 180, _startPosY + 80); // держатель для щетки
|
|
|
|
|
g.drawRect(_startPosX + 170, _startPosY + 80, 40, 10); // щетка
|
|
|
|
|
// обвесы
|
|
|
|
|
g.setColor(EntityRoadTrain.AdditionalColor);
|
2023-12-19 22:51:32 +04:00
|
|
|
|
wheelDrawing.Draw(_startPosX, _startPosY, EntityRoadTrain.AdditionalColor, g);
|
|
|
|
|
|
2023-12-14 13:43:13 +04:00
|
|
|
|
if (EntityRoadTrain.Door) {
|
|
|
|
|
g.fillRect(_startPosX + 40, _startPosY + 20, 20, 30); // дверь
|
|
|
|
|
}
|
|
|
|
|
if (EntityRoadTrain.Light) {
|
|
|
|
|
g.fillRect(_startPosX + 135, _startPosY, 10, 10); // мигалка
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|