import java.awt.*; public class DrawingCruiser { public EntityCruiser EntityCruiser; private int _pictureWidth; private int _pictureHeight; protected int _startPosX; protected int _startPosY; private int _cruiserWidth = 110; private int _cruiserHeight = 60; public int GetPosX() { return _startPosX; } ; public int GetPosY() { return _startPosY; } public int GetWidth() { return _cruiserWidth; } ; public int GetHeight() { return _cruiserHeight; } public IDop wheels; public DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height) { if (width < _cruiserWidth || height < _cruiserHeight) { return; } _pictureWidth = width; _pictureHeight = height; EntityCruiser = new EntityCruiser(speed, weight, bodyColor); } public EntityCruiser getEntity() { return EntityCruiser; } protected DrawingCruiser(int speed, double weight, Color bodyColor, int width, int height, int cruiserWidth, int cruiserHeight) { if (width <= _cruiserWidth || height <= _cruiserHeight) { return; } _pictureWidth = width; _pictureHeight = height; _cruiserWidth = cruiserWidth; _cruiserHeight = cruiserHeight; EntityCruiser = new EntityCruiser(speed, weight, bodyColor); } public DrawingCruiser(EntityCruiser entityCruiser, IDop wheels) { EntityCruiser = entityCruiser; this.wheels = wheels; _pictureWidth = 1000; _pictureHeight = 1000; _cruiserWidth = 110; _cruiserHeight = 60; } public void SetPosition(int x, int y) { if (x < 0 || x >= _pictureWidth || y < 0 || y >= _pictureHeight) { _startPosX = 0; _startPosY = 0; } _startPosX = x; _startPosY = y; } public void MoveTransport(Direction direction) { if (!CanMove(direction) || EntityCruiser == null) { return; } switch (direction) { case Left: _startPosX -= (int) EntityCruiser.Step(); break; case Up: _startPosY -= (int) EntityCruiser.Step(); break; case Right: _startPosX += (int) EntityCruiser.Step(); break; case Down: _startPosY += (int) EntityCruiser.Step(); break; } } public boolean CanMove(Direction direction) { if (EntityCruiser == null) { return false; } switch (direction) { case Left: return (_startPosX - EntityCruiser.Step()) > 0; case Up: return _startPosY - EntityCruiser.Step() > 0; case Right: return _startPosX + EntityCruiser.Step() + _cruiserWidth < _pictureWidth; case Down: return _startPosY + EntityCruiser.Step() + _cruiserHeight < _pictureHeight; default: return false; } } public void DrawTransport(Graphics g) { if (EntityCruiser == null) { return; } g.setColor(EntityCruiser.BodyColor); g.drawRect(_startPosX + 9, _startPosY + 15, 10, 30); g.drawRect(_startPosX + 90, _startPosY + 15, 10, 30); g.drawRect(_startPosX + 20, _startPosY + 4, 70, 52); g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30); g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30); g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50); g.fillRect(_startPosX + 10, _startPosY + 15, 10, 30); g.fillRect(_startPosX + 90, _startPosY + 15, 10, 30); g.fillRect(_startPosX + 20, _startPosY + 5, 70, 50); Point[] points1 = new Point[3]; points1[0] = new Point(_startPosX + 100, _startPosY + 5); points1[1] = new Point(_startPosX + 100, _startPosY + 55); points1[2] = new Point(_startPosX + 150, _startPosY + 30); g.fillPolygon(new int[]{points1[0].x, points1[1].x, points1[2].x}, new int[]{points1[0].y, points1[1].y, points1[2].y}, 3); g.fillRect(_startPosX + 5, _startPosY + 15, 10, 10); g.fillRect(_startPosX + 5, _startPosY + 35, 10, 10); if (wheels == null) { return; } wheels.drawWheels(g, _startPosX, _startPosY, EntityCruiser.BodyColor); } }