import java.awt.*; public class DrawingShip { public IMoveableObject GetMoveableObject() { return new DrawningObjectShip(this); } public EntityShip EntityShip; public int _pictureWidth; public int _pictureHeight; public int _startPosX; public int _startPosY; public int _shipWidth = 110; public int _shipHeight = 65; public int GetPosX(){ return _startPosX; } public int GetPosY(){ return _startPosY; } public int GetWidth(){ return _shipWidth; } public int GetHeight(){ return _shipHeight; } public boolean CanMove(Direction direction) { if(EntityShip == null) return false; switch(direction) { case Left: return _startPosX - EntityShip.Step > 0; case Right: return _startPosX + _shipWidth + EntityShip.Step < _pictureWidth; case Up: return _startPosY - EntityShip.Step > 0; case Down: return _startPosY + _shipHeight+ EntityShip.Step < _pictureHeight; default: return false; } } public DrawingShip(int speed, double weight, Color bodyColor, int width, int height) { if(width < _shipWidth || height < _shipHeight) { return; } _pictureWidth = width; _pictureHeight = height; EntityShip = new EntityShip(speed, weight, bodyColor); } public DrawingShip(EntityShip ship, int width, int height){ if(width < _shipWidth || height < _shipHeight) { return; } _pictureWidth = width; _pictureHeight = height; EntityShip = ship; } protected DrawingShip(int speed, double weight, Color bodyColor, int width, int height, int shipWidth, int shipHeight) { if (width < _shipWidth || height < _shipHeight) { return; } _pictureWidth = width; _pictureHeight = height; _shipHeight = shipHeight; _shipWidth = shipWidth; EntityShip = new EntityShip(speed, weight, bodyColor); } public void SetPosition(int x, int y) { _startPosX = Math.min(x, _pictureWidth - _shipWidth); _startPosY = Math.min(y, _pictureHeight - _shipHeight); } public void MoveTransport(Direction direction) { if (EntityShip == null) { return; } switch (direction) { case Left: if (_startPosX - EntityShip.Step > 0) { _startPosX -= (int)EntityShip.Step; } break; case Up: if (_startPosY - EntityShip.Step > 0) { _startPosY -= (int)EntityShip.Step; } break; case Right: if (_startPosX + EntityShip.Step + _shipWidth < _pictureWidth) { _startPosX += (int)EntityShip.Step; } break; case Down: if (_startPosY + EntityShip.Step + _shipHeight< _pictureHeight) { _startPosY += (int)EntityShip.Step; } break; } } public void DrawShip(Graphics2D g) { if (EntityShip == null) { return; } g.setPaint(EntityShip.BodyColor); // заполнение борта int x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20}; int y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65}; g.fillPolygon(x, y, 5); //борт корабля контур g.setPaint(Color.BLACK); int _x[] = {_startPosX+ 20, _startPosX+40, _startPosX+110, _startPosX+130, _startPosX+ 20}; int _y[] = {_startPosY+65,_startPosY+85, _startPosY+85, _startPosY+65, _startPosY+65}; g.drawPolyline(_x, _y, 5); //рисунок на борту g.drawLine(_startPosX + 43, _startPosY + 80, _startPosX + 47, _startPosY + 80); g.drawLine(_startPosX + 45, _startPosY + 70, _startPosX + 45, _startPosY + 80); g.drawLine(_startPosX + 40, _startPosY + 75, _startPosX + 50, _startPosY + 75); } }