import java.awt.*; public class DrawingShip { public EntityShip EntityShip; private int _pictureWidth; private int _pictureHeight; private int _startPosX; private int _startPosY; private int _shipWidth = 110; private int _shipHeight = 65; private DrawingDecks drawingDecks; 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); } 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; } //Pen pen = new Pen(Color.Black); //Brush adbrush = new SolidBrush(EntityContainerShip.AdditionalColor); //Brush brBlue = new SolidBrush(Color.Blue); 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); drawingDecks.DrawDeck(_startPosX, _startPosY, g); } }