import java.awt.*; public class DrawningCruiser { public EntityCruiser EntityCruiser; private int _pictureWidth; private int _pictureHeight; private int _startPosX; private int _startPosY; final private int _cruiserWidth = 110; final private int _cruiserHeight = 60; private NumberOfWheels wheels = new NumberOfWheels(); public boolean Init(int speed, double weight, Color bodyColor, Color additionalColor, boolean helicopterPad, boolean coating, int width, int height) { _pictureWidth = width; _pictureHeight = height; EntityCruiser = new EntityCruiser(); EntityCruiser.Init(speed, weight, bodyColor, additionalColor, helicopterPad, coating); return true; } public void SetPosition(int x, int y) { if (EntityCruiser == null) { return; } _startPosX = x; _startPosY = y; if (x + _cruiserWidth <= _pictureWidth || y + _cruiserHeight <= _pictureHeight) { _startPosX = 0; _startPosY = 0; } } public void MoveTransport(Direction direction) { if (EntityCruiser == null) { return; } switch (direction) { case Left: if (_startPosX - EntityCruiser.Step() > 0) { _startPosX -= (int)EntityCruiser.Step(); } break; case Up: if (_startPosY - EntityCruiser.Step() > 0) { _startPosY -= (int)EntityCruiser.Step(); } break; case Right: if (_startPosX + EntityCruiser.Step() + _cruiserWidth < _pictureWidth) { _startPosX += (int)EntityCruiser.Step(); } break; case Down: if (_startPosY + EntityCruiser.Step() + _cruiserHeight < _pictureHeight) { _startPosY += (int)EntityCruiser.Step(); } break; } } public void setWheels(int num){ wheels.setNumOfWheels(Integer.toString(num)); } 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); 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 (EntityCruiser.HelicopterPad()) { g.setColor(EntityCruiser.AdditionalColor()); g.drawRect(_startPosX + 35, _startPosY + 23, 15, 15); g.drawRect(_startPosX + 50, _startPosY + 19, 30, 25); } if (EntityCruiser.Coating()) { g.setColor(EntityCruiser.AdditionalColor()); g.fillRect(_startPosX + 35, _startPosY + 23, 15, 15); g.fillRect(_startPosX + 50, _startPosY + 19, 30, 25); } wheels.drawWheels(g, _startPosX, _startPosY, EntityCruiser.BodyColor()); } }